|
在論壇上找了這方面的內容,程序也是改了又改,始終上傳不了數據。
今天好不容易搞出來了,把他分享給有需要的朋友,希望能給正在學習這方面的同學一些參考。
調這玩意要細心,今天才發現是自己的上傳報文不對,參考了大神的帖子,讓我茅塞頓開。
https://open.iot.10086.cn/bbs/fo ... d=536&fromuid=23569
廢話不多說了直接上鏈接:
溫濕度上傳Onenet.rar
(6.33 MB, 下載次數: 176)
2020-5-18 16:22 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
1.jpg (3.05 MB, 下載次數: 89)
下載附件
2020-5-18 16:22 上傳
調試.png (22.32 KB, 下載次數: 80)
下載附件
2020-5-18 16:20 上傳
單片機源程序如下:
- /************************************************************************************
- 名稱:溫濕度檢測
- 功能:上傳溫濕度至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;
- }
- }
- }
復制代碼 |
評分
-
查看全部評分
|