最完整程序:基于Arduino的ESP8266天气预报设计

文章只涉及程序部分,评论区有完整文件下载链接,有需要自行下载
最完整程序:基于Arduino的ESP8266天气预报设计_第1张图片
最完整程序:基于Arduino的ESP8266天气预报设计_第2张图片
整个程序:经过多次验证有效。

#include
#include
#include
#include
#include
#include

/*按键模拟输入的值,按键的误差范围在之后会设置为正负30*/
#define exit_bt 930
#define left_bt 648
#define right_bt  393
#define enter_bt  144
#define null_bt 22      //不按按键时的值(由于会受外界干扰不为0)


#define City_Code_MAX 35              //城市数量(0~35)
#define MAX_CONTENT_SIZE  1000        //接受http响应内容的最大字节数
#define HTTP_TIMEOUT  5000            //最大响应时间

/*几个要用到的类的对象定义*/
File myFile;                          //读取sd卡数据
U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI oled(U8G2_R0, 10, 9, 5);      //驱动屏幕
WiFiClient client;                    //客户端联接服务器

/*全局变量*/
unsigned char selected[200];          //用于存放取反(黑白倒置)后的图像,做成被选择的效果
unsigned char weather_lb[64];         //存放从sd卡中读取的天气字样
unsigned char weather_pb[512];        //存放从sd卡中读取的天气图像
char response[MAX_CONTENT_SIZE];      //存放http响应的内容
char endOfHeaders[] = "\r\n\r\n";     //http响应头部结束的标志

bool has_net = false;           //判断是否联上网络的标志
bool sd_initial = false;            //判断初始化时是否成功读取sd卡保存的上一次设置的标志
short int s = 0;                      //主界面中选择的状态
short int City_Code = 35;               //当前设置城市对应的编码(开始时默认为佛山)
short int weather_Code = 99;            //http响应内容中天气对应的编码(开始默认为未知)
short int temper;                       //http响应内容中的温度

String City_ID = "WS06YNEMPP18";        //心知天气中城市对应的id,用于url合成
String ssid = "";                       //配网时保存账号
String password = "";                   //配网时保存密码

const char* host = "api.seniverse.com";      //服务器网址
const char* key = "smtq3n0ixdggurox";        //心知天气api的密匙
const char* language = "zh-Hans";            //设置响应的语言-简体中文

//此结构在解析json数据时存放json中的"code",“温度”
struct WeatherData {
  char code[8];         //天气对应的编码
  char temperature[8];  //温度
};


/*函数*/
void Get_initial_data();         //读取上一次设置的城市
void main_Interface();          //主界面
void main_interface_draw();     //主界面绘图函数

void smart_Config();            //主界面中的“网络”,配网连接wifi
void config_draw(short int);    //“网络”绘图函数

void city_Set();                              //主界面中的“工具”,设置城市
void city_set_draw(short int, bool = false);  //“工具”绘图函数
void draw_city_character(short int, short int, short int);  //绘画城市字样函数,三个形参分别是基准点x,y坐标及城市字样对应的数字
void city_set_store();                                      //将设置城市保存到sd卡中

void weather_Report();                                //主界面中的“天气”,发送请求接收响应内容并显示天气
bool SendRequest();                                   //发送请求
bool skipResponseHeaders();                           //跳过响应头部
void readReponseContent(char* );                      //将响应的数据保存到content数组中
bool AnalyseData(char* , struct WeatherData*);        //解析content中的josn数据
void printData(const struct WeatherData* );           //打印解析后的数据(主要用来debug)
void exchange(const struct WeatherData* );            //将解析后存在struct中的code和温度从字符串转换为整数
void weather_Readpic();                               //读取sd卡中对应的天气图片及字样
void weather_report_draw();                           //绘制天气显示
void request_fail();                                  //异常退出函数

/*城市编码和城市ID的键值对数组*/
//sizeof:36X12B
static const char *ID[] = {
"WX4FBXXFKE4F", "WTW3SJ5ZBJUY", "WS0E9D8WN298", "WS10730EM8EV", "WECNV8ZNE40W", "WEBTFUSKS7HB", "WSQQMXBCC2VS", "WWGQDCW6TBW1", "WM7B0X53DZW2",
"YB1UX38K6DY1", "WZC1EXZ0P9HU", "WXRVB9QYXKY8", "TZY33C4YJBP3", "WRR2Q2Z7CXWM", "WQGDF7NXZRZB", "WWC2MYYCM6J5", "WW8P3NH2TPDT", "WQ82K43YVYU8",
"WWE0TGW4PX6N", "WQ3V4QR6VR6G", "WW0V9QP93VS8", "WQJ6YY8MHZP0", "WTSQQYHVQ973", "WTEMH46Z5N09", "WTMKQ069CCJ7", "WT3Q0FW9ZJ3Q", "WM6N2PM3WY2K",
"WJ2B9TWGFBT5", "WT47HJP3HEMP", "WT029G15ETRJ", "WKEZD7MXE04F", "WSSU6EXX52RE", "WK3N92NQV6RQ", "WKJ1F428HH2F", "W7W3YQKE4QDH", "WS06YNEMPP18"
};


/*图像(一般以pb开头)、文字(一般以lb开头)数组*/

//开机时的图像: 88X50px length:550  sizeof:550B 
const unsigned char pb_start[] U8X8_PROGMEM= {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x03,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x04,0x00,0x00,0x00,0xC0,0x07,0x7F,
0xF0,0x8F,0x81,0x21,0x0B,0x00,0x00,0x00,0xE0,0x0F,0xFF,0xF0,0x8F,0x83,0xA1,0x0A,
0x00,0x00,0x00,0x70,0x1C,0xC3,0x31,0x80,0x83,0xA1,0x06,0x60,0x00,0x00,0x30,0x18,
0x83,0x31,0x80,0x87,0x21,0x03,0xF0,0x00,0x00,0x30,0x18,0x83,0x31,0x80,0x8F,0x41,
0x08,0xC2,0x01,0x00,0x30,0x18,0x83,0x31,0x80,0x8D,0x81,0x87,0x87,0x01,0x00,0x30,
0x18,0x83,0xF1,0x8F,0x99,0x01,0xC0,0x83,0x03,0x00,0x30,0x18,0xC3,0xF0,0x8F,0x99,
0x01,0xC0,0x87,0x03,0x00,0x30,0x18,0xFF,0x30,0x80,0xB1,0x01,0x80,0x8C,0x03,0x00,
0x30,0x18,0x7F,0x30,0x80,0xF1,0x01,0x00,0x98,0x03,0x00,0x30,0x18,0x03,0x30,0x80,
0xE1,0x01,0x20,0xF0,0x03,0x00,0x30,0x18,0x03,0x30,0x80,0xC1,0x01,0x60,0xE0,0x01,
0x00,0x30,0x18,0x03,0x30,0x80,0xC1,0x01,0xC0,0xF0,0x00,0x00,0x70,0x1C,0x03,0xF0,
0x8F,0x81,0x01,0xF0,0xFF,0x01,0x00,0xE0,0x0F,0x03,0xF0,0x8F,0x81,0x01,0x70,0x3F,
0x03,0x00,0xC0,0x07,0x03,0x00,0x00,0x00,0x00,0x70,0x00,0x06,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFB,0xF9,0xE3,0xE7,0xC7,0xC3,
0xE3,0xE3,0xC7,0x0F,0xFC,0xFB,0xF9,0xE7,0xEF,0xE7,0xE7,0xF7,0xE7,0xCF,0x0F,0x60,
0x18,0xD8,0x66,0x6C,0xE0,0x66,0x36,0x66,0xCC,0x00,0x60,0x18,0xD8,0x66,0x6C,0x60,
0x60,0x30,0x66,0xCC,0x00,0x60,0x18,0xD8,0x66,0x6C,0x60,0x60,0x30,0x66,0xCC,0x00,
0x60,0xF8,0xD9,0x66,0xEC,0xE7,0x63,0x30,0x66,0xCC,0x0F,0x60,0xF8,0xD9,0xE6,0xE7,
0xC7,0x67,0x30,0xE6,0xC7,0x0F,0x60,0x18,0xD8,0xE6,0x63,0x00,0x66,0x30,0xE6,0xC3,
0x00,0x60,0x18,0xD8,0x66,0x60,0x00,0x66,0x30,0x66,0xC0,0x00,0x60,0x18,0xD8,0x66,
0x60,0x60,0x66,0x36,0x66,0xC0,0x00,0x60,0xF8,0xD9,0x66,0xE0,0xE7,0xE7,0xF7,0x67,
0xC0,0x0F,0x60,0xF8,0xD9,0x66,0xE0,0xC7,0xC3,0xE3,0x63,0xC0,0x0F,0x60,0x00,0x00,
0x60,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00
};


/*主界面中的图像字样*/
//主界面中的"工具"图像: 40X40px length:200  sizeof:200B
const unsigned char pb_tool[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,
0x00,0x7C,0x00,0x40,0x06,0x00,0x63,0x00,0x40,0x0C,0x00,0x31,0x00,0x40,0x30,0x80,
0x18,0x04,0x80,0x20,0x80,0x08,0x06,0x80,0x60,0x40,0x08,0x05,0x00,0x41,0xC0,0x90,
0x04,0x00,0x42,0x80,0x60,0x04,0x00,0x9E,0xC0,0x00,0x04,0x00,0x30,0x61,0x00,0x02,
0x00,0x40,0x32,0x00,0x01,0x00,0x80,0x1C,0xFC,0x00,0x00,0x00,0x09,0x36,0x00,0x00,
0x00,0x12,0x01,0x00,0x00,0x00,0xA7,0x00,0x00,0x00,0x80,0xC9,0x00,0x00,0x00,0xC0,
0x90,0x0C,0x00,0x00,0x60,0x30,0x1B,0x00,0x00,0x30,0xC8,0x31,0x00,0x00,0x18,0x44,
0x64,0x00,0x00,0x0C,0x42,0xC8,0x00,0x00,0x06,0x41,0x92,0x01,0x00,0x83,0xC0,0x24,
0x03,0x80,0x49,0x80,0x49,0x06,0xC0,0x24,0x00,0x93,0x04,0x60,0x12,0x00,0x26,0x04,
0x20,0x09,0x00,0x0C,0x04,0x20,0x04,0x00,0x18,0x04,0x40,0x02,0x00,0x30,0x03,0x80,
0x01,0x00,0xC0,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
};

