【TinkerNode NB-IoT】连接ONENET物联网,收集环境温度与湿度

2020-04-193427
AI 快速预览详细 收起
本文介绍了如何使用TinkerNode NB-IoT开发板通过HTTP协议连接到ONENET平台,实现环境温度与湿度数据的采集。主要代码展示了数据封装和发送的过程,包括数据格式化和HTTP请求的构建。通过本文,你可以了解如何快速搭建一个简单的物联网项目,实现传感器数据的上传。
本次采用HTTP协议数据封装接口形式连接到ONENET平台进行数据交互。
ONENET架构模型
【TinkerNode NB-IoT】连接ONENET物联网,收集环境温度与湿度图1

主要代码如下:

void sendOnenet(void)
{
        char databuf[256];

        memset(TXbuf, 0, sizeof(databuf));

        PutOnenetBuf(databuf);

        Serial.println(databuf);
        client.print(databuf);

}

void PutOnenetBuf(char *buf)
{
        char text[24];
        char tempbuf[128];

        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);

}


采用码盘的显示展示数据:
【TinkerNode NB-IoT】连接ONENET物联网,收集环境温度与湿度图2

以上就是简单物联网数据采集的测试,下回见。


创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(0)
- 没有更多了 -