找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 5533|回復(fù): 8
打印 上一主題 下一主題
收起左側(cè)

基于arduino的ESP8266天氣預(yù)報(bào)設(shè)計(jì)資料

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
基于arduino的ESP8266天氣預(yù)報(bào)設(shè)計(jì)
附錄:代碼、天氣相關(guān)圖片、字樣等素材。

單片機(jī)源程序如下:
  1. #include<U8g2lib.h>
  2. #include<ESP8266WiFi.h>
  3. #include<avr/pgmspace.h>
  4. #include<SPI.h>
  5. #include<SD.h>
  6. #include<ArduinoJson.h>

  7. /*按鍵模擬輸入的值,按鍵的誤差范圍在之后會(huì)設(shè)置為正負(fù)30*/
  8. #define exit_bt 930
  9. #define left_bt 648
  10. #define right_bt  393
  11. #define enter_bt  144
  12. #define null_bt 22      //不按按鍵時(shí)的值(由于會(huì)受外界干擾不為0)


  13. #define City_Code_MAX 35              //城市數(shù)量(0~35)
  14. #define MAX_CONTENT_SIZE  1000        //接受http響應(yīng)內(nèi)容的最大字節(jié)數(shù)
  15. #define HTTP_TIMEOUT  5000            //最大響應(yīng)時(shí)間

  16. /*幾個(gè)要用到的類(lèi)的對(duì)象定義*/
  17. File myFile;                          //讀取sd卡數(shù)據(jù)
  18. U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI oled(U8G2_R0, 10, 9, 5);      //驅(qū)動(dòng)屏幕
  19. WiFiClient client;                    //客戶(hù)端聯(lián)接服務(wù)器

  20. /*全局變量*/
  21. unsigned char selected[200];          //用于存放取反(黑白倒置)后的圖像,做成被選擇的效果
  22. unsigned char weather_lb[64];         //存放從sd卡中讀取的天氣字樣
  23. unsigned char weather_pb[512];        //存放從sd卡中讀取的天氣圖像
  24. char response[MAX_CONTENT_SIZE];      //存放http響應(yīng)的內(nèi)容
  25. char endOfHeaders[] = "\r\n\r\n";     //http響應(yīng)頭部結(jié)束的標(biāo)志

  26. bool has_net = false;           //判斷是否聯(lián)上網(wǎng)絡(luò)的標(biāo)志
  27. bool sd_initial = false;            //判斷初始化時(shí)是否成功讀取sd卡保存的上一次設(shè)置的標(biāo)志
  28. short int s = 0;                      //主界面中選擇的狀態(tài)
  29. short int City_Code = 35;               //當(dāng)前設(shè)置城市對(duì)應(yīng)的編碼(開(kāi)始時(shí)默認(rèn)為佛山)
  30. short int weather_Code = 99;            //http響應(yīng)內(nèi)容中天氣對(duì)應(yīng)的編碼(開(kāi)始默認(rèn)為未知)
  31. short int temper;                       //http響應(yīng)內(nèi)容中的溫度

  32. String City_ID = "WS06YNEMPP18";        //心知天氣中城市對(duì)應(yīng)的id,用于url合成
  33. String ssid = "";                       //配網(wǎng)時(shí)保存賬號(hào)
  34. String password = "";                   //配網(wǎng)時(shí)保存密碼

  35. const char* host = "api.seniverse點(diǎn)com";      //服務(wù)器網(wǎng)址
  36. const char* key = "smtq3n0ixdggurox";        //心知天氣api的密匙
  37. const char* language = "zh-Hans";            //設(shè)置響應(yīng)的語(yǔ)言-簡(jiǎn)體中文

  38. //此結(jié)構(gòu)在解析json數(shù)據(jù)時(shí)存放json中的"code",“溫度”
  39. struct WeatherData {
  40.   char code[8];         //天氣對(duì)應(yīng)的編碼
  41.   char temperature[8];  //溫度
  42. };


  43. /*函數(shù)*/
  44. void Get_initial_data();         //讀取上一次設(shè)置的城市
  45. void main_Interface();          //主界面
  46. void main_interface_draw();     //主界面繪圖函數(shù)

  47. void smart_Config();            //主界面中的“網(wǎng)絡(luò)”,配網(wǎng)連接wifi
  48. void config_draw(short int);    //“網(wǎng)絡(luò)”繪圖函數(shù)

  49. void city_Set();                              //主界面中的“工具”,設(shè)置城市
  50. void city_set_draw(short int, bool = false);  //“工具”繪圖函數(shù)
  51. void draw_city_character(short int, short int, short int);  //繪畫(huà)城市字樣函數(shù),三個(gè)形參分別是基準(zhǔn)點(diǎn)x,y坐標(biāo)及城市字樣對(duì)應(yīng)的數(shù)字
  52. void city_set_store();                                      //將設(shè)置城市保存到sd卡中

  53. void weather_Report();                                //主界面中的“天氣”,發(fā)送請(qǐng)求接收響應(yīng)內(nèi)容并顯示天氣
  54. bool SendRequest();                                   //發(fā)送請(qǐng)求
  55. bool skipResponseHeaders();                           //跳過(guò)響應(yīng)頭部
  56. void readReponseContent(char* );                      //將響應(yīng)的數(shù)據(jù)保存到content數(shù)組中
  57. bool AnalyseData(char* , struct WeatherData*);        //解析content中的josn數(shù)據(jù)
  58. void printData(const struct WeatherData* );           //打印解析后的數(shù)據(jù)(主要用來(lái)debug)
  59. void exchange(const struct WeatherData* );            //將解析后存在struct中的code和溫度從字符串轉(zhuǎn)換為整數(shù)
  60. void weather_Readpic();                               //讀取sd卡中對(duì)應(yīng)的天氣圖片及字樣
  61. void weather_report_draw();                           //繪制天氣顯示
  62. void request_fail();                                  //異常退出函數(shù)

  63. /*城市編碼和城市ID的鍵值對(duì)數(shù)組*/
  64. //sizeof:36X12B
  65. static const char *ID[] = {
  66. "WX4FBXXFKE4F", "WTW3SJ5ZBJUY", "WS0E9D8WN298", "WS10730EM8EV", "WECNV8ZNE40W", "WEBTFUSKS7HB", "WSQQMXBCC2VS", "WWGQDCW6TBW1", "WM7B0X53DZW2",
  67. "YB1UX38K6DY1", "WZC1EXZ0P9HU", "WXRVB9QYXKY8", "TZY33C4YJBP3", "WRR2Q2Z7CXWM", "WQGDF7NXZRZB", "WWC2MYYCM6J5", "WW8P3NH2TPDT", "WQ82K43YVYU8",
  68. "WWE0TGW4PX6N", "WQ3V4QR6VR6G", "WW0V9QP93VS8", "WQJ6YY8MHZP0", "WTSQQYHVQ973", "WTEMH46Z5N09", "WTMKQ069CCJ7", "WT3Q0FW9ZJ3Q", "WM6N2PM3WY2K",
  69. "WJ2B9TWGFBT5", "WT47HJP3HEMP", "WT029G15ETRJ", "WKEZD7MXE04F", "WSSU6EXX52RE", "WK3N92NQV6RQ", "WKJ1F428HH2F", "W7W3YQKE4QDH", "WS06YNEMPP18"
  70. };


  71. /*圖像(一般以pb開(kāi)頭)、文字(一般以lb開(kāi)頭)數(shù)組*/

  72. //開(kāi)機(jī)時(shí)的圖像: 88X50px length:550  sizeof:550B
  73. const unsigned char pb_start[] U8X8_PROGMEM= {
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  75. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x03,0x00,
  76. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x04,0x00,0x00,0x00,0xC0,0x07,0x7F,
  77. 0xF0,0x8F,0x81,0x21,0x0B,0x00,0x00,0x00,0xE0,0x0F,0xFF,0xF0,0x8F,0x83,0xA1,0x0A,
  78. 0x00,0x00,0x00,0x70,0x1C,0xC3,0x31,0x80,0x83,0xA1,0x06,0x60,0x00,0x00,0x30,0x18,
  79. 0x83,0x31,0x80,0x87,0x21,0x03,0xF0,0x00,0x00,0x30,0x18,0x83,0x31,0x80,0x8F,0x41,
  80. 0x08,0xC2,0x01,0x00,0x30,0x18,0x83,0x31,0x80,0x8D,0x81,0x87,0x87,0x01,0x00,0x30,
  81. 0x18,0x83,0xF1,0x8F,0x99,0x01,0xC0,0x83,0x03,0x00,0x30,0x18,0xC3,0xF0,0x8F,0x99,
  82. 0x01,0xC0,0x87,0x03,0x00,0x30,0x18,0xFF,0x30,0x80,0xB1,0x01,0x80,0x8C,0x03,0x00,
  83. 0x30,0x18,0x7F,0x30,0x80,0xF1,0x01,0x00,0x98,0x03,0x00,0x30,0x18,0x03,0x30,0x80,
  84. 0xE1,0x01,0x20,0xF0,0x03,0x00,0x30,0x18,0x03,0x30,0x80,0xC1,0x01,0x60,0xE0,0x01,
  85. 0x00,0x30,0x18,0x03,0x30,0x80,0xC1,0x01,0xC0,0xF0,0x00,0x00,0x70,0x1C,0x03,0xF0,
  86. 0x8F,0x81,0x01,0xF0,0xFF,0x01,0x00,0xE0,0x0F,0x03,0xF0,0x8F,0x81,0x01,0x70,0x3F,
  87. 0x03,0x00,0xC0,0x07,0x03,0x00,0x00,0x00,0x00,0x70,0x00,0x06,0x00,0x00,0x00,0x00,
  88. 0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  89. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  90. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  91. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  92. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFB,0xF9,0xE3,0xE7,0xC7,0xC3,
  93. 0xE3,0xE3,0xC7,0x0F,0xFC,0xFB,0xF9,0xE7,0xEF,0xE7,0xE7,0xF7,0xE7,0xCF,0x0F,0x60,
  94. 0x18,0xD8,0x66,0x6C,0xE0,0x66,0x36,0x66,0xCC,0x00,0x60,0x18,0xD8,0x66,0x6C,0x60,
  95. 0x60,0x30,0x66,0xCC,0x00,0x60,0x18,0xD8,0x66,0x6C,0x60,0x60,0x30,0x66,0xCC,0x00,
  96. 0x60,0xF8,0xD9,0x66,0xEC,0xE7,0x63,0x30,0x66,0xCC,0x0F,0x60,0xF8,0xD9,0xE6,0xE7,
  97. 0xC7,0x67,0x30,0xE6,0xC7,0x0F,0x60,0x18,0xD8,0xE6,0x63,0x00,0x66,0x30,0xE6,0xC3,
  98. 0x00,0x60,0x18,0xD8,0x66,0x60,0x00,0x66,0x30,0x66,0xC0,0x00,0x60,0x18,0xD8,0x66,
  99. 0x60,0x60,0x66,0x36,0x66,0xC0,0x00,0x60,0xF8,0xD9,0x66,0xE0,0xE7,0xE7,0xF7,0x67,
  100. 0xC0,0x0F,0x60,0xF8,0xD9,0x66,0xE0,0xC7,0xC3,0xE3,0x63,0xC0,0x0F,0x60,0x00,0x00,
  101. 0x60,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  102. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  103. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  104. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  105. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  106. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  107. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  108. 0x00,0x00,0x00,0x00,0x00,0x00
  109. };


  110. /*主界面中的圖像字樣*/
  111. //主界面中的"工具"圖像: 40X40px length:200  sizeof:200B
  112. const unsigned char pb_tool[] U8X8_PROGMEM = {
  113. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  114. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,
  115. 0x00,0x7C,0x00,0x40,0x06,0x00,0x63,0x00,0x40,0x0C,0x00,0x31,0x00,0x40,0x30,0x80,
  116. 0x18,0x04,0x80,0x20,0x80,0x08,0x06,0x80,0x60,0x40,0x08,0x05,0x00,0x41,0xC0,0x90,
  117. 0x04,0x00,0x42,0x80,0x60,0x04,0x00,0x9E,0xC0,0x00,0x04,0x00,0x30,0x61,0x00,0x02,
  118. 0x00,0x40,0x32,0x00,0x01,0x00,0x80,0x1C,0xFC,0x00,0x00,0x00,0x09,0x36,0x00,0x00,
  119. ……………………

  120. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
代碼,素材,文檔及工具.rar (249.46 KB, 下載次數(shù): 100)

評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏7 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:64089 發(fā)表于 2021-5-31 10:09 | 只看該作者
不錯(cuò)的資料正在學(xué)習(xí)中
回復(fù)

使用道具 舉報(bào)

板凳
ID:374259 發(fā)表于 2021-6-5 23:25 | 只看該作者

不錯(cuò)的資料,要是有實(shí)物圖就更好了
回復(fù)

使用道具 舉報(bào)

地板
ID:925265 發(fā)表于 2021-8-28 20:22 | 只看該作者
這不是別人免費(fèi)開(kāi)源的嗎
回復(fù)

使用道具 舉報(bào)

5#
ID:88256 發(fā)表于 2021-8-28 21:11 | 只看該作者
應(yīng)該上幾張圖片看看的
回復(fù)

使用道具 舉報(bào)

6#
ID:963223 發(fā)表于 2021-8-31 12:48 | 只看該作者
en  想看看,就是沒(méi)圖片?
回復(fù)

使用道具 舉報(bào)

7#
ID:291765 發(fā)表于 2021-9-4 16:41 | 只看該作者
謝謝UP的分享啊,學(xué)習(xí)了。
回復(fù)

使用道具 舉報(bào)

8#
ID:964490 發(fā)表于 2021-9-7 00:09 | 只看該作者
這是接的什么顯示設(shè)備
回復(fù)

使用道具 舉報(bào)

9#
ID:64253 發(fā)表于 2021-9-11 20:46 | 只看該作者
這個(gè)想象在B站有看到過(guò),是某up開(kāi)源的東西
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表