//主界面中的"网络"图像: 40X40px length:200  sizeof:200B
const unsigned char pb_net[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0xFF,0x00,0x00,0x00,0xE0,0xFF,0x07,0x00,0x00,0xF8,0xFB,0x1F,0x00,0x00,0xFE,
0x99,0x7F,0x00,0x00,0xEF,0x18,0xF7,0x00,0x80,0xE7,0x18,0xC6,0x00,0x80,0x73,0x18,
0xC6,0x01,0xC0,0x71,0x18,0x8E,0x03,0xE0,0x30,0x18,0x0C,0x07,0xE0,0x3F,0x18,0xFC,
0x07,0xE0,0xFF,0xFF,0xFF,0x0F,0x70,0xFC,0xFF,0x7F,0x0C,0x30,0x18,0x18,0x18,0x0C,
0x30,0x18,0x18,0x18,0x1C,0x38,0x18,0x18,0x18,0x1C,0x38,0x18,0x18,0x00,0x18,0x38,
0x18,0x18,0x1E,0x18,0x38,0x18,0xD8,0x7F,0x18,0x38,0x18,0xE0,0xF7,0x01,0x30,0x18,
0xE0,0xC0,0x01,0x30,0x18,0x70,0x80,0x03,0x70,0xF8,0x37,0x00,0x03,0xF0,0xFF,0x37,
0x00,0x07,0xE0,0x3F,0x30,0x00,0x07,0xE0,0x30,0x30,0x00,0x07,0xC0,0x70,0x30,0x00,
0x07,0xC0,0x63,0x70,0x00,0x03,0x80,0xE7,0xE0,0xC0,0x03,0x00,0xCF,0xE0,0xE3,0x03,
0x00,0xFE,0xC1,0xFF,0x07,0x00,0xF8,0x03,0x3E,0x0F,0x00,0xF0,0x3F,0x00,0x1E,0x00,
0x80,0x3F,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

//主界面中的“天气”图像:  40X40px length:200  sizeof:200B
const unsigned char pb_weather[]  U8X8_PROGMEM= {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x60,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x60,0x20,0x00,0x00,0xC0,0x00,
0x70,0x00,0x00,0xC0,0xF1,0x38,0x00,0x00,0x80,0xFD,0x13,0x00,0x00,0x00,0x0E,0x07,
0x00,0x00,0x00,0x06,0x0E,0x00,0x00,0x00,0x03,0x1C,0x00,0x00,0x70,0x03,0xF8,0x01,
0x00,0x70,0x03,0xFC,0x0F,0x00,0x00,0x03,0x0E,0x1C,0x00,0x00,0x03,0x07,0x38,0x00,
0x40,0x07,0x03,0x30,0x00,0xE0,0xE6,0x01,0xF0,0x00,0x70,0xFC,0x01,0xE0,0x03,0x20,
0x18,0x00,0x00,0x07,0x80,0x1F,0x00,0x00,0x0E,0xC0,0x01,0x00,0x00,0x1C,0xE0,0x00,
0x00,0x00,0x18,0x60,0x00,0x00,0x00,0x18,0x60,0x00,0x00,0x00,0x18,0x60,0x00,0x00,
0x00,0x1C,0x60,0x00,0x00,0x00,0x0E,0xE0,0xC0,0x03,0x00,0x07,0xC0,0xFF,0xFF,0xFF,
0x03,0x80,0x1F,0xFC,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0xC3,0x30,0x00,
0x00,0x0C,0xC3,0x30,0x00,0x00,0x0C,0xC3,0x30,0x00,0x00,0x0C,0xC3,0x30,0x00,0x00,
0x0C,0xC3,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 
};


//主界面中的电池图像: 16X8px length:16  sizeof:16B
const unsigned char battery[] U8X8_PROGMEM = {
0xFF,0x1F,0x01,0x10,0xFD,0xF7,0xFD,0x97,0xFD,0x97,0xFD,0xF7,0x01,0x10,0xFF,0x1F
};

//主界面中的未联网图像: 8X8px length:8  sizeof:8B
const unsigned char off_line[] U8X8_PROGMEM ={
0x3C,0x42,0xA5,0x99,0x99,0xA5,0x42,0x3C
};

//主界面中的有网络图像: 8X8px length:8  sizeof:8B
const unsigned char on_line[] U8X8_PROGMEM ={
0x3C,0x42,0x81,0x18,0x24,0x00,0x18,0x18
};

//主界面中的“菜单”字样: 24X13px length:39 sizeof:39B
const unsigned char lb_menu[] U8X8_PROGMEM = {
0x08,0x82,0x20,0xFF,0x1F,0x11,0x08,0xC2,0x7F,0x00,0x4F,0x44,0xFE,0xC4,0x7F,0x24,
0x44,0x44,0x48,0x42,0x44,0x40,0xC0,0x7F,0xFF,0x1F,0x04,0xE0,0x00,0x04,0x50,0xE1,
0xFF,0x4C,0x06,0x04,0x43,0x18,0x04  
};

//主界面中的“工具”字样: 24X13px length:39 sizeof:39B
const unsigned char lb_tool[] U8X8_PROGMEM = {
0xFF,0xE3,0x3F,0x20,0x20,0x20,0x20,0xE0,0x3F,0x20,0x20,0x20,0x20,0xE0,0x3F,0x20,
0x20,0x20,0x20,0xE0,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF8,0xFF,0x20,0x80,
0x08,0xFF,0x43,0x10,0x00,0x20,0x20
};

//主界面中的“网络”字样: 24X13px length:39 sizeof:39B
const unsigned char lb_net[] U8X8_PROGMEM = {
0xFF,0x0F,0x11,0x01,0x88,0x10,0x21,0x4A,0xF0,0x65,0x2A,0x89,0xA9,0xEA,0x55,0x11,
0x89,0x20,0x11,0x49,0x50,0xA9,0x2A,0x88,0xA9,0xEA,0x05,0x45,0x08,0xF8,0x23,0x08,
0x88,0x01,0x88,0x89,0x01,0x6E,0xF8 
};

//主界面中的“天气”字样: 24X13px length:39 sizeof:39B
const unsigned char lb_weather[] U8X8_PROGMEM = {
0x00,0x80,0x00,0xFC,0x87,0x7F,0x40,0x40,0x00,0x40,0x40,0x00,0x40,0x20,0x3F,0xFE,
0x0F,0x00,0x40,0x00,0x00,0xA0,0x80,0x3F,0xA0,0x00,0x20,0x10,0x01,0x20,0x08,0x02,
0xA0,0x04,0x04,0xA0,0x03,0x18,0xC0 
};


/*"网络"中的图像字样*/
//满格WiFi图像: 48*48px length:288  sizeof:288
const unsigned char pb_signal_full[] U8X8_PROGMEM= {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x03,0xe0,0xff,0xff,0xff,0x3f,0x00,0x00,
0xfc,0xff,0xff,0x07,0x00,0x00,0xe0,0xff,0xff,0x01,0x00,0x00,0x80,0xff,0x7f,0x00,0x00,0x00,0x00,0xfe,
0x3f,0x00,0x00,0x00,0x00,0xfc,0x0f,0x00,0xe8,0x17,0x00,0xf0,0x07,0x00,0xff,0xff,0x01,0xe0,0x03,0xe0,
0xff,0xff,0x07,0xc0,0x00,0xf8,0xff,0xff,0x1f,0x80,0x01,0xfe,0x0f,0xf8,0x7f,0x00,0x03,0xff,0x01,0x00,
0xff,0xc0,0xc3,0x3f,0x00,0x00,0xfc,0xc3,0xef,0x0f,0x00,0x00,0xf0,0xf7,0xff,0x07,0x00,0x00,0xe0,0xff,
0xff,0x01,0x00,0x00,0x80,0xff,0xff,0x00,0x40,0x01,0x00,0xff,0xff,0x00,0xfc,0x3f,0x00,0xff,0xff,0x00,
0xff,0xff,0x00,0xff,0xff,0xc3,0xff,0xff,0xc3,0xff,0xff,0xe3,0x7f,0xff,0xc7,0xff,0xff,0xff,0x07,0xe0,
0xff,0xff,0xff,0xff,0x01,0x80,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0x7f,0x00,0x00,0xfe,0xff,
0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xe3,0xc7,0xff,0xff,0xff,0xff,
0xfb,0xdf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,0x1f,0xf8,
0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,
0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x1f,0xf8,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}; 

//两格WiFi图像: 48*48px length:288  sizeof:288
const unsigned char pb_signal_mid[] U8X8_PROGMEM= {
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0f,0xf8,0xff,0xff,0xff,0xff,0x01,0x00,
  0xff,0xff,0xff,0x3f,0x00,0x00,0xfc,0xff,0xff,0x0f,0x00,0x00,0xf0,0xff,0xff,0x07,0x00,0x00,0xe0,0xff,
  0xff,0x01,0x00,0x00,0x80,0xff,0xff,0x00,0x40,0x01,0x00,0xff,0xff,0x00,0xfc,0x3f,0x00,0xff,0xff,0x00,
  0xff,0xff,0x00,0xff,0xff,0xc3,0xff,0xff,0xc3,0xff,0xff,0xe3,0x7f,0xff,0xc7,0xff,0xff,0xff,0x07,0xe0,
  0xff,0xff,0xff,0xff,0x01,0x80,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0x7f,0x00,0x00,0xfe,0xff,
  0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xe3,0xc7,0xff,0xff,0xff,0xff,
  0xfb,0xdf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,0x1f,0xf8,
  0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,
  0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x1f,0xf8,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};

//一格WiFi图像: 48*48px length:288  sizeof:288
const unsigned char pb_signal_low[] U8X8_PROGMEM= {
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0xff,0xff,0xff,0xff,0xff,0x07,0xe0,
  0xff,0xff,0xff,0xff,0x01,0x80,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0x7f,0x00,0x00,0xfe,0xff,
  0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xe3,0xc7,0xff,0xff,0xff,0xff,
  0xfb,0xdf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,0x1f,0xf8,
  0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,
  0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x1f,0xf8,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};

//零格WiFi图像 : 48*48px length:288  sizeof:288
const unsigned char pb_signal_none[] U8X8_PROGMEM= {
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,0x1f,0xf8,
  0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x0f,0xf0,0xff,0xff,
  0xff,0xff,0x0f,0xf0,0xff,0xff,0xff,0xff,0x1f,0xf8,0xff,0xff,0xff,0xff,0x3f,0xfc,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};

//"连接中。。。"字样: 56X16px sizeof:112B
const unsigned char lb_config[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x84,0x00,0x20,0x00,0x00,0x04,0x01,
0x04,0x01,0x20,0x00,0x00,0xE8,0x1F,0xE4,0x0F,0xFF,0x07,0x00,0x88,0x00,0x5F,0x04,
0x21,0x04,0x00,0x40,0x02,0x84,0x02,0x21,0x04,0x00,0x40,0x02,0xF4,0x1F,0x21,0x04,
0x00,0xEE,0x1F,0x84,0x00,0x21,0x04,0x00,0x08,0x02,0x8C,0x00,0x21,0x04,0x00,0x08,
0x02,0xF7,0x1F,0xFF,0x07,0x00,0xE8,0x3F,0x44,0x04,0x21,0x04,0x00,0x08,0x02,0x64,
0x02,0x20,0x00,0x00,0x08,0x02,0x84,0x01,0x20,0x38,0xE7,0x14,0x02,0x44,0x06,0x20,
0x28,0xA5,0xE2,0x3F,0x37,0x08,0x20,0x38,0xE7,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

//"重新"字样: 32X16px sizeof:64B
const unsigned char lb_renew[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x00,0x00,0x1F,0x10,0x20,0xFC,0x00,0xFE,0x1E,
0x80,0x00,0x00,0x02,0xFF,0x7F,0x44,0x02,0x80,0x00,0x28,0x02,0xF8,0x0F,0xFF,0x7E,
0x88,0x08,0x10,0x12,0xF8,0x0F,0x10,0x12,0x88,0x08,0xFE,0x12,0xF8,0x0F,0x10,0x12,
0x80,0x00,0x54,0x12,0xFC,0x1F,0x92,0x12,0x80,0x00,0x11,0x11,0xFF,0x7F,0x14,0x11
};

//"是"字样: 16X16px sizeof:32B
const unsigned char lb_yes[] U8X8_PROGMEM = {
0x00,0x00,0xF8,0x0F,0x08,0x08,0x08,0x08,0xF8,0x0F,0x08,0x08,0x08,0x08,0xF8,0x0F,
0x00,0x00,0xFF,0x7F,0x80,0x00,0x90,0x00,0x90,0x1F,0xA8,0x00,0x48,0x00,0x84,0x3F 
};

//"否"字样: 16X16px sizeof:32B
const unsigned char lb_no[] U8X8_PROGMEM = {
0x00,0x00,0xFE,0x3F,0x00,0x01,0x80,0x00,0xC0,0x00,0xA0,0x06,0x90,0x18,0x8C,0x20,
0x83,0x40,0x00,0x00,0xF8,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0xF8,0x0F,0x08,0x08  
};


/*“工具”中的字样(城市字样)*/
//所有城市字样都是: 32X16px sizeof:36X64B
//依次为:北上广深港澳台津渝及各省的省会
const unsigned char Beijing[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x20,0x02,0x40,0x00,0x20,0x02,0x80,0x00,0x20,0x02,0xFF,0x7F,
0x20,0x22,0x00,0x00,0x20,0x12,0x00,0x00,0x3E,0x0A,0xF8,0x0F,0x20,0x06,0x08,0x08,
0x20,0x02,0x08,0x08,0x20,0x02,0x08,0x08,0x20,0x02,0xF8,0x0F,0x20,0x02,0x80,0x00,
0x20,0x42,0x88,0x08,0x38,0x42,0x88,0x10,0x27,0x42,0x84,0x20,0x22,0x7C,0xA2,0x20
};
const unsigned char Shanghai[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x40,0x00,0x80,0x00,0x40,0x00,0x84,0x00,0x40,0x00,0x88,0x3F,
0x40,0x00,0x48,0x00,0x40,0x00,0xA1,0x1F,0x40,0x00,0x82,0x10,0xC0,0x1F,0x92,0x12,
0x40,0x00,0x90,0x14,0x40,0x00,0xE8,0x7F,0x40,0x00,0x88,0x10,0x40,0x00,0x47,0x12,
0x40,0x00,0x44,0x14,0x40,0x00,0xC4,0x3F,0x40,0x00,0x04,0x10,0xFF,0x7F,0x04,0x0A  
};
const unsigned char Guangzhou[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0x08,0x20,0x00,0x01,0x08,0x21,0x00,0x01,0x08,0x21,
0xFC,0x3F,0x08,0x21,0x04,0x00,0x08,0x21,0x04,0x00,0x2A,0x25,0x04,0x00,0x4A,0x29,
0x04,0x00,0x4A,0x29,0x04,0x00,0x09,0x21,0x04,0x00,0x08,0x21,0x04,0x00,0x08,0x21,
0x04,0x00,0x08,0x21,0x04,0x00,0x04,0x21,0x02,0x00,0x04,0x21,0x02,0x00,0x02,0x20  
};
const unsigned char Shenzhen[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0xE4,0x3F,0x88,0x20,0x28,0x20,0x88,0x24,0x28,0x25,0x88,0x24,
0x81,0x08,0x88,0x24,0x42,0x10,0x88,0x24,0x02,0x02,0xBF,0x24,0x08,0x02,0x88,0x24,
0xE8,0x3F,0x88,0x24,0x04,0x02,0x88,0x24,0x07,0x07,0x88,0x24,0x84,0x0A,0x88,0x24,
0x44,0x12,0xB8,0x24,0x34,0x62,0x87,0x24,0x04,0x02,0x42,0x24,0x00,0x02,0x40,0x20  
};
const unsigned char Hongkong[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x0E,0x80,0x08,0xF8,0x01,0x84,0x08,0x80,0x00,0xE8,0x3F,
0x80,0x00,0x88,0x08,0xFF,0x7F,0x81,0x08,0xA0,0x02,0xF2,0x7F,0x90,0x04,0x82,0x08,
0x8C,0x18,0x48,0x10,0xFB,0x6F,0xE8,0x2F,0x08,0x08,0x54,0x48,0x08,0x08,0x47,0x08,
0xF8,0x0F,0xC4,0x0F,0x08,0x08,0x44,0x20,0x08,0x08,0x44,0x20,0xF8,0x0F,0x84,0x3F  
};
const unsigned char Macao[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x01,0x04,0x00,0x84,0x00,0xC8,0x3F,0xE8,0x3F,0x08,0x20,
0x28,0x22,0x02,0x20,0xA1,0x2A,0x02,0x20,0x22,0x22,0x02,0x20,0xE2,0x3F,0x02,0x20,
0x28,0x27,0x02,0x20,0xA8,0x2A,0x02,0x20,0x24,0x20,0x02,0x20,0x07,0x02,0x02,0x20,
0xF4,0x7F,0x02,0x20,0x04,0x05,0x02,0x20,0x84,0x08,0x02,0x28,0x44,0x10,0x02,0x30 
};
const unsigned char Taipei[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x40,0x00,0x20,0x02,0x40,0x00,0x20,0x02,0x20,0x00,0x20,0x02,
0x10,0x04,0x20,0x22,0x08,0x08,0x20,0x12,0x04,0x10,0x3E,0x0A,0xFE,0x3F,0x20,0x06,
0x04,0x20,0x20,0x02,0x00,0x00,0x20,0x02,0xF8,0x0F,0x20,0x02,0x08,0x08,0x20,0x02,
0x08,0x08,0x20,0x42,0x08,0x08,0x38,0x42,0x08,0x08,0x27,0x42,0xF8,0x0F,0x22,0x7C  
};
const unsigned char Tianjin[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0xFC,0x1F,0x00,0x02,0x80,0x00,0x04,0x02,0x80,0x00,0xC8,0x1F,
0x80,0x00,0x08,0x12,0x80,0x00,0xE1,0x7F,0xFF,0x7F,0x02,0x12,0x80,0x00,0xD2,0x1F,
0x40,0x01,0x10,0x02,0x40,0x01,0x08,0x02,0x20,0x02,0xC8,0x1F,0x20,0x02,0x07,0x02,
0x10,0x04,0x04,0x02,0x08,0x08,0xE4,0x3F,0x04,0x10,0x04,0x02,0x03,0x60,0x04,0x02  
};
const unsigned char Chongqing[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x00,0x1F,0x00,0x01,0xFC,0x00,0xFC,0x7F,
0x80,0x00,0x04,0x00,0xFF,0x7F,0x04,0x01,0x80,0x00,0x04,0x01,0xF8,0x0F,0x04,0x01,
0x88,0x08,0xF4,0x3F,0xF8,0x0F,0x04,0x01,0x88,0x08,0x84,0x02,0xF8,0x0F,0x84,0x02,
0x80,0x00,0x44,0x04,0xFC,0x1F,0x42,0x04,0x80,0x00,0x22,0x08,0xFF,0x7F,0x11,0x10  
};
const unsigned char Harbin[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x80,0x80,0x00,0x10,0x80,0x80,0x40,0xFE,
0x4E,0xC1,0x9F,0x42,0x2A,0x42,0x10,0x3C,0x1A,0x2C,0x4A,0x04,0xEA,0x03,0x82,0x7C,
0x0A,0x80,0x0A,0x24,0xEE,0x43,0x92,0xFE,0x2A,0x22,0x92,0x00,0x20,0x82,0xC2,0x28,
0xE0,0x03,0x83,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00  
};
const unsigned char Changchun[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x10,0x00,0x80,0x00,0x10,0x08,0x80,0x00,0x10,0x04,0xFE,0x3F,
0x10,0x02,0x80,0x00,0x10,0x01,0xFC,0x1F,0x90,0x00,0x40,0x00,0x10,0x00,0xFF,0x7F,
0xFF,0x7F,0x10,0x04,0x50,0x00,0x08,0x08,0x90,0x00,0xF4,0x17,0x10,0x01,0x13,0x64,
0x10,0x02,0xF0,0x07,0x90,0x04,0x90,0x04,0x50,0x18,0x90,0x04,0x30,0x60,0xF0,0x07  
};
const unsigned char Shenyang[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x02,0x3E,0x00,0x04,0x02,0xA2,0x3F,0x08,0x02,0x92,0x20,
0xE8,0x7F,0x92,0x20,0x21,0x22,0x8A,0x20,0x12,0x12,0x92,0x20,0x02,0x02,0x92,0x20,
0x08,0x05,0xA2,0x3F,0x08,0x05,0xA2,0x20,0x04,0x05,0xA2,0x20,0x87,0x04,0x96,0x20,
0x84,0x04,0x8A,0x20,0x44,0x44,0x82,0x20,0x44,0x44,0x82,0x3F,0x24,0x78,0x82,0x20  
};
const unsigned char Urumchi[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x08,0x02,0x00,0x08,0x04,0x3E,0x10,0x10,0x3E,0x11,0x10,0xFF,
0xA2,0xFE,0x10,0x24,0x22,0x92,0xFE,0x24,0x3A,0xFE,0x10,0x18,0x02,0x92,0x38,0x24,
0x7E,0xFF,0x55,0xC3,0x40,0x00,0x54,0x24,0x40,0xFE,0x92,0x24,0x7F,0x82,0x92,0x24,
0x40,0xFE,0x11,0x25,0x48,0x82,0x10,0x22,0x70,0xFE,0x10,0x22,0x00,0x00,0x00,0x00  
};
const unsigned char Hohhot[] U8X8_PROGMEM = {
0xC0,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x57,0x01,0x01,0x21,0xE5,0x44,0x01,0x79,
0x45,0xC8,0x4F,0x21,0xF5,0x21,0xC1,0x23,0x47,0x04,0x41,0xFD,0x50,0xE8,0x2F,0x21,
0x60,0x00,0x00,0x23,0x08,0x10,0x80,0xFD,0xE6,0xD8,0x4F,0x21,0xA4,0x48,0x08,0x2D,
0xAF,0x44,0x08,0x21,0xA4,0xC4,0x0F,0x29,0xEE,0x00,0x00,0x31,0x15,0x00,0x00,0x00  
};
const unsigned char Yinchuan[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x20,0x88,0x1F,0x08,0x21,0xBC,0x10,0x08,0x21,
0x84,0x10,0x08,0x21,0x82,0x1F,0x08,0x21,0xBD,0x10,0x08,0x21,0x88,0x10,0x08,0x21,
0x88,0x1F,0x08,0x21,0xBF,0x22,0x08,0x21,0x88,0x12,0x08,0x21,0x88,0x0C,0x08,0x21,
0x88,0x04,0x08,0x21,0xA8,0x08,0x04,0x21,0x98,0x12,0x04,0x21,0x88,0x61,0x02,0x20  
};
const unsigned char Shijiazhuang[] U8X8_PROGMEM = {
0x00,0x40,0x00,0x00,0x00,0x80,0x00,0x04,0xFF,0xFD,0x0F,0x04,0x10,0x04,0xC8,0x3F,
0x08,0x02,0x40,0x00,0x08,0xF8,0x47,0x04,0x04,0x40,0x40,0x04,0xFE,0xA1,0x46,0x04,
0x05,0x91,0x41,0x3F,0x04,0x41,0x43,0x04,0x04,0x39,0x45,0x04,0x04,0x81,0x49,0x04,
0x04,0x41,0x21,0x04,0xFC,0x31,0xA1,0x7F,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00  
};
const unsigned char Taiyuan[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0xFC,0x7F,0x80,0x00,0x04,0x01,0x80,0x00,0x84,0x00,
0x80,0x00,0xE4,0x0F,0x80,0x00,0x24,0x08,0xFF,0x7F,0x24,0x08,0x80,0x00,0xE4,0x0F,
0x80,0x00,0x24,0x08,0x40,0x01,0x24,0x08,0x40,0x01,0xE4,0x0F,0x20,0x02,0x04,0x01,
0x20,0x02,0x24,0x09,0x50,0x04,0x12,0x11,0x88,0x08,0x4A,0x21,0x84,0x10,0x81,0x00  
};
const unsigned char Xining[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0xFF,0x7F,0x40,0x00,0x20,0x02,0x80,0x00,0x20,0x02,0x80,0x00,
0x20,0x02,0xFE,0x7F,0xFC,0x1F,0x02,0x40,0x24,0x12,0x01,0x20,0x24,0x12,0x00,0x00,
0x24,0x12,0xFC,0x1F,0x24,0x12,0x80,0x00,0x14,0x1C,0x80,0x00,0x0C,0x10,0x80,0x00,
0x04,0x10,0x80,0x00,0x04,0x10,0x80,0x00,0xFC,0x1F,0x80,0x00,0x04,0x10,0xA0,0x00  
};
const unsigned char Jinan[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x04,0x02,0x80,0x00,0xE8,0x7F,0xFF,0x7F,
0x48,0x10,0x80,0x00,0x81,0x08,0x80,0x00,0x02,0x05,0xFE,0x3F,0x02,0x02,0x12,0x24,
0x88,0x0D,0x22,0x22,0x68,0x70,0xF2,0x27,0x84,0x08,0x82,0x20,0x87,0x08,0x82,0x20,
0x84,0x08,0xFA,0x2F,0x84,0x08,0x82,0x20,0x44,0x08,0x82,0x20,0x44,0x08,0x82,0x28  
};
const unsigned char Lanzhou[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x20,0x10,0x08,0x08,0x21,0x20,0x04,0x08,0x21,
0x20,0x02,0x08,0x21,0x00,0x00,0x08,0x21,0xFE,0x3F,0x2A,0x25,0x00,0x00,0x4A,0x29,
0x00,0x00,0x4A,0x29,0x00,0x00,0x09,0x21,0xFC,0x1F,0x08,0x21,0x00,0x00,0x08,0x21,
0x00,0x00,0x08,0x21,0x00,0x00,0x04,0x21,0x00,0x00,0x04,0x21,0xFF,0x7F,0x02,0x20  
};
const unsigned char Zhengzhou[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x44,0x00,0x08,0x20,0x48,0x7C,0x08,0x21,0x28,0x44,0x08,0x21,
0xFE,0x24,0x08,0x21,0x10,0x24,0x08,0x21,0x10,0x14,0x2A,0x25,0x10,0x24,0x4A,0x29,
0xFF,0x25,0x4A,0x29,0x10,0x44,0x09,0x21,0x10,0x44,0x08,0x21,0x28,0x44,0x08,0x21,
0x48,0x2C,0x08,0x21,0x84,0x14,0x04,0x21,0x82,0x04,0x04,0x21,0x01,0x04,0x02,0x20  
};
const unsigned char Xian[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0xFF,0x7F,0x40,0x00,0x20,0x02,0x80,0x00,0x20,0x02,0xFC,0x3F,
0x20,0x02,0x04,0x20,0xFC,0x1F,0x42,0x10,0x24,0x12,0x40,0x00,0x24,0x12,0x40,0x00,
0x24,0x12,0xFF,0x7F,0x24,0x12,0x20,0x04,0x14,0x1C,0x10,0x04,0x0C,0x10,0x18,0x02,
0x04,0x10,0x60,0x02,0x04,0x10,0x80,0x01,0xFC,0x1F,0x40,0x06,0x04,0x10,0x30,0x08  
};
const unsigned char Nanjing[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0x40,0x00,0x80,0x00,0x80,0x00,0xFF,0x7F,0xFF,0x7F,
0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0xFE,0x3F,0xF8,0x0F,0x12,0x24,0x08,0x08,
0x22,0x22,0x08,0x08,0xF2,0x27,0x08,0x08,0x82,0x20,0xF8,0x0F,0x82,0x20,0x80,0x00,
0xFA,0x2F,0x88,0x08,0x82,0x20,0x88,0x10,0x82,0x20,0x84,0x20,0x82,0x28,0xA2,0x20  
};
const unsigned char Hefei[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0xBC,0x3F,0x40,0x01,0xA4,0x24,
0x20,0x02,0xA4,0x24,0x10,0x04,0xA4,0x24,0x0C,0x18,0xBC,0x24,0xF3,0x67,0xA4,0x24,
0x00,0x00,0xA4,0x3F,0x00,0x00,0xA4,0x20,0xF8,0x0F,0xBC,0x00,0x08,0x08,0xA4,0x00,
0x08,0x08,0xA4,0x00,0x08,0x08,0xA4,0x40,0x08,0x08,0xA2,0x40,0xF8,0x0F,0x2A,0x7F  
};
const unsigned char Hangzhou[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x08,0x01,0x08,0x20,0x08,0x02,0x08,0x21,0x08,0x02,0x08,0x21,
0xC8,0x3F,0x08,0x21,0x3F,0x00,0x08,0x21,0x08,0x00,0x2A,0x25,0x8C,0x0F,0x4A,0x29,
0x9C,0x08,0x4A,0x29,0xAA,0x08,0x09,0x21,0xAA,0x08,0x08,0x21,0x89,0x08,0x08,0x21,
0x88,0x48,0x08,0x21,0x88,0x48,0x04,0x21,0x48,0x48,0x04,0x21,0x48,0x70,0x02,0x20  
};
const unsigned char Wuhan[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x02,0xE4,0x1F,0x00,0x0A,0x48,0x10,0xFC,0x12,0x48,0x10,
0x00,0x12,0x41,0x10,0x00,0x02,0x82,0x08,0xFF,0x7F,0x92,0x08,0x00,0x02,0x90,0x08,
0x20,0x02,0x08,0x05,0x20,0x02,0x08,0x05,0xE4,0x02,0x07,0x02,0x24,0x04,0x04,0x02,
0x24,0x44,0x04,0x05,0x24,0x48,0x84,0x08,0xE4,0x51,0x44,0x10,0x1F,0x60,0x30,0x60  
};
const unsigned char Chengdu[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x0A,0x10,0x00,0x00,0x12,0x10,0x7D,0x00,0x02,0x7E,0x45,
0xFC,0x7F,0x90,0x24,0x04,0x02,0x50,0x24,0x04,0x02,0xFF,0x17,0x04,0x22,0x10,0x24,
0x7C,0x22,0x08,0x24,0x44,0x22,0xFC,0x44,0x44,0x14,0x86,0x44,0x44,0x14,0x85,0x44,
0x44,0x48,0xFC,0x2C,0x54,0x4C,0x84,0x14,0x22,0x52,0x84,0x04,0x02,0x61,0xFC,0x04  
};
const unsigned char Lhasa[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x08,0x02,0x20,0x02,0x08,0x04,0x20,0x02,0x08,0x04,0xFF,0x7F,
0x08,0x00,0x20,0x02,0xDF,0x7F,0x00,0x04,0x08,0x00,0xBE,0x3F,0x28,0x20,0x22,0x11,
0x98,0x20,0x12,0x0A,0x8C,0x20,0x8A,0x7F,0x0B,0x11,0x92,0x00,0x08,0x11,0xA2,0x00,
0x08,0x11,0xA2,0x00,0x08,0x09,0xAA,0x00,0x08,0x08,0x92,0x00,0xEA,0x7F,0x42,0x00  
};
const unsigned char Nanchang[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0xF8,0x0F,0x80,0x00,0x08,0x08,0xFF,0x7F,0x08,0x08,
0x80,0x00,0xF8,0x0F,0x80,0x00,0x08,0x08,0xFE,0x3F,0x08,0x08,0x12,0x24,0xF8,0x0F,
0x22,0x22,0x00,0x00,0xF2,0x27,0xFC,0x1F,0x82,0x20,0x04,0x10,0x82,0x20,0x04,0x10,
0xFA,0x2F,0xFC,0x1F,0x82,0x20,0x04,0x10,0x82,0x20,0x04,0x10,0x82,0x28,0xFC,0x1F 
};
const unsigned char Changsha[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x02,0x10,0x08,0x04,0x02,0x10,0x04,0x08,0x02,
0x10,0x02,0x88,0x12,0x10,0x01,0x81,0x22,0x90,0x00,0x42,0x42,0x10,0x00,0x42,0x42,
0xFF,0x7F,0x28,0x12,0x50,0x00,0x08,0x12,0x90,0x00,0x04,0x12,0x10,0x01,0x07,0x08,
0x10,0x02,0x04,0x08,0x90,0x04,0x04,0x04,0x50,0x18,0x04,0x02,0x30,0x60,0x84,0x01  
};
const unsigned char Guiyang[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0x3E,0x00,0xF8,0x0F,0xA2,0x3F,0x88,0x08,0x92,0x20,
0x88,0x08,0x92,0x20,0xF8,0x0F,0x8A,0x20,0x80,0x00,0x92,0x20,0xFF,0x7F,0x92,0x20,
0x00,0x00,0xA2,0x3F,0xF8,0x0F,0xA2,0x20,0x08,0x08,0xA2,0x20,0x88,0x08,0x96,0x20,
0x88,0x08,0x8A,0x20,0x88,0x08,0x82,0x20,0x40,0x06,0x82,0x3F,0x30,0x18,0x82,0x20 
};
const unsigned char Fuzhou[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x02,0x00,0x08,0x20,0xC4,0x7F,0x08,0x21,0x04,0x00,0x08,0x21,
0x9F,0x3F,0x08,0x21,0x88,0x20,0x08,0x21,0x88,0x20,0x2A,0x25,0x84,0x3F,0x4A,0x29,
0x0C,0x00,0x4A,0x29,0xD6,0x7F,0x09,0x21,0x55,0x44,0x08,0x21,0x44,0x44,0x08,0x21,
0xC4,0x7F,0x08,0x21,0x44,0x44,0x04,0x21,0x44,0x44,0x04,0x21,0xC4,0x7F,0x02,0x20  
};
const unsigned char Kunming[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0xFC,0x0F,0x00,0x3F,0x04,0x08,0x3E,0x21,0x04,0x08,0x22,0x21,
0xFC,0x0F,0x22,0x21,0x04,0x08,0x22,0x3F,0x04,0x08,0x3E,0x21,0xFC,0x0F,0x22,0x21,
0x00,0x00,0x22,0x21,0x04,0x01,0x22,0x3F,0x04,0x21,0x3E,0x21,0x7C,0x19,0x22,0x21,
0x04,0x07,0x80,0x20,0x04,0x21,0x80,0x20,0x64,0x21,0x40,0x28,0x1C,0x3E,0x20,0x10  
};
const unsigned char Nanning[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0x40,0x00,0x80,0x00,0x80,0x00,0xFF,0x7F,0x80,0x00,
0x80,0x00,0xFE,0x7F,0x80,0x00,0x02,0x40,0xFE,0x3F,0x01,0x20,0x12,0x24,0x00,0x00,
0x22,0x22,0xFC,0x1F,0xF2,0x27,0x80,0x00,0x82,0x20,0x80,0x00,0x82,0x20,0x80,0x00,
0xFA,0x2F,0x80,0x00,0x82,0x20,0x80,0x00,0x82,0x20,0x80,0x00,0x82,0x28,0xA0,0x00  
};
const unsigned char Haikou[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x84,0x00,0x00,0x00,0x88,0x3F,0xFC,0x1F,
0x48,0x00,0x04,0x10,0xA1,0x1F,0x04,0x10,0x82,0x10,0x04,0x10,0x92,0x12,0x04,0x10,
0x90,0x14,0x04,0x10,0xE8,0x7F,0x04,0x10,0x88,0x10,0x04,0x10,0x47,0x12,0x04,0x10,
0x44,0x14,0x04,0x10,0xC4,0x3F,0x04,0x10,0x04,0x10,0xFC,0x1F,0x04,0x0A,0x04,0x10  
};
const unsigned char Foshan[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x88,0x04,0x80,0x00,0x88,0x04,0x80,0x00,0x88,0x04,0x80,0x00,
0xF4,0x3F,0x80,0x00,0x84,0x24,0x84,0x10,0x86,0x24,0x84,0x10,0xE6,0x3F,0x84,0x10,
0xA5,0x04,0x84,0x10,0x94,0x04,0x84,0x10,0xF4,0x7F,0x84,0x10,0x84,0x44,0x84,0x10,
0x84,0x44,0x84,0x10,0x44,0x54,0x84,0x10,0x44,0x24,0xFC,0x1F,0x24,0x04,0x00,0x10  
};

//标记的小点点图像: 8X16px  sizeof:16B
const unsigned char lb_dot[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x3E,0x3E,0x3E,0x1C,0x00,0x00,0x00,0x00,0x00  
};

//"设置"字样: 32X16px sizeof:128B
const unsigned char lb_set[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x84,0x0F,0xFE,0x3F,0x88,0x08,0x22,0x22,0x88,0x08,0xFE,0x3F,
0x80,0x08,0x80,0x00,0x40,0x70,0xFE,0x3F,0x2F,0x00,0x80,0x00,0xC8,0x1F,0xF8,0x0F,
0x88,0x10,0x08,0x08,0x88,0x08,0xF8,0x0F,0x08,0x09,0x08,0x08,0x28,0x05,0xF8,0x0F,
0x18,0x02,0x08,0x08,0x08,0x05,0xF8,0x0F,0xC0,0x18,0x08,0x08,0x30,0x60,0xFF,0x7F  
};

//"1"字样: 8X13px sizeof:13B
const unsigned char lb_num1[] U8X8_PROGMEM = {
0x00,0x10,0x1C,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x7C,0x00
};
//"2"字样: 8X13px sizeof:13B
const unsigned char lb_num2[] U8X8_PROGMEM = {
0x00,0x3C,0x42,0x42,0x42,0x40,0x20,0x10,0x08,0x04,0x42,0x7E,0x00  
};
//"3"字样: 8X13px sizeof:13B
const unsigned char lb_num3[] U8X8_PROGMEM = {
0x00,0x3C,0x42,0x42,0x40,0x20,0x18,0x20,0x40,0x42,0x42,0x3C,0x00  
};
//"4"字样: 8X13px sizeof:13B
const unsigned char lb_num4[] U8X8_PROGMEM = {
0x00,0x20,0x30,0x30,0x28,0x24,0x24,0x22,0xFE,0x20,0x20,0xF8,0x00  
};
//"/"字样: 8X13px sizeof:13B
const unsigned char lb_slash[] U8X8_PROGMEM = {
0x40,0x20,0x20,0x20,0x10,0x10,0x08,0x08,0x08,0x04,0x04,0x02,0x02  
};

//"成功"字样: 32X16px sizeof:128B
const unsigned char lb_success[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x0A,0x00,0x02,0x00,0x12,0x00,0x02,0x00,0x02,0x00,0x02,
0xFC,0x7F,0x7F,0x02,0x04,0x02,0x88,0x3F,0x04,0x02,0x08,0x22,0x04,0x22,0x08,0x22,
0x7C,0x22,0x08,0x22,0x44,0x22,0x08,0x22,0x44,0x14,0x08,0x21,0x44,0x14,0x08,0x21,
0x44,0x48,0x78,0x21,0x54,0x4C,0x8F,0x20,0x22,0x52,0x82,0x20,0x02,0x61,0x40,0x14  
};

//“失败”字样:  32X16px sizeof:128B
const unsigned char lb_failure[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x02,0x88,0x00,0x3E,0x02,0x88,0x00,0x22,0x02,
0x88,0x00,0x2A,0x01,0xFC,0x1F,0x2A,0x7F,0x84,0x00,0xAA,0x10,0x82,0x00,0x6A,0x11,
0x80,0x00,0x2A,0x11,0xFF,0x7F,0x2A,0x11,0x40,0x01,0x2A,0x0A,0x20,0x02,0x2A,0x0A,
0x20,0x02,0x08,0x04,0x10,0x04,0x14,0x0A,0x08,0x08,0x24,0x11,0x04,0x10,0xA2,0x20  
};


/*“天气”中的图像字样*/

//“请求”字样: 32X16px
const unsigned char lb_request[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x02,0x80,0x04,0x02,0x02,0x80,0x08,0xE4,0x3F,0x80,0x00,
0x04,0x02,0xFE,0x3F,0xC0,0x1F,0x80,0x00,0x00,0x02,0x84,0x10,0xE7,0x7F,0x88,0x08,
0x04,0x00,0x90,0x05,0xC4,0x1F,0xC0,0x02,0x44,0x10,0xA0,0x04,0xC4,0x1F,0x90,0x08,
0x44,0x10,0x88,0x10,0xD4,0x1F,0x86,0x60,0x4C,0x10,0x80,0x00,0x44,0x14,0xA0,0x00  
};

//"中。。。"字样: 32X16px
const unsigned char lb_ing[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x00,0x00,
0x80,0x00,0x00,0x00,0xFC,0x1F,0x00,0x00,0x84,0x10,0x00,0x00,0x84,0x10,0x00,0x00,
0x84,0x10,0x00,0x00,0x84,0x10,0x00,0x00,0x84,0x10,0x00,0x00,0xFC,0x1F,0x00,0x00,
0x84,0x10,0x00,0x00,0x80,0x00,0xE7,0x1C,0x80,0x00,0xA5,0x14,0x80,0x00,0xE7,0x1C  
};


void setup() {
  delay(3000);
  ESP.wdtEnable(9000);             //设置看门狗复位的时间为9s
  Serial.begin(115200);
  pinMode(15,OUTPUT);               //将gpio15(SS)作为输出引脚,表明作为主机
  pinMode(10,OUTPUT);               //gpio10连接屏幕的片选(cs)
  pinMode(4,OUTPUT);                //gpio4连接sd卡模块片选(cs)
  client.setTimeout(HTTP_TIMEOUT);  //设置http最大响应时间为5s
  delay(100);

  if(SD.begin(4)){              //如果成功打开sd卡则读取上一次设置的城市
    sd_initial = true;          //成功初始化
    Get_initial_data();
  }
  else{                           //失败则拉高gpio4,拉低gpio10
    Serial.println("sd unopen");
    digitalWrite(4,HIGH);
    digitalWrite(10,LOW);
  }
  
  WiFi.mode(WIFI_STA);          //设置wifi为station模式
  WiFi.disconnect();            //断开网络连接,清除上一次保存的接入点
  delay(2000);
  
  oled.begin();                 //绘制开机图像
  oled.firstPage();
  do{
    oled.drawXBMP(20,7,88,50,pb_start);
  }while(oled.nextPage());

  while(analogRead(A0) <= null_bt + 30){ESP.wdtFeed();}     //随便按一个按键进入主界面,循环时要喂狗
  delay(700);
}

void loop() {

  s = 0;
  main_Interface();       //进入主界面
  
  if(s == 1)              //s的数值对应在主界面函数中的选择,1进入“工具”,2进入“网络”,3进入“天气”
    city_Set();
  else if(s == 2)
    smart_Config();
  else if(s == 3)
    weather_Report();
    
  delay(50);
}


void Get_initial_data(){              //初始化时读取sd卡上次设置保存的城市,保存在“INITIAL_DATA.txt”的文本中,以 #城市编码@ 的格式保存
  
    ESP.wdtFeed();                  //喂狗
    Serial.println("sd open");
    bool sy = false;                //读取标志,#开始,@结束        
    bool is_read = false;           //有无读取到数据的标志
    short int tmp = 0;
    digitalWrite(10,HIGH);        
    digitalWrite(4,LOW);          //拉低4拉高10,选择sd卡模块为从机
    delay(10);

    myFile = SD.open("INITIAL_DATA.txt", FILE_READ);
    delay(10);
    if(myFile){
      Serial.println("Read data..");
      while(myFile.available()){
        char ch = myFile.read();
        if(sy && ch >= 48 && ch <= 57){         //将读到的字符转换为数字
          tmp = tmp * 10 + (ch - 48);
        }
        if(ch == '#')
         sy = true;
        if(ch == '@')
         sy = false;

         delay(2);
      }
      is_read = true;
      Serial.println("read done");
      myFile.close();
    }
    else{
      Serial.println("error open");
    }
    if(tmp >= 0 && tmp <= City_Code_MAX && is_read){      //数据大于等于零,且小于等于最大城市编码,且是从sd卡中读取的,则认为合法
      City_Code = tmp;                                    //城市编码改变为从sd卡中读取的数据
      City_ID = String(FPSTR(ID[tmp]));                   //城市ID改变
      Serial.println(City_Code);
      Serial.println(City_ID);
    }
      
    digitalWrite(4,HIGH);
    digitalWrite(10,LOW);           //重新把屏幕作为从机
    delay(10);
    return ;
}



void main_Interface(){        //主界面函数,两层循环

  while(1){
    oled.firstPage();
    do{
      main_interface_draw();      //当进入主界面时或者小循环break时重新绘制
    }while(oled.nextPage());
    delay(150);
    
  while(1){
    ESP.wdtFeed();      //喂狗
    
    if(WiFi.status() != WL_CONNECTED && has_net){       //两种情况: 界面右上角网络标志显示有网实际没网,标志显示断网实际连接上网络,重绘页面
        WiFi.disconnect();
        WiFi.setAutoConnect(false);             //断网时,断开连接,取消自动连接
        has_net = false;
        break;
      }
    else if(WiFi.status() == WL_CONNECTED && !has_net){
      has_net = true;
      Serial.println("net ok");
      break;
    }
    
    int value = analogRead(A0);                           //时刻扫描A0口的读取数值
    if(value >= left_bt - 30 && value <= left_bt + 30){   //按下左键
      --s;
      if(s < 0)
        s = 3;
      break;
    }
    else if(value >= right_bt - 30 && value <= right_bt + 30){      //按下右键
      s = (s + 1) % 4;
      break; 
    }
    else if(value >= enter_bt - 30 && value <= enter_bt + 30 && s)    //按下回车
      return ;  
    }
  delay(4);
  }
}

void main_interface_draw(){             //主界面绘制函数

  if(has_net)
  oled.drawXBMP(102,0,8,8,on_line);
  else
  oled.drawXBMP(102,0,8,8,off_line);
  
  oled.drawXBMP(112,0,16,8,battery);
  
  if(s == 0){ 
    oled.drawXBMP(52,0,24,13,lb_menu);
    oled.drawXBMP(0,16,40,40,pb_tool);
    oled.drawXBMP(42,16,40,40,pb_net);
    oled.drawXBMP(84,16,40,40,pb_weather);
  }
  else if(s == 1){                            //选择菜单中哪个选项,则将图像数组元素取反,保存到全局数组中,显示此数组就有被选择的效果了
    oled.drawXBMP(52,0,24,13,lb_tool);
    for(int i = 0; i < 200; ++i){
      selected[i] = ~(unsigned char)pgm_read_byte(&pb_tool[i]);
    }
      
    delay(4);
    oled.drawXBM(0,16,40,40,selected);
    oled.drawXBMP(42,16,40,40,pb_net);
    oled.drawXBMP(84,16,40,40,pb_weather);
  }
  else if(s == 2){
    oled.drawXBMP(52,0,24,13,lb_net);
    for(int i = 0; i < 200; ++i){
      selected[i] = ~(unsigned char)pgm_read_byte(&pb_net[i]);
    }
      delay(4);
    oled.drawXBMP(0,16,40,40,pb_tool);
    oled.drawXBM(42,16,40,40,selected);
    oled.drawXBMP(84,16,40,40,pb_weather);
  }
  else if(s == 3){
    oled.drawXBMP(52,0,24,13,lb_weather);
   for(int i = 0; i < 200; ++i){
      selected[i] = ~(unsigned char)pgm_read_byte(&pb_weather[i]);
    }
      delay(4);
    oled.drawXBMP(0,16,40,40,pb_tool);
    oled.drawXBMP(42,16,40,40,pb_net);
    oled.drawXBM(84,16,40,40,selected);
  }
  delay(6);
  return ;
}



void smart_Config(){

  bool Reset = true;                //以一键配网还是wifi.begin()方式联网的标志
  short int signals = 0;            //四幅wifi图像画哪一幅
  short int times = 0;              //记录进入等待配网的时间,防止死循环,到时间未配网则退出
  WiFi.mode(WIFI_STA);
  WiFi.setAutoConnect(false);
  WiFi.stopSmartConfig();
  WiFi.disconnect();
  delay(1500);

  if(ssid != "" && password != ""){         //此前未配过网
    oled.firstPage();
    do{
      oled.drawXBMP(32,24,32,16,lb_renew);
      oled.drawXBMP(64,24,32,16,lb_set);
      oled.drawXBMP(32,44,16,16,lb_yes);
      oled.drawXBMP(80,44,16,16,lb_no);
    }while(oled.nextPage());

    while(1){
      ESP.wdtFeed();
      int value = analogRead(A0);
      if(value >= left_bt - 30 && value <= left_bt + 30){           //选了重新配网
        ssid = ""; password = ""; break;
      }
      else if(value >= right_bt - 30 && value <= right_bt + 30){      //选了以wifi.begin(ssid,password)的方式联网
        Reset = false; break;}
    }
  }
  
  if(Reset){                              //一键配网
    WiFi.beginSmartConfig();
    Serial.println("\n\rWait for smartConfig.");
    while(1){
      ESP.wdtFeed();
      oled.firstPage();
      do{
        config_draw(signals);
      }while(oled.nextPage());
      signals = (signals + 1) % 4;
    
      int value = analogRead(A0);
      if(value >= exit_bt - 30 && value <= exit_bt + 30){
        WiFi.stopSmartConfig();
        WiFi.setAutoConnect(false);
        WiFi.disconnect();
        delay(2000);
        return ;
      }
      delay(725);
    
      if(WiFi.smartConfigDone()){                       //配网成功
        Serial.println("smartconfig successed.");
        Serial.printf("SSID: %s\n\r", WiFi.SSID().c_str());
        Serial.printf("PSW: %s\n\r", WiFi.psk().c_str());
        ssid = WiFi.SSID();
        password = WiFi.psk();        //配网的账号密码保存起来以便联网不成功再次进入“网络”联接网络
        WiFi.setAutoConnect(true);
        break;
      }
      else if(times == 25){           //到时间未配网则退出
        WiFi.stopSmartConfig();
        WiFi.setAutoConnect(false);
        WiFi.disconnect();
        delay(2000);
        return ;
      }
      ++times;
    }
  }
  else{
    WiFi.begin(ssid.c_str(), password.c_str());       //选了否,wifi.begin(ssid,password)形式联网
    delay(100);
    while(WiFi.status() != WL_CONNECTED && times <= 11){
      ESP.wdtFeed();
      ++times;
      oled.firstPage();
      do{
        config_draw(signals);
      }while(oled.nextPage());
      signals = (signals + 1) % 4;
      delay(550);
    }
  }
  
  oled.firstPage();           //动态的wifi连接图片效果
    do{
      oled.drawXBMP(32,15,32,16,lb_set);
      oled.drawXBMP(64,15,32,16,lb_success);
    }while(oled.nextPage());
    delay(2000);
    return ;
}

void config_draw(short int k){
  if(k == 0)
    oled.drawXBMP(0,8,48,48,pb_signal_full);
  else if(k == 1)
    oled.drawXBMP(0,8,48,48,pb_signal_none);
  else if(k == 2)
    oled.drawXBMP(0,8,48,48,pb_signal_low);
  else if(k == 3)
    oled.drawXBMP(0,8,48,48,pb_signal_mid);

  oled.setFont(u8g2_font_osb18_tf);
  oled.drawStr(50,20,"WiFi");
  oled.drawXBMP(58,25,56,16,lb_config);
}



void city_Set(){                    //城市设置
  short int dpl = City_Code;
  while(1){
    oled.firstPage();
    do{
      city_set_draw(dpl);         //dpl为当前选择的城市编码
    }while(oled.nextPage());
    delay(150);

    while(1){
      ESP.wdtFeed();
      int value = analogRead(A0);
      if(value >= exit_bt - 30 && value <= exit_bt + 30)      //退出键直接退出
        return ;
      else if(value >= left_bt - 30 && value <= left_bt + 30){        //左键
        dpl--;
        if(dpl < 0)
        dpl = City_Code_MAX;
        Serial.println(dpl);
        delay(2);
        break;
      }
      else if(value >= right_bt - 30 && value <= right_bt + 30){    //右键
        dpl = (dpl + 1) % (City_Code_MAX + 1);
        Serial.println(dpl);
        delay(2);
        break;
      }
      else if(value >= enter_bt - 30 && value <= enter_bt + 30){      //确定键
        City_Code = dpl;
        City_ID = String(FPSTR(ID[dpl]));
        Serial.println(City_Code);
        Serial.println(City_ID);
        oled.firstPage();
        do{
          city_set_draw(-1, true);          //设置完成,绘制提示字样“设置成功”
        }while(oled.nextPage());
        delay(2000);
        ESP.wdtFeed();
        return ;
      }
      delay(4);
    }
  }
}

void city_set_draw(short int dpl, bool setdone){
  
  if(setdone){
    if(sd_initial){
      city_set_store();       //设置成功的时候把设置的城市编码写入sd卡
    }
    oled.drawXBMP(32,15,32,16,lb_set);
    oled.drawXBMP(64,15,32,16,lb_success);
    draw_city_character(48,33,City_Code);
    delay(2);
  }
  
  else{
    if(dpl / 9 == 0){
      oled.drawXBMP(52,51,8,13,lb_num1);
      oled.drawXBMP(60,51,8,13,lb_slash);
      oled.drawXBMP(68,51,8,13,lb_num4);
      
      oled.drawXBMP(8,0,32,16,Beijing);
      oled.drawXBMP(8,17,32,16,Shanghai);
      oled.drawXBMP(8,34,32,16,Guangzhou);

      oled.drawXBMP(48,0,32,16,Shenzhen);
      oled.drawXBMP(48,17,32,16,Hongkong);
      oled.drawXBMP(48,34,32,16,Macao);
      
      oled.drawXBMP(88,0,32,16,Taipei);
      oled.drawXBMP(88,17,32,16,Tianjin);
      oled.drawXBMP(88,34,32,16,Chongqing);

      short int cx = dpl / 3;
      short int cy = dpl % 3;
      oled.drawXBMP(cx*40, cy*17,8,16,lb_dot);
    }
    else if(dpl / 9 == 1){
      dpl = dpl - 9;
      oled.drawXBMP(52,51,8,13,lb_num2);
      oled.drawXBMP(60,51,8,13,lb_slash);
      oled.drawXBMP(68,51,8,13,lb_num4);
      
      oled.drawXBMP(8,0,32,16,Harbin);
      oled.drawXBMP(8,17,32,16,Changchun);
      oled.drawXBMP(8,34,32,16,Shenyang);

      oled.drawXBMP(48,0,32,16,Urumchi);
      oled.drawXBMP(48,17,32,16,Hohhot);
      oled.drawXBMP(48,34,32,16,Yinchuan);
      
      oled.drawXBMP(88,0,32,16,Shijiazhuang);
      oled.drawXBMP(88,17,32,16,Taiyuan);
      oled.drawXBMP(88,34,32,16,Xining);

      short int cx = dpl / 3;
      short int cy = dpl % 3;
      oled.drawXBMP(cx*40, cy*17,8,16,lb_dot);
    }
    else if(dpl / 9 == 2){
      dpl = dpl - 18;
      oled.drawXBMP(52,51,8,13,lb_num3);
      oled.drawXBMP(60,51,8,13,lb_slash);
      oled.drawXBMP(68,51,8,13,lb_num4);
      
      oled.drawXBMP(8,0,32,16,Jinan);
      oled.drawXBMP(8,17,32,16,Lanzhou);
      oled.drawXBMP(8,34,32,16,Zhengzhou);

      oled.drawXBMP(48,0,32,16,Xian);
      oled.drawXBMP(48,17,32,16,Nanjing);
      oled.drawXBMP(48,34,32,16,Hefei);
      
      oled.drawXBMP(88,0,32,16,Hangzhou);
      oled.drawXBMP(88,17,32,16,Wuhan);
      oled.drawXBMP(88,34,32,16,Chengdu);

      short int cx = dpl / 3;
      short int cy = dpl % 3;
      oled.drawXBMP(cx*40, cy*17,8,16,lb_dot);
    }
    else if(dpl / 9 == 3){
      dpl = dpl - 27;
      oled.drawXBMP(52,51,8,13,lb_num4);
      oled.drawXBMP(60,51,8,13,lb_slash);
      oled.drawXBMP(68,51,8,13,lb_num4);
      
      oled.drawXBMP(8,0,32,16,Lhasa);
      oled.drawXBMP(8,17,32,16,Nanchang);
      oled.drawXBMP(8,34,32,16,Changsha);

      oled.drawXBMP(48,0,32,16,Guiyang);
      oled.drawXBMP(48,17,32,16,Fuzhou);
      oled.drawXBMP(48,34,32,16,Kunming);
      
      oled.drawXBMP(88,0,32,16,Nanning);
      oled.drawXBMP(88,17,32,16,Haikou);
      oled.drawXBMP(88,34,32,16,Foshan);

      short int cx = dpl / 3;
      short int cy = dpl % 3;
      oled.drawXBMP(cx*40, cy*17,8,16,lb_dot);
    }
    delay(2);
  }
   return ; 
}

void city_set_store(){        //设置城市编码写入sd卡,按#数字@的格式
  ESP.wdtFeed();
  digitalWrite(10,HIGH);
  digitalWrite(4,LOW);
  delay(5);

    myFile = SD.open("INITIAL_DATA.txt", sdfat::O_READ | sdfat::O_WRITE | sdfat::O_CREAT);
    delay(10);
    if(myFile){
      Serial.println("Write data..");
      myFile.println("#" + String(City_Code) + "@");
      delay(4);
      myFile.close();
      Serial.println("store success");
      digitalWrite(10,LOW);
      digitalWrite(4,HIGH);
    }
    else
    {
      Serial.println("file op fail");
      digitalWrite(10,LOW);
      digitalWrite(4,HIGH);
    } 
    delay(3); 
}



void weather_Report(){

  ESP.wdtFeed();
  oled.firstPage();
  do{
    oled.drawXBMP(32,24,32,16,lb_request);
    oled.drawXBMP(64,24,32,16,lb_ing);
  }while(oled.nextPage());
  delay(1000);

  
  if(WiFi.status() != WL_CONNECTED){        //无网络异常
    request_fail();
    return ;   
  }
  
  short int times = 0;
  while (!client.connected()){        //建立tcp连接
    ESP.wdtFeed();
    if (!client.connect(host, 80)){
        Serial.print(".");
        delay(500);
        ++times;
     }
     if(times == 15){
      request_fail();
      return;
     }
  }
  
  if (SendRequest() && skipResponseHeaders()) {   //发送请求,跳过响应头部
    memset(response, 0, sizeof(response));
    readReponseContent(response);
    WeatherData weatherData;
    if (AnalyseData(response, &weatherData)) {    //解析数据,存到结构中
      exchange(&weatherData);       //将结构中的字符数据转换为整形数据
      printData(&weatherData);
      weather_Readpic();            //从sd卡中读储存天气图像文字的数组
      weather_report_draw();
      while(analogRead(A0) <= null_bt + 30){ESP.wdtFeed();}
      return ;
    }
    else{
      request_fail();   //解析数据异常
      return ;
    }
  }
  else{
    request_fail();   //无响应或响应内容非法异常
    return ;
  } 
}


bool SendRequest(){       //发送url请求
  
  String Url = "/v3/weather/now.json?key=";
  Url += key;
  Url += "&location=";
  Url += City_ID;
  Url += "&language=";
  Url += language;
  client.print(String("GET ") + Url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  Serial.println("create a request:");
  Serial.println(String("GET ") + Url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n");
  delay(1000);
  return true;
}

bool skipResponseHeaders() {      //跳过响应头部
  
  bool is_found = client.find(endOfHeaders);
  if (!is_found) {
    Serial.println("No response or invalid response!");
  }
  return is_found;
}

void readReponseContent(char* content) {                    //保存响应json数据到content数组中
  int len = client.readBytes(content, MAX_CONTENT_SIZE);
  delay(100);
  Serial.println("Get the data from Internet!");
  content[len] = 0;
  Serial.println(content);
  Serial.println("Read data Over!");
  client.flush();
}

bool AnalyseData(char* content, struct WeatherData* weatherData) {      //解析json数据保存到结构中

  DynamicJsonBuffer jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(content);
   
  if (!root.success()) {
    Serial.println("JSON parsing failed!");
    return false;
  }
    
  strcpy(weatherData->code, root["results"][0]["now"]["code"]);
  strcpy(weatherData->temperature, root["results"][0]["now"]["temperature"]);
  return true;
}
   
void exchange(const struct WeatherData* weatherData){           //结构中数据整形转换
  short int t1 = 0;
  short int t2 = 0;
  for(short int i = 0; i < 8; ++i){
    if(weatherData->code[i] >= 48 && weatherData->code[i] <= 57)
      t1 = t1 * 10 + (weatherData->code[i] - 48);
    if(weatherData->temperature[i] >= 48 && weatherData->temperature[i] <= 57)
      t2 = t2 * 10 + (weatherData->temperature[i] - 48);
  }
  if((t1 >= 0 && t1 <= 38) || (t1 == 99))
    weather_Code = t1;
  if(t2 > 0 && t2 < 60)
    temper = t2;
}

void printData(const struct WeatherData* weatherData) {
  Serial.println("Print parsed data :");
  Serial.print("Code : ");
  Serial.print(weatherData->code);
  Serial.print(", \t");
  Serial.print("Temp : ");
  Serial.print(weatherData->temperature);
  Serial.print(" C");
  Serial.println("\r\n");
  Serial.println(weather_Code);
  Serial.println(temper);
}

void weather_Readpic(){           //sd卡文本中读取天气图像字样数组
  digitalWrite(10,HIGH);
  digitalWrite(4,LOW);
  delay(10);

  String tmp = (String)weather_Code + ".txt";       //读取图像
  myFile = SD.open(tmp.c_str(), FILE_READ);
  delay(10);
  if(myFile){
    unsigned short int s = 0;
    unsigned char tmp = 0;
    Serial.println("read pb");
    while(myFile.available()){
      unsigned char ch = myFile.read();
      if(ch >= 48 && ch <= 57)
        tmp = tmp * 16 + (ch - 48);
      else if(ch >= 65 && ch <= 70)
        tmp = tmp * 16 + (ch - 55);
      else if(ch == ','){
         weather_pb[s] = tmp; 
         tmp = 0;
         ++s;
      }
    }
    weather_pb[s] = tmp;
    myFile.close();
    delay(4);
  }
  
  tmp = (String)weather_Code + "c.txt";           //读取文字
  myFile = SD.open(tmp.c_str(), FILE_READ);
  delay(10);
  if(myFile){
    unsigned short int s = 0;
    unsigned char tmp = 0;
    Serial.println("read lb");
    while(myFile.available()){
      unsigned char ch = myFile.read();
      if(ch >= 48 && ch <= 57)
        tmp = tmp * 16 + (ch - 48);
      else if(ch >= 65 && ch <= 70)
        tmp = tmp * 16 + (ch - 55);
      else if(ch == ','){
         weather_lb[s] = tmp; 
         tmp = 0;
         ++s;
      }
    }
    weather_lb[s] = tmp;
    myFile.close();
    delay(4);
  }

  digitalWrite(4,HIGH);
  digitalWrite(10,LOW);
  delay(10);
  return ;
}

void weather_report_draw(){           //绘制天气图像文字,图像都为64X64px,文字都为32X16px
  
    String tmp = (String)temper;
    tmp += "c"; 
    oled.firstPage();
    do{
    oled.drawXBM(0,0,64,64,weather_pb);
    oled.drawXBM(64,39,32,16,weather_lb);
    oled.setFont(u8g2_font_osr29_tf);
    oled.drawStr(63,30,tmp.c_str());
    oled.drawCircle(111,5,2);
    draw_city_character(96, 39, City_Code);
    }while(oled.nextPage());
    delay(4);
} 

void request_fail(){
  Serial.println("request fail");
  client.flush();
  client.stop();
  oled.firstPage();
  do{
    oled.drawXBMP(32,24,32,16,lb_request);
    oled.drawXBMP(64,24,32,16,lb_failure);
  }while(oled.nextPage());
  delay(1500);
}

void draw_city_character(short int x, short int y, short int num){      //城市文字绘制,城市文字都为32X16px
    if(num == 0)
      oled.drawXBMP(x,y,32,16,Beijing);
    else if(num == 1)
      oled.drawXBMP(x,y,32,16,Shanghai);
    else if(num == 2)
      oled.drawXBMP(x,y,32,16,Guangzhou);
    else if(num == 3)
      oled.drawXBMP(x,y,32,16,Shenzhen);
    else if(num == 4)
      oled.drawXBMP(x,y,32,16,Hongkong);
    else if(num == 5)
      oled.drawXBMP(x,y,32,16,Macao);
    else if(num == 6)
      oled.drawXBMP(x,y,32,16,Taipei);
    else if(num == 7)
      oled.drawXBMP(x,y,32,16,Tianjin);
    else if(num == 8)
      oled.drawXBMP(x,y,32,16,Chongqing);
    else if(num == 9)
      oled.drawXBMP(x,y,32,16,Harbin);
    else if(num == 10)
      oled.drawXBMP(x,y,32,16,Changchun);
    else if(num == 11)
      oled.drawXBMP(x,y,32,16,Shenyang);
    else if(num == 12)
      oled.drawXBMP(x,y,32,16,Urumchi);
    else if(num == 13)
      oled.drawXBMP(x,y,32,16,Hohhot);
    else if(num == 14)
      oled.drawXBMP(x,y,32,16,Yinchuan);
    else if(num == 15)
      oled.drawXBMP(x,y,32,16,Shijiazhuang);
    else if(num == 16)
      oled.drawXBMP(x,y,32,16,Taiyuan);
    else if(num == 17)
      oled.drawXBMP(x,y,32,16,Xining);
    else if(num == 18)
      oled.drawXBMP(x,y,32,16,Jinan);
    else if(num == 19)
      oled.drawXBMP(x,y,32,16,Lanzhou);
    else if(num == 20)
      oled.drawXBMP(x,y,32,16,Zhengzhou);
    else if(num == 21)
      oled.drawXBMP(x,y,32,16,Xian);
    else if(num == 22)
      oled.drawXBMP(x,y,32,16,Nanjing);
    else if(num == 23)
      oled.drawXBMP(x,y,32,16,Hefei);
    else if(num == 24)
      oled.drawXBMP(x,y,32,16,Hangzhou);
    else if(num == 25)
      oled.drawXBMP(x,y,32,16,Wuhan);
    else if(num == 26)
      oled.drawXBMP(x,y,32,16,Chengdu);
    else if(num == 27)
      oled.drawXBMP(x,y,32,16,Lhasa);
    else if(num == 28)
      oled.drawXBMP(x,y,32,16,Nanchang);
    else if(num == 29)
      oled.drawXBMP(x,y,32,16,Changsha);
    else if(num == 30)
      oled.drawXBMP(x,y,32,16,Guiyang);
    else if(num == 31)
      oled.drawXBMP(x,y,32,16,Fuzhou);
    else if(num == 32)
      oled.drawXBMP(x,y,32,16,Kunming);
    else if(num == 33)
      oled.drawXBMP(x,y,32,16,Nanning);
    else if(num == 34)
      oled.drawXBMP(x,y,32,16,Haikou);
    else if(num == 35)
      oled.drawXBMP(x,y,32,16,Foshan);
}

你可能感兴趣的:(单片机,arduino,Esp8266,天气预报)