2017-12-1913:36:41
昨天按照B站的资料利用esp12F做了一个天气站,可预报天气,惭愧的是模型做好了,照片还没拍就夭折了,可怜了我20块的屏幕,我心伤悲,莫知我哀呀!
本来调试已经成功,运行还是很完美的,哎,手残。
碎了一个角,我的心也跟着碎了。
代码备份一下:
1 //http://flash.weather.com.cn/wmaps/xml/nanjing.xml 2 //http://flash.weather.com.cn/wmaps/xml/zhengzhou.xml 3 //http://www.pm25.in/api/querys/pm2_5.json?city=nanjing&token=5j1znBVAsnSf5xQyNQyq 4 //http://www.pm25.in/api/querys/pm2_5.json?city=zhengzhou&token=郑州 5 #include <ESP8266WiFi.h> 6 #include <ESP8266HTTPClient.h> 7 #include <Adafruit_ssd1306syp.h> 8 #define SDA_PIN 4 9 #define SCL_PIN 2 10 char ssid[] = "maker_space"; // WiFi名 SSID (name) 11 char pass[] = "chuangke666"; // WiFi密码 12 /*---------------------------------------------------------------*/ 13 const byte sunny[] = { 14 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 15 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x20,0x00,0x00, 16 0x00,0x00,0x1C,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0xF0,0x00,0x00, 17 0x00,0x00,0x1E,0x00,0x01,0xF0,0x00,0x00,0x00,0x00,0x1F,0x03,0x01,0xE0,0x00,0x00, 18 0x00,0x00,0x0F,0x03,0x01,0xE0,0x00,0x00,0x00,0x00,0x0F,0x03,0x83,0xE0,0x00,0x00, 19 0x00,0x00,0x0F,0x83,0x83,0xC0,0x00,0x00,0x00,0x00,0x07,0x83,0x87,0xC0,0x00,0x00, 20 0x00,0x00,0x07,0xC0,0x07,0x80,0x00,0x00,0x00,0x00,0x03,0x80,0x03,0x80,0x00,0x00, 21 0x00,0x03,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x03,0x80,0x00,0x00,0x07,0x80,0x00, 22 0x00,0x03,0xC0,0x1F,0xE0,0x0F,0x00,0x00,0x00,0x01,0xC0,0x7F,0xFC,0x0E,0x00,0x00, 23 0x00,0x00,0x81,0xF8,0xFF,0x00,0x00,0x40,0x0F,0x00,0x03,0xC0,0x3F,0x80,0x03,0xE0, 24 0x1F,0xC0,0x07,0x00,0x1F,0xC0,0x0F,0xE0,0x0F,0xF0,0x0E,0x0F,0xFF,0xE0,0x3F,0xE0, 25 0x07,0xFC,0x1C,0x3F,0xFF,0xF0,0xFF,0xC0,0x01,0xFC,0x38,0x7F,0xFF,0xF8,0x7E,0x00, 26 0x00,0x7C,0x31,0xFF,0xFF,0xF8,0x78,0x00,0x00,0x08,0x71,0xFF,0xFF,0xFC,0x00,0x00, 27 0x00,0x00,0x63,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x00,0x63,0xFF,0xFF,0xFC,0x00,0x00, 28 0x00,0x00,0xE3,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0xE7,0xFF,0xFF,0xFE,0x1C,0x00, 29 0x00,0xF0,0xE7,0xFF,0xFF,0xFE,0x1F,0x00,0x01,0xF0,0xE7,0xFF,0xFF,0xFE,0x3F,0x00, 30 0x01,0xF0,0xE3,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0xE3,0xFF,0xFF,0xFE,0x00,0x00, 31 0x00,0x00,0xE3,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x73,0xFF,0xFF,0xFC,0x00,0x00, 32 0x00,0x00,0x7F,0xFF,0xFF,0xFC,0x00,0x00,0x00,0x08,0x7F,0xFF,0xFF,0xFC,0x30,0x00, 33 0x00,0x3C,0x3F,0xFF,0xFF,0xF8,0x7C,0x00,0x01,0xFC,0x3F,0xFF,0xFF,0xF0,0x7F,0x80, 34 0x07,0xFE,0x1F,0xFF,0xFF,0xF0,0x7F,0xE0,0x0F,0xF8,0x0F,0xFF,0xFF,0xE0,0x1F,0xF0, 35 0x0F,0xC0,0x07,0xFF,0xFF,0xC0,0x03,0xE0,0x0F,0x00,0x03,0xFF,0xFF,0x80,0x00,0xE0, 36 0x00,0x00,0x40,0xFF,0xFE,0x06,0x00,0x00,0x00,0x00,0xE0,0x3F,0xF8,0x07,0x00,0x00, 37 0x00,0x01,0xE0,0x07,0xC0,0x07,0x80,0x00,0x00,0x03,0xC0,0x00,0x00,0x03,0x80,0x00, 38 0x00,0x03,0x80,0x00,0x00,0x81,0x80,0x00,0x00,0x00,0x03,0xC0,0x07,0xC0,0x00,0x00, 39 0x00,0x00,0x03,0xC1,0x87,0xC0,0x00,0x00,0x00,0x00,0x07,0xC3,0x83,0xC0,0x00,0x00, 40 0x00,0x00,0x07,0x83,0x83,0xE0,0x00,0x00,0x00,0x00,0x0F,0x83,0x81,0xE0,0x00,0x00, 41 0x00,0x00,0x0F,0x03,0x81,0xF0,0x00,0x00,0x00,0x00,0x1F,0x01,0x81,0xF0,0x00,0x00, 42 0x00,0x00,0x1E,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0xF0,0x00,0x00, 43 0x00,0x00,0x1E,0x00,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 44 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 45 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 46 }; 47 const byte cloudy[] = { 48 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x1E,0x30,0xE0,0x00,0x00,0x00,0x00,0x00,0x0E,0x30,0xE0,0x00,0x00,0x00,0x00,0x00,0x06,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x3F,0xE0,0x00,0x00,0x0E,0x00,0x00,0x00,0xFF,0xFC,0x01,0xFF,0x0C,0x00,0x00,0x03,0xFF,0xFE,0x07,0x87,0xC0,0x04,0x00,0x07,0xC0,0x1F,0x84,0x03,0xE0,0x7E,0x00,0x0F,0x80,0x07,0x80,0xFF,0xF1,0xFE,0x00,0x1E,0x00,0x01,0xE0,0xFF,0xF8,0xE0,0x00,0x1C,0x00,0x01,0xE0,0x3F,0xF8,0x80,0x00,0x3C,0x00,0x03,0xFC,0x0F,0xFC,0x00,0x00,0x38,0x00,0x07,0xFE,0x0F,0xFC,0x00,0x00,0x30,0x00,0x1F,0xFF,0x07,0xFC,0x00,0x00,0x70,0x00,0x3E,0x07,0xC3,0xFC,0xF0,0x00,0x70,0x00,0x7C,0x03,0xC3,0xFC,0xF0,0x03,0xFE,0x00,0x78,0x01,0xF1,0xFC,0x00,0x07,0xFF,0x00,0x30,0x00,0xF1,0xFC,0x00,0x0F,0x87,0x00,0x00,0x00,0x70,0xF8,0x80,0x1E,0x00,0x00,0x00,0x00,0x70,0xF8,0xE0,0x1E,0x00,0x00,0x00,0x00,0x30,0xF1,0xF8,0x1C,0x00,0x00,0x00,0x00,0x30,0xF0,0xFE,0x18,0x00,0x00,0x00,0x00,0x30,0xC0,0x1E,0x18,0x00,0x00,0x00,0x00,0x70,0xC4,0x00,0x1C,0x00,0x00,0x00,0x00,0x70,0x0E,0x00,0x1C,0x00,0x00,0x00,0x00,0xF0,0x07,0x00,0x1E,0x03,0x80,0x00,0x01,0xE0,0xC0,0x00,0x1F,0x03,0xC0,0x08,0x03,0xC0,0xC0,0x00,0x0F,0x8F,0xE0,0x1E,0x07,0xC0,0xE0,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0x80,0xE0,0x00,0x03,0xFE,0xFF,0xFF,0xFE,0x00,0x70,0x00,0x00,0x00,0x0F,0xE1,0xF8,0x00,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 49 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 50 }; 51 const byte cloudy2[] = { 52 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x7F,0xE0,0x3F,0xF0,0x00,0x00,0x00,0x00,0xFF,0x00,0x07,0xF8,0x00,0x00,0x00,0x01,0xFC,0x00,0x01,0xFC,0x00,0x00,0x00,0x03,0xF8,0x00,0x00,0x7E,0x00,0x00,0x00,0x03,0xE0,0x00,0x00,0x3F,0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x1F,0x00,0x00,0x00,0x0F,0x80,0x00,0x00,0x1F,0x80,0x00,0x00,0x0F,0x80,0x00,0x00,0x7F,0xF8,0x00,0x00,0x1F,0x00,0x00,0x01,0xFF,0xFE,0x00,0x00,0x1F,0x00,0x00,0x03,0xFF,0xFF,0x00,0x00,0x1E,0x00,0x00,0x07,0xFF,0xFF,0x80,0x00,0x1E,0x00,0x00,0x1F,0xE0,0x1F,0xE0,0x00,0x3E,0x00,0x00,0x1F,0x80,0x07,0xE0,0x00,0x7F,0x80,0x00,0x3F,0x00,0x03,0xF0,0x01,0xFF,0xE0,0x00,0x3E,0x00,0x01,0xF0,0x07,0xFF,0xF0,0x00,0x1C,0x00,0x00,0xF8,0x0F,0xFF,0xF0,0x00,0x00,0x00,0x00,0x78,0x1F,0xC0,0xF0,0x00,0x00,0x00,0x00,0x7C,0x1F,0x80,0x60,0x00,0x00,0x00,0x00,0x7C,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x7C,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x3E,0x00,0x1C,0x00,0x00,0x00,0x01,0xF0,0x3F,0x00,0x7E,0x00,0x03,0x00,0x03,0xF0,0x1F,0xC0,0xFF,0x80,0x07,0xC0,0x0F,0xE0,0x0F,0xFF,0xFF,0xF0,0x7F,0xF8,0x7F,0xC0,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x03,0xFF,0xE7,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0xC1,0xFF,0xFC,0xFF,0xFC,0x00,0x00,0x0C,0x00,0x7F,0xF0,0x3F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 53 }; 54 const byte rain[] = { 55 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x3F,0x80,0x00,0x00,0x00,0x00,0x01,0xFC,0x3F,0x80,0x00,0x00,0x00,0x00,0x03,0xF8,0x1F,0xC0,0x00,0x00,0x00,0x00,0x03,0xF8,0x0F,0xC0,0x00,0x00,0x00,0x00,0x07,0xF0,0x0F,0xE0,0x00,0x00,0x00,0x00,0x07,0xF0,0x07,0xF0,0x00,0x00,0x00,0x00,0x0F,0xE0,0x07,0xF0,0x00,0x00,0x00,0x00,0x0F,0xE0,0x03,0xF0,0x00,0x00,0x00,0x00,0x1F,0xC0,0x03,0xF8,0x00,0x00,0x00,0x00,0x1F,0x80,0x01,0xFC,0x00,0x00,0x00,0x00,0x3F,0x80,0x01,0xFC,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,0xFC,0x00,0x00,0x3F,0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x3F,0x80,0x00,0x00,0x01,0xF8,0x00,0x00,0x1F,0x80,0x00,0x00,0x01,0xF8,0x00,0x00,0x1F,0x80,0x00,0x00,0x01,0xF8,0x00,0x00,0x1F,0xC0,0x00,0x00,0x01,0xF8,0x00,0x00,0x0F,0xC0,0x00,0x00,0x03,0xF0,0x00,0x00,0x0F,0xC0,0x00,0x00,0x03,0xF0,0x00,0x00,0x0F,0xC0,0x00,0x00,0x03,0xF0,0x00,0x00,0x0F,0xC0,0x00,0x00,0x03,0xF0,0x00,0x00,0x0F,0xC0,0x00,0x00,0x03,0xF0,0x00,0x00,0x0F,0xC0,0x00,0x00,0x01,0xF8,0x00,0x00,0x0F,0xC0,0x00,0x00,0x01,0xF8,0x00,0x00,0x1F,0xC0,0x00,0x00,0x01,0xF8,0x00,0x00,0x1F,0x80,0x00,0x00,0x01,0xFC,0x00,0x00,0x3F,0x80,0x00,0x00,0x00,0xFE,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0xFE,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x7F,0x80,0x00,0xFF,0x00,0x00,0x00,0x00,0x7F,0xC0,0x03,0xFE,0x00,0x00,0x00,0x00,0x3F,0xF0,0x0F,0xFC,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 56 }; 57 /*---------------------------------------------------------------------*/ 58 59 const byte tp1[] = { 60 0x00,0x40,0x40,0x40,0x27,0xFC,0x20,0x40,0x03,0xF8,0x00,0x40,0xE7,0xFE,0x20,0x00, 61 0x23,0xF8,0x22,0x08,0x23,0xF8,0x22,0x08,0x2B,0xF8,0x32,0x08,0x22,0x28,0x02,0x10 62 }; 63 const byte tp2[] = { 64 65 0x08,0x20,0x1D,0x24,0xF0,0xA4,0x10,0xA8,0x10,0x20,0xFD,0xFC,0x11,0x04,0x31,0x04, 66 0x39,0xFC,0x55,0x04,0x55,0x04,0x91,0xFC,0x11,0x04,0x11,0x04,0x11,0x14,0x11,0x08 67 }; 68 const byte tp3[] = { 69 0x00,0x10,0x00,0xF8,0x1F,0x00,0x10,0x00,0x10,0x00,0x1F,0xFE,0x10,0x00,0x10,0x00, 70 0x10,0x00,0x17,0xF8,0x14,0x08,0x24,0x08,0x24,0x08,0x44,0x08,0x87,0xF8,0x04,0x08 71 }; 72 const byte tp4[] = { 73 0x00,0x00,0x7F,0xFC,0x40,0x04,0x40,0x04,0x42,0x14,0x52,0x94,0x4A,0x54,0x44,0x24, 74 0x44,0x24,0x4A,0x54,0x4A,0x54,0x52,0x94,0x61,0x04,0x40,0x04,0x40,0x14,0x40,0x08, 75 }; 76 const byte tp5[] = { 77 0x10,0x80,0x10,0x80,0x20,0xF8,0x21,0x08,0x4B,0x10,0xFC,0xA0,0x10,0x40,0x20,0xA0, 78 0x41,0x18,0xFA,0x06,0x45,0xF8,0x01,0x08,0x19,0x08,0xE1,0x08,0x41,0xF8,0x01,0x08, 79 }; 80 const byte tp6[] = { 81 0x08,0x40,0x08,0x20,0x0B,0xFE,0x10,0x00,0x10,0x00,0x31,0xFC,0x30,0x00,0x50,0x00, 82 0x91,0xFC,0x10,0x00,0x10,0x00,0x11,0xFC,0x11,0x04,0x11,0x04,0x11,0xFC,0x11,0x04, 83 }; 84 const byte tp7[] = { 85 0x01,0x00,0x02,0x00,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10, 86 0x1F,0xF0,0x10,0x10,0x01,0x00,0x08,0x84,0x48,0x92,0x48,0x12,0x87,0xF0,0x00,0x00, 87 }; 88 const byte ssd[] = {0x00,0xB0,0x48,0x40,0x40,0x48,0x30,0x00}; 89 Adafruit_ssd1306syp display(SDA_PIN,SCL_PIN); 90 String payload = ""; //获取数据储存变量 91 String payload1 = ""; 92 String webadd = "http://flash.weather.com.cn/wmaps/xml/zhengzhou.xml"; //接口地址 93 String pmadd = "http://www.pm25.in/api/querys/pm2_5.json?city=zhengzhou&token=郑州"; 94 int time1 = 0; //WIFI等待时间(500ms) 95 int sta,sta2; 96 String com,tem1,tem2,humi,temnow,state1,state2,pm,pm2; 97 String sun[] = {"Sunny","Cloudy","Overcast"," "," "," "," ","Rain"," "," ","Snow"}; 98 void setup() 99 { 100 delay(1000); 101 display.initialize(); 102 WiFi.begin(ssid, pass); 103 init1(); 104 } 105 void loop(){ 106 http(); 107 data(); 108 inof1(); 109 inof2(); 110 show(); 111 } 112 /********************************************开机自启*********************************************/ 113 void init1(){ //启动wifi连接 114 display.drawBitmap(0, 0, tp1, 16, 16, WHITE); 115 display.drawBitmap(16, 0, tp2, 16, 16, WHITE); 116 display.drawBitmap(32, 0, tp3, 16, 16, WHITE); 117 display.setCursor(0,16); 118 display.setTextSize(1); 119 display.setTextColor(WHITE); 120 display.print("Connect to "); 121 display.println(ssid); 122 display.setCursor(0,55); 123 display.setTextSize(1); 124 display.setTextColor(WHITE); 125 display.println("Power by Wen Zheng"); 126 display.update(); 127 display.setCursor(0,32); 128 display.setTextSize(1); 129 display.setTextColor(WHITE); 130 while (WiFi.status() != WL_CONNECTED) { 131 delay(500); 132 // Serial.print("."); 133 display.print("."); 134 display.update(); 135 time1++; 136 while(time1>21) 137 { 138 display.clear(); 139 display.setCursor(0,0); 140 display.setTextSize(1); 141 display.setTextColor(WHITE); 142 // Serial.println("Error:Unable to connect to WIFI"); 143 display.println("Error:"); 144 display.setCursor(0,16); 145 display.setTextSize(1); 146 display.setTextColor(WHITE); 147 display.println("Unable to connect to WIFI"); 148 display.update(); 149 delay(10000); 150 } 151 } 152 display.clear(); 153 display.drawBitmap(0, 0, tp4, 16, 16, WHITE); 154 display.drawBitmap(16, 0, tp5, 16, 16, WHITE); 155 display.drawBitmap(32, 0, tp6, 16, 16, WHITE); 156 display.drawBitmap(48, 0, tp7, 16, 16, WHITE); 157 display.setCursor(0,16); 158 display.print("SSID:"); 159 display.println(ssid); 160 display.print("IP: "); 161 display.println(WiFi.localIP()); 162 // Serial.println("IP address: "); 163 // Serial.println(WiFi.localIP()); 164 165 //display.print("WEB: "); 166 //display.println(webadd); 167 display.update(); 168 delay(2000); 169 display.clear(); 170 } 171 /*****************************************http数据获取*******************************************/ 172 void http(){ 173 HTTPClient http; 174 http.begin(webadd); 175 int httpCode = http.GET(); 176 if(httpCode > 0) { 177 // if(httpCode == HTTP_CODE_OK) { 178 payload = http.getString(); 179 int a = payload.indexOf("101190104"); 180 com = payload.substring(a-280,a+12); 181 // } 182 } 183 http.end(); 184 } 185 /*****************************************数据处理**********************************************/ 186 void data(){ 187 int i=0; 188 i=com.indexOf("tem1"); 189 tem1=com.substring(i+5,i+9); 190 i=0; 191 i=com.indexOf("tem2"); 192 tem2=com.substring(i+5,i+9); 193 i=0; 194 i=com.indexOf("umidity"); 195 humi=com.substring(i+8,i+13); 196 i=0; 197 i=com.indexOf("state1"); 198 state1=com.substring(i+7,i+11); 199 i=0; 200 i=com.indexOf("state2"); 201 state2=com.substring(i+7,i+11); 202 i=0; 203 i=com.indexOf("temNow"); 204 temnow=com.substring(i+7,i+10); 205 i=0; 206 tem1.replace('"',' '); 207 tem2.replace('"',' '); 208 humi.replace('"',' '); 209 temnow.replace('"',' '); 210 humi.replace('%',' '); 211 state1.replace('"',' '); 212 state2.replace('"',' '); 213 } 214 /*************************************OLED显示函数********************************************/ 215 void show(){ 216 display.drawBitmap(120, 16, ssd, 5, 8, WHITE); 217 display.drawBitmap(120, 24, ssd, 5, 8, WHITE); 218 display.drawBitmap(120, 32, ssd, 5, 8, WHITE); 219 display.setTextSize(1); 220 display.setTextColor(WHITE); 221 display.setCursor(120,40); 222 display.println("%"); 223 display.update(); 224 display.setTextSize(1); 225 display.setTextColor(WHITE); 226 display.setCursor(64,16); 227 display.print("Max:"); 228 display.println(tem1); 229 display.setCursor(64,24); 230 display.print("Now:"); 231 display.println(temnow); 232 display.setCursor(64,32); 233 display.print("Min:"); 234 display.println(tem2); 235 display.setCursor(64,40); 236 display.print("Humi"); 237 display.println(humi); 238 //display.setCursor(64,48); 239 //display.print("PM2.5:"); 240 //display.println(pm2); 241 /* 242 if(sta != sta2){ 243 display.setTextSize(1); 244 display.setTextColor(BLACK, WHITE); 245 display.print("{"+sun[sta]+"}"); 246 display.print("--"); 247 display.println("{"+sun[sta2]+"}"); 248 } 249 if(sta == sta2){ 250 display.setTextSize(1); 251 display.setTextColor(BLACK, WHITE); 252 display.println("{"+sun[sta]+"}"); 253 } 254 255 display.update(); 256 delay(20000); 257 display.clear(); 258 */ 259 if(sta == 1){ 260 display.drawBitmap(0, 0, sunny, 64, 64, WHITE); 261 } 262 else if(sta == 2) 263 { 264 display.drawBitmap(0, 0, cloudy, 64, 64, WHITE); 265 } 266 else if(sta == 3) 267 { 268 display.drawBitmap(0, 0, cloudy2, 64, 64, WHITE); 269 } 270 else if(sta == 7) 271 { 272 display.drawBitmap(0, 0, rain, 64, 64, WHITE); 273 } 274 } 275 /*********************************天气判断函数****************************/ 276 void inof1(){ 277 if(state1==" 0 ") 278 { 279 sta=1; 280 } 281 else if(state1==" 1 ") 282 { 283 sta=1; 284 } 285 else if(state1==" 2 ") 286 { 287 sta=2; 288 } 289 else if(state1==" 3 ") 290 { 291 sta=3; 292 } 293 else if(state1==" 4 ") 294 { 295 sta=4; 296 } 297 else if(state1==" 5 ") 298 { 299 sta=5; 300 } 301 else if(state1==" 6 ") 302 { 303 sta=6; 304 } 305 else if(state1==" 7 ") 306 { 307 sta=7; 308 } 309 else if(state1==" 8 ") 310 { 311 sta=7; 312 } 313 else if(state1==" 9 ") 314 { 315 sta=7; 316 } 317 else if(state1==" 10 ") 318 { 319 sta=7; 320 } 321 else if(state1==" 11 ") 322 { 323 sta=8; 324 } 325 else if(state1==" 12 ") 326 { 327 sta=9; 328 } 329 else if(state1==" 13 ") 330 { 331 sta=10; 332 } 333 else if(state1==" 14 ") 334 { 335 sta=10; 336 } 337 else if(state1==" 15 ") 338 { 339 sta=10; 340 } 341 else if(state1==" 16 ") 342 { 343 sta=10; 344 } 345 } 346 void inof2(){ 347 if(state2==" 0 ") 348 { 349 sta2=0; 350 } 351 else if(state2==" 1 ") 352 { 353 sta2=1; 354 } 355 else if(state2==" 2 ") 356 { 357 sta2=2; 358 } 359 else if(state2==" 3 ") 360 { 361 sta2=3; 362 } 363 else if(state2==" 4 ") 364 { 365 sta2=4; 366 } 367 else if(state2==" 5 ") 368 { 369 sta2=5; 370 } 371 else if(state2==" 6 ") 372 { 373 sta2=6; 374 } 375 else if(state2==" 7 ") 376 { 377 sta2=7; 378 } 379 else if(state2==" 8 ") 380 { 381 sta2=7; 382 } 383 else if(state2==" 9 ") 384 { 385 sta2=7; 386 } 387 else if(state2==" 10 ") 388 { 389 sta2=7; 390 } 391 else if(state2==" 11 ") 392 { 393 sta=8; 394 } 395 else if(state2==" 12 ") 396 { 397 sta2=9; 398 } 399 else if(state2==" 13 ") 400 { 401 sta2=10; 402 } 403 else if(state2==" 14 ") 404 { 405 sta2=10; 406 } 407 else if(state2==" 15 ") 408 { 409 sta2=10; 410 } 411 else if(state2==" 16 ") 412 { 413 sta2=10; 414 } 415 } 416 /* 417 void pm25(){ 418 HTTPClient http; 419 http.begin(pmadd); 420 int httpCode = http.GET(); 421 if(httpCode > 0) { 422 // if(httpCode == HTTP_CODE_OK) { 423 payload1 = http.getString(); 424 pm = payload1.substring(0,35); 425 // } 426 } 427 http.end(); 428 429 int i,i2; 430 i=pm.indexOf("pm2_5"); 431 pm2=pm.substring(i+6,i+9); 432 pm.replace(':',' '); 433 pm.replace(',',' '); 434 Serial.println(payload1); 435 Serial.println(pm); 436 437 } 438 */