久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標(biāo)題: 51單片機(jī)上傳溫濕度至Onenet服務(wù)器 源程序 [打印本頁(yè)]

作者: 陳潤(rùn)源home    時(shí)間: 2020-5-18 16:24
標(biāo)題: 51單片機(jī)上傳溫濕度至Onenet服務(wù)器 源程序
在論壇上找了這方面的內(nèi)容,程序也是改了又改,始終上傳不了數(shù)據(jù)。
今天好不容易搞出來(lái)了,把他分享給有需要的朋友,希望能給正在學(xué)習(xí)這方面的同學(xué)一些參考。

調(diào)這玩意要細(xì)心,今天才發(fā)現(xiàn)是自己的上傳報(bào)文不對(duì),參考了大神的帖子,讓我茅塞頓開。
https://open.iot.10086.cn/bbs/fo ... d=536&fromuid=23569

廢話不多說(shuō)了直接上鏈接: 溫濕度上傳Onenet.rar (6.33 MB, 下載次數(shù): 176)


單片機(jī)源程序如下:
  1. /************************************************************************************
  2. 名稱:溫濕度檢測(cè)
  3. 功能:上傳溫濕度至Onenet服務(wù)器
  4. 時(shí)間:2020年5月18日15:36:25
  5. 地點(diǎn):內(nèi)江職業(yè)技術(shù)學(xué)院
  6. 作者:陳潤(rùn)源
  7. 申明:未經(jīng)作者允許,禁止在其他論壇發(fā)布,此程序目前只在51黑論壇、電路城發(fā)布。
  8. 注明:此程序僅供參考
  9.          89C52RC        ESP8266           DHT11
  10.       P3.0(RX)========>TX
  11.           P3.1(TX)========>RX
  12.           P2.2====================> OUT
  13. ************************************************************************************/
  14. #include "reg52.h"
  15. #include "uart.h"
  16. #include "stdio.h"
  17. #include "lcd.h"
  18. #include "dht11.h"  
  19. #include "string.h"

  20. #define uchar unsigned char
  21. #define uint  unsigned int
  22. uchar Timer0_count,Timer0_miao,RsPoint;
  23. uchar Key_num,Flag_rec,Rec_stop;
  24. uchar xdata RsBuf[100];




  25. void main()
  26. {
  27.         char *str2="AT+CIPSEND=14\r\n";
  28.         uchar i;

  29.         memset(&RsBuf[1],' ',18);
  30.     Uart_init();                 //串口初始化
  31.     lcd_init();                         //1602初始化
  32.         delay(3000);
  33.          SendString("+++");
  34.         delay(500);
  35.         SendString("+++\r\n");         //串口測(cè)試
  36.         delay(500);
  37.         Rec_stop=0;
  38.         
  39.         memset(&RsBuf[1],' ',18);
  40.         SendString("AT+CWMODE=1\r\n");
  41.         write_1602com(0x01);
  42.         write_string(0x80,"AT+CWMODE=1     ",0);  //發(fā)送AT指令至ESP8826
  43.         while(Rec_stop==0) ;             //未發(fā)送成功則等待
  44.         Rec_stop=0;
  45.         delay(2000);

  46.         memset(&RsBuf[1],' ',18);
  47.         SendString("AT+RST\r\n");
  48.         write_1602com(0x01);
  49.     write_string(0x80,"AT+RST          ",0);
  50.         while(Rec_stop==0&&RsBuf[0]!='W');
  51.         Rec_stop=0;
  52.            delay(3000);

  53.         memset(&RsBuf[1],' ',18);
  54.     SendString("ATE0\r\n");
  55.         write_string(0x80,"ATE0            ",0);
  56.         write_string(0xc0,"                ",0);
  57.         while(Rec_stop==0) ;
  58.         Rec_stop=0;
  59.         write_1602dat(RsBuf[i+2]);
  60.          delay(2000);

  61.         memset(&RsBuf[1],' ',18);
  62.         SendString("ATE0\r\n");
  63.         write_1602com(0x01);
  64.         write_string(0x80,"ATE0            ",0);
  65.         while(Rec_stop==0) ;
  66.         Rec_stop=0;
  67.     delay(2000);

  68.         memset(&RsBuf[1],' ',18);
  69.     SendString("AT+CIPMUX=0\r\n");
  70.         write_1602com(0x01);
  71.     write_string(0x80,"AT+CIPMUX=0      ",0);
  72.         while(Rec_stop==0);
  73.         Rec_stop=0;
  74.            delay(100);

  75.         memset(&RsBuf[1],' ',18);
  76.         SendString("AT+CIPSTART=\"TCP\",\"183.xx.40.33\",80\r\n");
  77.         write_1602com(0x01);
  78.     write_string(0x80,"AT+CISTART=TCP   ",0);
  79.         while(Rec_stop==0&&RsBuf[2]=='O');
  80.         Rec_stop=0;
  81.          delay(2000);


  82.         memset(&RsBuf[1],' ',18);
  83.         SendString("AT+CIPMODE=1\r\n");
  84.         write_1602com(0x01);
  85.     write_string(0x80,"AT+CIPMODE=1     ",0);
  86.         while(Rec_stop==0);
  87.         Rec_stop=0;
  88.          delay(2000);

  89.         RsPoint=0;
  90.         memset(&RsBuf[1],' ',18);
  91.     SendString("AT+CIPSEND\r\n");
  92.         write_1602com(0x01);
  93.     write_string(0x80,"AT+CIPSEND       ",0);
  94.         while(RsPoint==0);
  95.            delay(2000);
  96.         SendString("AT+CWJAP=\"SSID\",\"Password\"\r\n");                        
  97.         //在這里填入你的路由器名稱和密碼 分別替代 SSID 和 Password 雙引號(hào)和斜杠不能刪除
  98.         delay(5000);        
  99.          write_string(0x80,"Te:   C   Hu:  %",0);
  100.         write_string(0xc0,"QQ:101742xxxx   ",0);
  101.         write_1602com(0x85);
  102.         write_1602dat(0xdf);

  103.         while(1)
  104.         {
  105.                   if(FlagStart==1)                //2秒發(fā)送一次數(shù)據(jù)
  106.                 {
  107.                      TR0=0;
  108.              RH();                           //獲取溫濕度
  109.                           FlagStart = 0;
  110.                          write_1602com(0x83);
  111.                          write_1602dat(temperature%100/10+0x30);  //1602屏幕顯示溫濕度
  112.                          write_1602dat(temperature%100%10+0x30);
  113.                          write_1602com(0x8d);
  114.                          write_1602dat(humidity%100/10+0x30);
  115.                          write_1602dat(humidity%100%10+0x30);
  116.                          SendString( "POST /devices/設(shè)備ID/datapoints?type=3 HTTP/1.1\r\napi-key:你的秘鑰\r\nHost:api.heclouds點(diǎn)com\r\n"
  117.                                         "Content-Length:59\r\n\r\n");
  118.                          //設(shè)備ID 改成你自己的設(shè)備ID   你的秘鑰 改成你的APIkey  
  119.                          SendString("{\"\WD\":\"");   
  120.                  SendASC(temperature%100/10+0x30);          //1
  121.                  SendASC(temperature%10+0x30);                //1
  122.                          SendString("\",\"SD\":\"");
  123.                  SendASC(humidity%100/10+0x30);          //1
  124.                  SendASC(humidity%10+0x30);                //1
  125.                  SendString("\",\"RET\":\"OK\"}\r\n");         
  126.                          TR0=1;
  127.                          Timer0_count=0;
  128.                          Timer0_miao=0;
  129.                 }
  130.          
  131.         }

  132.    
  133. }

  134. //  通訊中斷接收程序   中斷函數(shù)無(wú)返回值
  135.   void uart_rx(void)  interrupt 4   //放在這里 和放在main()里面是一樣的
  136. {
  137.    
  138.         unsigned char dat;
  139.     if(RI)                         //是否接收中斷
  140.     {
  141.      RI=0;
  142.          dat = SBUF;
  143.          if(SBUF=='\r')                   //檢測(cè)指令是否發(fā)送并被接收成功
  144.          {
  145.            RsPoint=0;
  146.            Rec_stop=1;
  147.           }
  148.           RsBuf[RsPoint]=SBUF;
  149.           RsPoint++;
  150.         }

  151. }

  152. void Timer0_ISR (void) interrupt 1 using 0
  153. {
  154.   TH0=0x4c;
  155.   TL0=0x00;
  156.   Timer0_count++;
  157.   if(Timer0_count>=20)                                //Timer0_count=20 表示1秒時(shí)間到
  158.   {
  159.    Timer0_count=0;
  160.    Timer0_miao++;

  161.    if(Timer0_miao>=2)
  162.    {
  163.     Timer0_miao=0;
  164.         FlagStart=1;
  165.    }
  166.   }
  167. }  
