【TinkerNode NB-IoT】连接ONENET物联网,收集环境温度与湿度
本次采用HTTP协议数据封装接口形式连接到ONENET平台进行数据交互。ONENET架构模型
主要代码如下:
void sendOnenet(void)
{
char databuf;
memset(TXbuf, 0, sizeof(databuf));
PutOnenetBuf(databuf);
Serial.println(databuf);
client.print(databuf);
}
void PutOnenetBuf(char *buf)
{
char text;
char tempbuf;
memset(text, 0, sizeof(text));
memset(tempbuf, 0, sizeof(tempbuf));
strcpy(tempbuf, "{");
memset(text, 0, sizeof(text));
sprintf(text, "\"Temperature\":%0.2f,", dataInfo.tempreture);
strcat(tempbuf, text);
memset(text, 0, sizeof(text));
sprintf(text, "\"Humidity\":%0.2f", dataInfo.humidity);
strcat(tempbuf, text);
strcat(tempbuf, "}");
sprintf(buf, "POST /devices/%s/datapoints?type=3 HTTP/1.1\r\napi-key:%s\r\nHost:api.heclouds.com\r\n"
"Content-Length:%d\r\n\r\n",DEVID, APIKEY, strlen(tempbuf));
strcat(buf, tempbuf);
}
采用码盘的显示展示数据:
以上就是简单物联网数据采集的测试,下回见。
页:
[1]