|
在论坛上找了这方面的内容,程序也是改了又改,始终上传不了数据。
今天好不容易搞出来了,把他分享给有需要的朋友,希望能给正在学习这方面的同学一些参考。
调这玩意要细心,今天才发现是自己的上传报文不对,参考了大神的帖子,让我茅塞顿开。
https://open.iot.10086.cn/bbs/fo ... d=536&fromuid=23569
废话不多说了直接上链接:
温湿度上传Onenet.rar
(6.33 MB, 下载次数: 176)
单片机源程序如下:
- /************************************************************************************
- 名称:温湿度检测
- 功能:上传温湿度至Onenet服务器
- 时间:2020年5月18日15:36:25
- 地点:内江职业技术学院
- 作者:陈润源
- 申明:未经作者允许,禁止在其他论坛发布,此程序目前只在51黑论坛、电路城发布。
- 注明:此程序仅供参考
- 89C52RC ESP8266 DHT11
- P3.0(RX)========>TX
- P3.1(TX)========>RX
- P2.2====================> OUT
- ************************************************************************************/
- #include "reg52.h"
- #include "uart.h"
- #include "stdio.h"
- #include "lcd.h"
- #include "dht11.h"
- #include "string.h"
- #define uchar unsigned char
- #define uint unsigned int
- uchar Timer0_count,Timer0_miao,RsPoint;
- uchar Key_num,Flag_rec,Rec_stop;
- uchar xdata RsBuf[100];
-
-
- void main()
- {
- char *str2="AT+CIPSEND=14\r\n";
- uchar i;
-
- memset(&RsBuf[1],' ',18);
- Uart_init(); //串口初始化
- lcd_init(); //1602初始化
- delay(3000);
- SendString("+++");
- delay(500);
- SendString("+++\r\n"); //串口测试
- delay(500);
- Rec_stop=0;
-
- memset(&RsBuf[1],' ',18);
- SendString("AT+CWMODE=1\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CWMODE=1 ",0); //发送AT指令至ESP8826
- while(Rec_stop==0) ; //未发送成功则等待
- Rec_stop=0;
- delay(2000);
- memset(&RsBuf[1],' ',18);
- SendString("AT+RST\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+RST ",0);
- while(Rec_stop==0&&RsBuf[0]!='W');
- Rec_stop=0;
- delay(3000);
- memset(&RsBuf[1],' ',18);
- SendString("ATE0\r\n");
- write_string(0x80,"ATE0 ",0);
- write_string(0xc0," ",0);
- while(Rec_stop==0) ;
- Rec_stop=0;
- write_1602dat(RsBuf[i+2]);
- delay(2000);
- memset(&RsBuf[1],' ',18);
- SendString("ATE0\r\n");
- write_1602com(0x01);
- write_string(0x80,"ATE0 ",0);
- while(Rec_stop==0) ;
- Rec_stop=0;
- delay(2000);
- memset(&RsBuf[1],' ',18);
- SendString("AT+CIPMUX=0\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CIPMUX=0 ",0);
- while(Rec_stop==0);
- Rec_stop=0;
- delay(100);
- memset(&RsBuf[1],' ',18);
- SendString("AT+CIPSTART=\"TCP\",\"183.xx.40.33\",80\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CISTART=TCP ",0);
- while(Rec_stop==0&&RsBuf[2]=='O');
- Rec_stop=0;
- delay(2000);
- memset(&RsBuf[1],' ',18);
- SendString("AT+CIPMODE=1\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CIPMODE=1 ",0);
- while(Rec_stop==0);
- Rec_stop=0;
- delay(2000);
- RsPoint=0;
- memset(&RsBuf[1],' ',18);
- SendString("AT+CIPSEND\r\n");
- write_1602com(0x01);
- write_string(0x80,"AT+CIPSEND ",0);
- while(RsPoint==0);
- delay(2000);
- SendString("AT+CWJAP=\"SSID\",\"Password\"\r\n");
- //在这里填入你的路由器名称和密码 分别替代 SSID 和 Password 双引号和斜杠不能删除
- delay(5000);
- write_string(0x80,"Te: C Hu: %",0);
- write_string(0xc0,"QQ:101742xxxx ",0);
- write_1602com(0x85);
- write_1602dat(0xdf);
- while(1)
- {
- if(FlagStart==1) //2秒发送一次数据
- {
- TR0=0;
- RH(); //获取温湿度
- FlagStart = 0;
- write_1602com(0x83);
- write_1602dat(temperature%100/10+0x30); //1602屏幕显示温湿度
- write_1602dat(temperature%100%10+0x30);
- write_1602com(0x8d);
- write_1602dat(humidity%100/10+0x30);
- write_1602dat(humidity%100%10+0x30);
- SendString( "POST /devices/设备ID/datapoints?type=3 HTTP/1.1\r\napi-key:你的秘钥\r\nHost:api.heclouds点com\r\n"
- "Content-Length:59\r\n\r\n");
- //设备ID 改成你自己的设备ID 你的秘钥 改成你的APIkey
- SendString("{\"\WD\":\"");
- SendASC(temperature%100/10+0x30); //1
- SendASC(temperature%10+0x30); //1
- SendString("\",\"SD\":\"");
- SendASC(humidity%100/10+0x30); //1
- SendASC(humidity%10+0x30); //1
- SendString("\",\"RET\":\"OK\"}\r\n");
- TR0=1;
- Timer0_count=0;
- Timer0_miao=0;
- }
-
- }
-
-
- }
- // 通讯中断接收程序 中断函数无返回值
- void uart_rx(void) interrupt 4 //放在这里 和放在main()里面是一样的
- {
-
- unsigned char dat;
- if(RI) //是否接收中断
- {
- RI=0;
- dat = SBUF;
- if(SBUF=='\r') //检测指令是否发送并被接收成功
- {
- RsPoint=0;
- Rec_stop=1;
- }
- RsBuf[RsPoint]=SBUF;
- RsPoint++;
- }
- }
- void Timer0_ISR (void) interrupt 1 using 0
- {
- TH0=0x4c;
- TL0=0x00;
- Timer0_count++;
- if(Timer0_count>=20) //Timer0_count=20 表示1秒时间到
- {
- Timer0_count=0;
- Timer0_miao++;
-
- if(Timer0_miao>=2)
- {
- Timer0_miao=0;
- FlagStart=1;
- }
- }
- }
复制代码 |
评分
-
查看全部评分
|