復(fù)制代碼

作者: xy027172    時(shí)間: 2020-5-18 21:31
好帖,學(xué)習(xí)、收藏了
作者: zqy181818    時(shí)間: 2020-5-18 22:55
我看了一下 可是代碼不全呀
作者: 陳潤(rùn)源home    時(shí)間: 2020-5-19 06:23
zqy181818 發(fā)表于 2020-5-18 22:55
我看了一下 可是代碼不全呀

完整代碼在附件里,這里顯示的只有main.c文件內(nèi)容哦
作者: 12345trewq    時(shí)間: 2021-4-30 22:35
數(shù)據(jù)上傳不了

作者: zbx5    時(shí)間: 2021-5-2 21:53
數(shù)據(jù)上傳沒(méi)問(wèn)題,但數(shù)據(jù)下載(指令)解析可能會(huì)有問(wèn)題,51的資源太少了
作者: 陳潤(rùn)源home    時(shí)間: 2021-5-3 22:33
zbx5 發(fā)表于 2021-5-2 21:53
數(shù)據(jù)上傳沒(méi)問(wèn)題,但數(shù)據(jù)下載(指令)解析可能會(huì)有問(wèn)題,51的資源太少了

數(shù)據(jù)解析得自己寫
作者: 陳潤(rùn)源home    時(shí)間: 2022-11-28 11:17
有問(wèn)題的朋友可以私信我




歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 成人伊人| 久久激情视频 | 国产欧美在线播放 | 在线观看免费av片 | 一级一片在线观看 | 日韩免费| 日韩欧美精品一区 | 一区二区三区视频 | 久99久视频 | 日日夜夜精品视频 | 国产美女视频黄 | 免费a级毛片在线播放 | 亚洲欧美日韩系列 | 亚洲一区二区久久 | 精品亚洲视频在线 | 久久噜噜噜精品国产亚洲综合 | 天天草草草 | 日本一区二区电影 | 久久伊人影院 | 香蕉久久久 | 综合国产第二页 | 欧美成视频在线观看 | 国产精品中文字幕在线 | 在线精品观看 | 91色视频在线观看 | 日韩精品一区在线观看 | 亚洲欧美综合精品久久成人 | av影音 | 亚洲永久免费观看 | 成人在线激情 | 性欧美xxxx | 欧美在线一级 | 99精品欧美一区二区三区 | 欧洲成人 | 国产999精品久久久久久 | 精品丝袜在线 | 91av在线免费观看 | 久久久久久国产精品三区 | av网站免费在线观看 | 国产色| 亚洲福利|