进入https://www.xively.com/注册登录
添加设备(Add Device) 在Development Devices页面点击Add Device添加设备
填写Device Name和Device Description,将Privacy设定为Public Device
设置API Key 进入Device详情页,在API Keys中点击Add Key添加一个Key,将Permissions中的Read,Create,Update,Delete全部勾选,Label随便填。
向Xively提交数据 在这里通过CURL向xively提交JSON格式的数据
JSON数据格式
{ "datastreams": [ { "id": "load", "current_value": "9.00" }, { "id": "temp", "current_value": "89.15" } ] } 其中每个id为数据定义的idcurrent_value为提交的值
脚本文件send_xively.sh
#!/bin/bash LOCATION='/home/pi/xively_data' #Path of Xively JSON DATA file API_KEY='orxUhgjqSYPDbv5243534tG65464345eArxSVY9pE8ITnE' #API Key FEED_ID='1354438558' #FEED_ID #################################################### COSM_URL=https://api.xively.com/v2/feeds/${FEED_ID}?timezone=+8 cpu_load=`cat /proc/loadavg | awk '{print $2}'` sen_t=`sudo /home/pi/st` sen_h=`sudo /home/pi/sh` for i in 1 2 3 4 5; do cpu_t=`cat /sys/class/thermal/thermal_zone0/temp | awk '{print $1/1000}'` if [[ "${cpu_t}" =~ ^- ]] then cpu_t='0.0' else echo ${cpu_t} break fi done STR=`awk 'BEGIN{printf "{\"datastreams\":[ {\"id\":\"cpu_load\",\"current_value\":\"%.2f\"}, {\"id\":\"cpu_temp\",\"current_value\":\"%.2f\"},{\"id\":\"sensor_t\",\"current_value\":\"%.2f\"}, {\"id\":\"sensor_h\",\"current_value\":\"%.2f\"}] } ",'$cpu_load','$cpu_t','$sen_t','$sen_h'}'` echo ${cpu_t} echo ${cpu_load} echo ${sen_t} echo ${sen_h} echo ${STR} echo ${STR} > ${LOCATION}/cosm.json curl -s -v --request PUT --header "X-ApiKey: ${API_KEY}" --data-binary @${LOCATION}/cosm.json ${COSM_URL} 其中LOCATION为JSON文件存放目录,没有的话请新建。API_KEY和FEED_ID按照自己的配置填写。
...