|
楼主 |
发表于 2022-5-28 12:14:40
|
显示全部楼层
=============
获取天气并且显示7789LCD代码,
,
- /*
- code color
- 0x0000 Black
- 0xFFFF White
- 0xBDF7 Light Gray
- 0x7BEF Dark Gray
- 0xF800 Red
- 0xFFE0 Yellow
- 0xFBE0 Orange
- 0x79E0 Brown
- 0x7E0 Green
- 0x7FF Cyan
- 0x1F Blue
- 0xF81F Pink
- A1E6= ℃ //2103
- A1E7=钱,
- //====================
- A3A1=! 33 ++
- A3A2="
- A3B0=0 48 ++
- */
- #include <ArduinoJson.h>
-
- //#include <ArduinoJson.h> //使用ArduinoJson库
- #include <ESP8266WiFi.h>
- #include <TimeLib.h>
- #include <WiFiUdp.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- WiFiClient client;
- ESP8266WebServer webServer(80);
- #include <ESP8266WiFiMulti.h>
- #include <ESP8266HTTPClient.h>
- //#include "cp936.h"
- #include "UTF-8toGB2312.h"
- #include "Solar2Luner.h"
- Solar2Luner S2L;
- typedef unsigned char uchar;
- typedef unsigned int uint;
- //========直接替换WIFI网络,密码
- #define WIFI_SSID "4FFF"
- #define WIFI_PASSWORD "666688888"
- #include <FS.h>
- FSInfo fs_info;
- File f;
- #include <TFT_eSPI.h> // Hardware-specific library
- #include <SPI.h>
- #define TFT_GREY 0x5AEB
- TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
- uint32_t targetTime = 0; // for next 1 second timeout
- static uint8_t conv2d(const char* p); // Forward declaration needed for IDE 1.6.x
- uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time
- byte omm = 99, oss = 99;
- byte xcolon = 0, xsecs = 0;
- unsigned int colour = 0;
- int KKI;
- bool tq_fff ;//
- /***
- diqu = result_result_city ;//温州
- dangtian_ch = result_result_weather ;// 晴转多云
- dangqian_tq = result_result_temp ;/22
- dang_tian_l = result_result_templow ;//18
- dang_tian_h = result_result_temphigh ;//23
- **/
- String diqu = "";
-
- String dangtian_ch = "";
- String dangqian_tq = "";
- String dang_tian_l = "";
- String dang_tian_h = "";
-
- String ttqq_all="";
- String duan_tq_all="";
-
- int xit_wk;
- int xit_nn,xit_yy,xit_rr,xit_hh,xit_mm,xit_ss;
-
- int bk_ss ;
- int xit_up_ss;
- int urat_up_ss;
- //---------------------------
-
- //星期
- String week(int xqik )
- {
- //1-7,7=星期天 "" 1 2 3 4 5 6 7
- String wk[8] = {"日","一","二","三","四","五","六","天"};
- String s = "星期" + wk[ xqik ];//wk==4
- return s;
- }
- String wk_ch="";
- void get_new_time(void )
- {
- int xq = weekday();//5==星期4
- xq=xq-1; //0=天 ,123456
- //0=星期天
- if(xq==0)
- xq=7;
- //=== 1=星期1 --- 7=星期日
- xit_wk = xq ;//1-7
- wk_ch="";
- wk_ch = week( xit_wk );
- xit_nn = year() ;
- xit_yy =month() ;
- xit_rr = day();
- xit_hh =hour() ;
- xit_mm =minute() ;
- xit_ss =second();
-
- }
-
- //=============================================================
- //---------------------------ntp
-
-
- time_t prevDisplay = 0; // 显示时间
- unsigned long weaterTime = 0;
- //=========
- //NTP服务器
- static const char ntpServerName[] = "ntp6.aliyun.com";
- int timeZone = 8; //东八区 ===修改时区
- WiFiUDP Udp;
- unsigned int localPort = 8000;
- time_t getNtpTime();
- void digitalClockDisplay();
- void printDigits(int digits);
- String num2str(int digits);
- void sendNTPpacket(IPAddress &address);
-
- //=============================================================
- //=============================================================
- void drawchar(u16 chr,int x,int y){
- if(chr>=0xa1a0){
- u8 high,low;u8 buf[32];
- high=chr>>8;
- low=chr&0xff;
- f.seek(32*((high-0xa0-1)*94+(low-0xa0-1)),SeekSet);
- f.read(buf,32);
- for(int i=0;i<16;i++)
- {
- u8 readr=buf[i*2];
- for(int j=0;j<8;j++) {if(readr&(0x80>>j)) tft.drawPixel(x+j,y+i,TFT_MAGENTA );}
- readr=buf[i*2+1];
- for(int j=0;j<8;j++) if(readr&(0x80>>j)) tft.drawPixel(x+j+8,y+i,TFT_MAGENTA );
- }
-
- }
- }
- bool printchs(String str,int x,int y)
- {
-
- int num=str.length();
- int n=num/3+10;
- u16 s[n+1];
- bool pd=false;
-
- Utf8ToGb2312(str.c_str(),num,s);
-
- int j=0;
- for(int i=0;i<n;i++)
- {
- if(s[i]==0xffff) break;
- if(x+i*16+16<241)
- drawchar(s[i],x+i*16,y);
- else
- {
- drawchar(s[i],j*16,y+16);j++;
-
- pd=true;
-
- }
-
- }
-
- return pd;
-
- }
- //=============================================
- //=============================================================
- char ch_dat_all [ 4000];
- void drawchar22(u16 chr,int x,int y , u16 bjk ) // bjk TFT_MAGENTA
- {
-
- if(chr>=0xa1a0)
- {
- u8 high,low;u8 buf[32];
- high=chr>>8;
- low=chr&0xff;
- f.seek(32*((high-0xa0-1)*94+(low-0xa0-1)),SeekSet);
- f.read(buf,32);
- for(int i=0;i<16;i++)
- {
- u8 readr=buf[i*2];
- for(int j=0;j<8;j++) {if(readr&(0x80>>j)) tft.drawPixel(x+j,y+i,bjk );}
- readr=buf[i*2+1];
- for(int j=0;j<8;j++) if(readr&(0x80>>j)) tft.drawPixel(x+j+8,y+i,bjk );
- }
-
- }
- }
- //----------------------------
- // drawchar_zf22( str_alll[ki] ,x,y+yid ); // 写点阵
- // tft.drawString("open-lcd", 0, 0 ,4);
- void drawchar_zf22(u16 chr,int x,int y , u16 bjk)
- {
- // bjk
-
- // tft.setTextColor( bjk , TFT_BLACK );
- tft.setTextColor( bjk );
- // tft.drawString( chr, x, y ,4);
- tft.drawChar( chr, x, y , 2 );
-
- }
- void drawchar_zf223(u16 chr,int x,int y, u16 bjk)
- {
-
- //if(chr>=0xa1a0)
- if(chr>=33)// A3A1 A3A2
- {
- u8 high,low;u8 buf[32];
- u8 dum;
- dum=chr-33;
- high=0xa3;
- low=0xa1 + dum ;
- //A3A1 ++
- // f.seek(16*((high-0xa0-1)*94+(low-0xa0-1)),SeekSet);
- f.seek(16* ((high-0xa0-1)*94+(low-0xa0-1) ) ,SeekSet);
- f.read(buf,16);
- for(int i=0;i<16;i++)
- {
- u8 readr=buf[i];
- for(int j=0;j<8;j++)
- {
- if(readr&(0x80>>j))
- tft.drawPixel(x+j,y+i, bjk );
-
- }
-
- // readr=buf[i*2+1];
- // for(int j=0;j<8;j++) if(readr&(0x80>>j)) tft.drawPixel(x+j+8,y+i,TFT_MAGENTA );
- }
-
- }
-
- }
- //----------------------------
- bool cc_gb2312( String strutf8 , int comch ,int x ,int y , u16 bjk ) // //=0串口=1数据 3=写LCD
- {
- int str_len = strutf8.length() + 1;
- char str_alll[ str_len ];
-
- strutf8.toCharArray( str_alll , str_len);
- //循环解析
- int ki=0;
- int kpp;
- int endd_len=0;
- int upget_id =0;
- u16 unicodeKey = 0;
- u16 gbKey = 0;
- int yid=0;
- int xid=0;
-
- while (ki < str_len )
- {
-
-
-
- kpp = GetUtf8ByteNumForWord( str_alll[ki] );
-
-
- if( kpp==0 )
- {
- if(comch==1)//数据
- {
-
- ch_dat_all [ upget_id ] = str_alll[ki] ;
- }
- else if(comch==0)//串口
- {
-
-
- Serial.write( str_alll[ki] );
- }
- else if(comch==3)// 写LCD
- {
- // gbKey u16 gb2312
- // drawchar22(u16 chr,int x,int y); // 写点阵
- drawchar_zf22( str_alll[ki] ,x+xid,y+yid , bjk ); // 写点阵
- // yid=yid+17;
- xid=xid+9;
- if(xid>239-5)
- {
- xid=0;
- yid=yid+17;
-
- }
-
- }
-
-
- upget_id ++;
- ki++;
- }
- else
- {
- if( kpp==3 )
- {
-
- unicodeKey = (( str_alll[ki] & 0x0F) << 4) | (( str_alll[ki+1] >> 2) & 0x0F);
- unicodeKey =unicodeKey<<8;
- unicodeKey |= ((str_alll[ki + 1] & 0x03) << 6) + (str_alll[ki + 2] & 0x3F);
-
-
- //根据这个值查表取得对应的GB2312的值
- gbKey = SearchCodeTable(unicodeKey);
-
- if(comch==1)//数据
- {
- ch_dat_all [ upget_id ] = gbKey>>8 ;
- ch_dat_all [ upget_id +1 ] = gbKey&0xff ;
-
- }
-
- else if(comch==0)//串口
- {
- Serial.write( gbKey>>8 );
- Serial.write( gbKey&0xff );
- }
- else if(comch==3)// 写LCD
- {
- // gbKey u16 gb2312
- // drawchar22(u16 chr,int x,int y); // 写点阵
- drawchar22(gbKey ,x+xid,y+yid , bjk ); // 写点阵
- // yid=yid+33;
- xid=xid+17;
- if(xid>239-5)
- {
- xid=0;
- yid=yid+17;
-
- }
-
- }
- //=========================================
-
- upget_id +=2;
-
-
- ki+= 3 ; // 3
-
- }
- else
- {
- // ki++;
-
- }
-
-
- }
-
-
- }
- if(comch==1)//数据
- {
- //ch_dat_all [ upget_id ]=0;
- //ch_dat_all [ upget_id +1 ]=0;
- }
- else if(comch==0)//串口
- {
- //ch_dat_all [0 ]=0;
- //ch_dat_all [ 1 ]=0;
-
- }
-
- return 1;
- }
- //========================================
- void setup(void)
- {
- delay(80);
- Serial.begin(115200);
- delay(80);
- Serial.println("");
- Serial.println("=======8266================");
- Serial.println("=======8266================");
- Serial.println("");
- SPIFFS.begin(); //启动SPIFFS
- Serial.println("");
- Serial.println("SPIFFS Started.");
-
- // 闪存文件系统信息
- SPIFFS.info(fs_info);
-
- // 可用空间总和(单位:字节)
- Serial.print("totalBytes: ");
- Serial.print(fs_info.totalBytes);
- Serial.println(" Bytes");
-
- // 已用空间(单位:字节)
- Serial.print("usedBytes: ");
- Serial.print(fs_info.usedBytes);
- Serial.println(" Bytes");
-
- // 最大文件名字符限制(含路径和'\0')
- Serial.print("maxPathLength: ");
- Serial.println(fs_info.maxPathLength);
-
- // 最多允许打开文件数量
- Serial.print("maxOpenFiles: ");
- Serial.println(fs_info.maxOpenFiles);
-
- // 存储块大小
- Serial.print("blockSize: ");
- Serial.println(fs_info.blockSize);
-
- // 存储页大小
- Serial.print("pageSize: ");
- Serial.println(fs_info.pageSize);
- Serial.println("=====all=======");
- Dir dir = SPIFFS.openDir("/"); // 開啟“/data”目錄
- while (dir.next())
- { // 只要還有檔案…
- Serial.print(dir.fileName()); // 顯示檔名
- File f = dir.openFile("r"); // 以「唯讀」模式開啟檔案
- Serial.println(f.size()); // 顯示檔案大小
- }
- Serial.println("=====allned=======");
- delay(100);
-
- f = SPIFFS.open("/hzk16.bin", "r");
- delay(100);
- if (!f) {
- Serial.println("file open ==11111=not 文件打开失败");
- Serial.println("======11111111111======");
- f = SPIFFS.open("/hzk16.bin", "r");
- delay(100);
- if (!f) {
- Serial.println("file open =222222==not 文件打开失败");
- Serial.println("======22222222222======");
-
- }
- else
- {
- Serial.println("file open ===OKkkkkk ");
- Serial.println("=====222222222222=======");
-
- }
- }
- else
- {
- Serial.println("file open ===OKkkkkk ");
-
- }
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- tft.init();
- tft.setRotation(1);
- tft.fillScreen(TFT_BLACK);
- tft.setTextSize(1);
- tft.setTextColor(TFT_YELLOW, TFT_BLACK);
- targetTime = millis() + 1000;
- tft.setTextColor(TFT_GREEN );
- tft.drawString("open-lcd", 0, 0 ,4);
- delay(2000);
- tft.fillScreen( TFT_BLACK );//清屏 ,背景全黑
- tft.setCursor(10, 40); //显示位置
-
- tft.setTextSize( 1 );//字号
-
- tft.setTextColor( TFT_YELLOW ); //文字颜色
- tft.println("===========================");
- tft.println("==SPIFFS.open /HZK16.bin==");
- tft.println("===========================");
-
- delay(2000);
- tft.fillScreen( TFT_BLACK );//清屏 ,背景全黑
-
- String bx="我是ESP8266中文屏幕";
- printchs(bx,5,30);
-
-
- while (WiFi.status() != WL_CONNECTED)
- {
- Serial.println("==正在链接网络==");
- delay(500);
- }
- Serial.println("");
- Serial.print("链接成功 IP地址=: ");
- Serial.println(WiFi.localIP());
- Serial.println("");
- delay(200);
- tft.setTextWrap( 1 ); //打开(关闭)屏幕宽度(高度)中的文本换行
- //textwrap.fill(text, width=70, **kwargs)
- tft.setCursor(0 , 0);
- tft.setTextSize(1);
- tft.fillScreen( TFT_BLACK );//清屏 ,背景全黑
-
- tft.setTextColor( TFT_RED );
- tft.print( "===open===" );
-
- delay(45);
- //----------------------------
- //----------ntp-------
- timeZone = 8; //东八区
- //Serial.println("启动UDP");
- Udp.begin(localPort);
- //Serial.print("端口号: ");
- //Serial.println(Udp.localPort());
- //Serial.println("等待同步...");
- // setSyncProvider(getNtpTime);
- // setSyncInterval(300);
- setSyncProvider( getNtpTime );//设置同步提供程序
- // setSyncInterval(300); //设置同步间隔
- //----------------------------
- tq_fff=1;
-
- }
- void loop()
- {
-
-
- webServer.handleClient();
-
- // put your main code here, to run repeatedly:
- get_new_time();
- //更新...
- // xit_wk;
- // xit_nn,xit_yy,xit_rr,xit_hh,xit_mm,xit_ss;
- // String wk_ch="";//中文星期 UTF8
- //--------------------
- jd_tianqi() ; // tq_fff
-
- // ttqq_all
- tft.fillScreen(TFT_BLACK);
- // void setTextWrap(bool wrapX, bool wrapY = false); //打开(关闭)屏幕宽度(高度)中的文本换行
- // tft.setTextWrap( 1 ); //打开(关闭)屏幕宽度(高度)中的文本换行
- //textwrap.fill(text, width=70, **kwargs)
- tft.setCursor(0 , 0);
- tft.setTextSize(1);
-
- tft.setTextColor( TFT_RED );
- // tft.print( "TFT_REdfgwerty4567yuy5fgh====ghhnfgbhtre4ry57y654jhbgfrbhhdr===222D" );
-
- // tft.print( ch_dat_all );
- cc_gb2312( ttqq_all , 3, 0 , 0 , TFT_MAGENTA ); // //=0串口=1数据 3=写LCD
- //
-
- delay(45);
- //===================
- /*******
- String bx="我是ESP, 68:2;34=中文屏幕";
- // printchs(bx, 5 , KKI );
- // cc_gb2312( String strutf8 , int comch ,int x ,int y ); // //=0串口=1数据 3=写LCD
- cc_gb2312( bx , 3, 1 , KKI , TFT_MAGENTA ); // //=0串口=1数据 3=写LCD
-
- KKI += 33 ;
- if( KKI >240)
- {
- KKI=0;
- tft.fillScreen( TFT_BLACK );//清屏 ,背景全黑
-
- tft.setCursor(0, 0);
-
- }
- **********/
- delay(1000);
-
- delay(1000);
- delay(1000);
- }
- // Function to extract numbers from compile time string
- static uint8_t conv2d(const char* p) {
- uint8_t v = 0;
- if ('0' <= *p && *p <= '9')
- v = *p - '0';
- return 10 * v + *++p - '0';
- }
- //=============================================================
- /*-------- NTP code ----------*/
- const int NTP_PACKET_SIZE = 48; // NTP时间在消息的前48字节中
- byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets
- time_t getNtpTime()
- {
-
- IPAddress ntpServerIP; // NTP server's ip address
- while (Udp.parsePacket() > 0) ; // discard any previously received packets
- //Serial.println("Transmit NTP Request");
- // get a random server from the pool
- WiFi.hostByName(ntpServerName, ntpServerIP);
- //Serial.print(ntpServerName);
- //Serial.print(": ");
- //Serial.println(ntpServerIP);
- sendNTPpacket(ntpServerIP);
- uint32_t beginWait = millis();
- while (millis() - beginWait < 1500)
- {
-
- int size = Udp.parsePacket();
-
- if (size >= NTP_PACKET_SIZE)
- {
-
- // Serial.println("Receive NTP Response"); // 接收NTP响应
- Serial.println("Receive NTP Response"); // 接收NTP响应
- Serial.println("接收NTP响应"); // 接收NTP响应
- Serial.println("==更新NTP网络时间=OK==="); // 接收NTP响应
-
- Udp.read(packetBuffer, NTP_PACKET_SIZE); // read packet into the buffer
- unsigned long secsSince1900;
- // convert four bytes starting at location 40 to a long integer
- secsSince1900 = (unsigned long)packetBuffer[40] << 24;
- secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
- secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
- secsSince1900 |= (unsigned long)packetBuffer[43];
- //Serial.println(secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR);
- return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
- }
- }
- // Serial.println("No NTP Response :-(");
- Serial.println("=====No NTP ====没有NTP时间数据=====");
- return 0; // 无法获取时间时返回0
- }
- // 向NTP服务器发送请求
- void sendNTPpacket(IPAddress &address)
- {
- // set all bytes in the buffer to 0
- memset(packetBuffer, 0, NTP_PACKET_SIZE);
- // Initialize values needed to form NTP request
- // (see URL above for details on the packets)
- packetBuffer[0] = 0b11100011; // LI, Version, Mode
- packetBuffer[1] = 0; // Stratum, or type of clock
- packetBuffer[2] = 6; // Polling Interval
- packetBuffer[3] = 0xEC; // Peer Clock Precision
- // 8 bytes of zero for Root Delay & Root Dispersion
- packetBuffer[12] = 49;
- packetBuffer[13] = 0x4E;
- packetBuffer[14] = 49;
- packetBuffer[15] = 52;
- // all NTP fields have been given values, now
- // you can send a packet requesting a timestamp:
- Udp.beginPacket(address, 123); //NTP requests are to port 123
- Udp.write(packetBuffer, NTP_PACKET_SIZE);
- Udp.endPacket();
- }
- //=============================================================
-
- // bool tq_fff ;//
- void jd_tianqi(void) // tq_fff
- {
- if(tq_fff)
- {
- // API server
- const char* host22 = "way.jd.com";
-
-
- // Connect to API
- Serial.print("连接网站: ");
- Serial.println(host22);
- Serial.println("");
-
- // Use WiFiClient class to create TCP connections
- WiFiClient client;
-
- const int httpPort = 80;
-
- if (!client.connect(host22, httpPort))
- {
- Serial.println("网站连接没有数据 not http datta ");
- Serial.println("");
- return;
- }
-
- // We now create a URI for the request
- String url = "/jisuapi/weather?city=温州&cityid=111&citycode=101260301&appkey=389直接注册京东的APK替换此处";
-
-
- Serial.println("连接 URL : ");
- Serial.println(url);
- Serial.println("");
-
- // This will send the request to the server
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
- "Host: " + host22 + "\r\n" +
- "Connection: close\r\n\r\n");
- delay(600);
-
- //定义answer变量用来存放请求网络服务器后返回的数据
- String answer;
-
- while(client.available())
- {
- String line = client.readStringUntil('\r');
- answer += line;
- }
-
- //断开服务器连接
- client.stop();
- Serial.println();
- Serial.println("closing 断开服务器连接 connection");
- //====================
-
- //获得json格式的数据
- String jsonAnswer;
- int jsonIndex;
-
- //找到有用的返回数据位置i 返回头不要
- for (int i = 0; i < answer.length(); i++)
- {
- if (answer[i] == '{')
- {
- jsonIndex = i;
- break;
- }
- }
-
- jsonAnswer = answer.substring(jsonIndex);
-
- Serial.println();
- Serial.println("");
- Serial.println("");
- Serial.println("======URL 网站 返回的全部数据--经过 json 处理 删除没用的 ====");
- Serial.println("");
-
- // Serial.println( jsonAnswer);
- Serial.println("");
- Serial.println("");
- Serial.println("================= ");
- // str=str.substring(int startIndex,int endIndex);截取str中从startIndex开始至endIndex结束时的字符串,并将其赋值给str;
- ttqq_all="";
- ttqq_all += jsonAnswer.substring(373,1500 );
- // ttqq_all
-
- Serial.println("");
- Serial.println("");
- Serial.println("===73-1500数据=:");
- Serial.println( ttqq_all );
- Serial.println("");
- Serial.println("");
- // ttqq_all +=jsonAnswer;
- //y":"温州",
- //"cityid":390,"citycode":101210701,"date":"2022-05-26",
- //"week":"星期四","weather":"小到中雨","temp":"19","temphigh":"22","templow":"16",
- //"img":"21","humidity":"99","pressure":"1005","windspeed":"1.7","winddirect":
- //"西南风","windpower":"2级","updatetime":"2022-05-26 13:38:00","index":
- //[{"iname":"空调指数","ivalue":"较少开启","detail":"您将感到
- //500
- //很舒适,一般不需要开启空调。"},
- //{"iname":"运动指数","ivalue":"较不宜","detail":"有降水,且风力较强,较适宜在户内进行各种健身休闲运动
- //;若坚持户外运动,请注意保暖。"},{"iname":"紫外线指数","ivalue":"最弱","detail":"属弱紫外线辐射天气,
- //无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。"},{"iname":"感冒指数","ivalue":
- //"易发","detail":"相对于今天将会出现大幅度降温,易发生感冒,请注意适当增加衣服,加强自我防护避免感冒。
- //"},{"iname":"洗车指数","ivalue":"不宜","detail":"不宜洗车,未来24小时内有雨,如果在此期间洗车,
- //雨水和路上的泥水可能会再次弄脏您的爱车。"},{"iname":"空气污染扩散指数","ivalue":"良","detail":"气
- //象条件有利于空气污染物稀释、扩散和清除,可在室外正常活动。"},{"iname":"穿衣指数","ivalue":"较舒适"
- //,"detail":"建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。"}],"aq
- //i":{"so2":"6","so224":"0","no2":"34","no224":"0","co":"0.520","co24":"0.000","o3":"64","o
- //38":"0","o324":"0","pm10":"38","pm1024":"0","pm2_5":"22","pm2_524":"0","iso2":"2","ino2":
- //"17","ico":"6","io3":"21","io38":"0","ipm10":"38","ipm2_5":"32","aqi":"38","primarypolluta
- //nt":"PM10","quality":"优","timepoint":"2022-05-26 13:00:00","aqiinfo":{"level":"一级","color
- //":"#00e400","affect":"空气质量令人满意,基本无空气污染","measure":"各类人群可正常活动"}},"daily":[
- //{"date":"2022-05-26","week":"星期四","sunrise":"05:03","sunset":"18:46","night":{"weather":"
- //阴","templow":"16","img":"2","winddirect":"持续无风向","windpower":"微风"},"day":{"weather":"
- //小到中雨","temphigh":"22","img":"21","winddirect":"持续无风向","windpower":"微风"}},{"date":"20
- //22-05-27","week":"星期五","sunrise":"05:03","sunset":"18:46","night":{"weather":"小到中雨","te
- //mplow":"18","img":"21","winddirect":"持续无风向","windpower":"微风"},"day":{"weather":"阴","te
- //mphigh":"26","img":"2","winddirect":"东南风","windpower":"3-5级"}},{"date":"2022-05-28","week
- //":"星期六","sunrise":"05:03","sunset":"18:47","night":{"weather":"小雨","templow":"19","img":
- //"7","winddirect":"持续无风向","windpower":"微风"},"day":{"weather":"中到大雨","temphigh":"20","
- //img":"22","winddirect":"持续无风向","windpower":"微风"}},{"date":"2022-05-29","week":"星期日","
- //sunrise":"05:02","sunset":"18:47","night":{"weather":"小雨","templow":"20","img":"7","winddir
- //ect":"持续无风向","windpower":"微风"},"day":{"weather":"小雨","temphigh":"28","img":"7","winddi
- //rect":"持续无风向","windpower":"微风"}},{"date":"2022-05-30","week":"星期一","sunrise":"05:02","
- //sunset":"18:48","night":{"weather":"小到中雨","templow":"21","img":"21","winddirect":"持续无风向
- //","windpower":"微风"},"day":{"weather":"小到中雨","temphigh":"28","img":"21","winddirect":"持续无
- //风向","windpower":"微风"}},{"date":"2022-05-31","week":"星期二","sunrise":"05:02","sunset":"18:48","night":{"weather":"小到中雨","templow":"20","img":"21","winddirect":"持续无风向","windpower":"微风"},"day":{"weather":"中到大
- 雨","temphigh":"26","img":"22","winddirect":"持续无风向","windpower":"微风"}},{"date":"2022-06-01","week":"星期三","sunrise":"05:01","sunset":"18:49","night":{"weather":"小雨","templow":"21","img":"7","winddirect":"持续无风
- 向","windpower":"微风"},"day":{"weather":"小到中雨","temphigh":"28","img":"21","winddirect":"东南风","windpower":"3-5级"}}],"hourly":[{"time":"13:00","weather":"小雨","temp":"22","img":"7"},{"time":"14:00","weather":"小
- 雨","temp":"22","img":"7"},{"time":"15:00","weather":"多云","temp":"22","img":"1"},{"time":"16:00","weather":"多云","temp":"21","img":"1"},{"time":"17:00","weather":"小雨","temp":"21","img":"7"},{"time":"18:00","weather":"多
- 云","temp":"20","img":"1"},{"time":"19:00","weather":"多云","temp":"19","img":"1"},{"time":"20:00","weather":"小雨","temp":"19","img":"7"},{"time":"21:00","weather":"阴","temp":"19","img":"2"},
- {"time":"22:00","weather":"阴","temp":"19","img":"2"},{"time":"23:00","weather":"阴","temp":"19","img":"2"},{"time":"0:00","weather":"阴","temp":"18","img":"2"},{"time":"1:00","weather":"阴","temp":"18","img":"2"},
- {"time":"2:00","weather":"阴","temp":"18","img":"2"},{"time":"3:00","weather":"阴","temp":"18","img":"2"},{"time":"4:00","weather":"阴","temp":"17","img":"2"},{"time":"5:00","weather":"阴","temp":"17","img":"2"},
- {"time":"6:00","weather":"阴","temp":"18","img":"2"},{"time":"7:00","weather":"阴","temp":"19","img":"2"},{"time":"8:00","weather":"阴","temp":"19","img":"2"},{"time":"9:00","weather":"阴","temp":"21","img":"2"},
- {"time":"10:00","weather":"阴","temp":"23","img":"2"},{"time":"11:00","weather":"阴","temp":"25","img":"2"},{"time":"12:00","weather":"阴","temp":"26","img":"2"}]}},"requestId":"897f6b3d2596472f8e1bf10609df9927"}',2);
-
-
- //===================================================
-
- DynamicJsonDocument doc(9000);
- deserializeJson(doc,jsonAnswer);
- JsonObject obj = doc.as<JsonObject>();
- /********
- String input = "{"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}";
- deserializeJson(doc, input);
- JsonObject obj = doc.as<JsonObject>();
- // You can use a String to get an element of a JsonObject
- // No duplication is done.
- //反序列化
- long time = obj[String("time")];
- String sensor = obj["sensor"];
- double latitude = doc["data"][0];
- double longitude = doc["data"][1];
- **********/
-
-
- const char* code = doc["code"]; // "10000"
- Serial.println("");
- Serial.println("===code数据=: ");
- Serial.print( code );
- Serial.println("");
- Serial.println("=====end====== ");
- Serial.println("");
-
- bool charge = doc["charge"]; // false
- const char* msg = doc["msg"]; // "查询成功"
- JsonObject result = doc["result"];
- int result_status = result["status"]; // 0
- const char* result_msg = result["msg"]; // "ok"
- String okstrr = result_msg ;
- String okbjj = "ok";
- if( okstrr == okbjj )
- {
- Serial.println("");
- Serial.println(" result['msg']; ok == 成功退出 ============================ ");
- Serial.println("");
- tq_fff=0;
-
- }
- JsonObject result_result = result["result"];
- const char* result_result_city = result_result["city"]; // "温州"
- Serial.println("");
- Serial.println("=== 地区=: ");
- Serial.print( result_result_city );
- Serial.println("");
- Serial.println("=====end====== ");
- Serial.println("");
- diqu = result_result_city ;//温州
-
- int result_result_cityid = result_result["cityid"]; // 390
- const char* result_result_citycode = result_result["citycode"]; // "101210701"
- const char* result_result_date = result_result["date"]; // "2021-04-21"
- const char* result_result_week = result_result["week"]; // "星期三"
- const char* result_result_weather = result_result["weather"]; // "阴"
- const char* result_result_temp = result_result["temp"]; // "22"
- const char* result_result_temphigh = result_result["temphigh"]; // "23"
- const char* result_result_templow = result_result["templow"]; // "15"
- Serial.println("");
- Serial.println("==日期天气数据=: ");
-
- Serial.print( result_result_date );
- Serial.print(",");
- Serial.print( result_result_week );
- Serial.print(",");
- Serial.print( result_result_weather );
- Serial.print(",");
- Serial.print(" 当前");
- Serial.print( result_result_temp );
- Serial.print("度");
- Serial.print(",");
- Serial.print("当天: ");
- Serial.print( result_result_templow );
- Serial.print("~");
- Serial.print(result_result_temphigh);
-
- Serial.println("度");
- Serial.print(",");
- Serial.println("");
-
- Serial.println("");
- Serial.println("=====end====== ");
- Serial.println("");
- Serial.println("");
- dangtian_ch = result_result_weather ;// 晴转多云
- dangqian_tq = result_result_temp ;//22
- dang_tian_l = result_result_templow ;//18
- dang_tian_h = result_result_temphigh ;//23
- String DAOJJK ="";
- DAOJJK = String( result_result_templow) +"~" + String( result_result_temphigh ) ;
-
-
- const char* result_result_img = result_result["img"]; // "2"
- const char* result_result_humidity = result_result["humidity"]; // "65"
- const char* result_result_pressure = result_result["pressure"]; // "1015"
- const char* result_result_windspeed = result_result["windspeed"]; // "2.5"
- const char* result_result_winddirect = result_result["winddirect"]; // "东风"
- const char* result_result_windpower = result_result["windpower"]; // "1级"
- const char* result_result_updatetime = result_result["updatetime"]; // "2021-04-21 10:00:00"
-
-
- for (JsonObject elem : result_result["index"].as<JsonArray>()) {
- const char* iname = elem["iname"]; // "空调指数", "运动指数", "紫外线指数", "感冒指数", "洗车指数", "空气污染扩散指数", "穿衣指数"
- const char* ivalue = elem["ivalue"]; // "较少开启", "较不宜", "最弱", "较易发", "不宜", "良", "较舒适"
- const char* detail = elem["detail"]; // "您将感到很舒适,一般不需要开启空调。", ...
- }
- JsonObject result_result_aqi = result_result["aqi"];
- const char* result_result_aqi_so2 = result_result_aqi["so2"]; // "9"
- const char* result_result_aqi_so224 = result_result_aqi["so224"]; // "7"
- const char* result_result_aqi_no2 = result_result_aqi["no2"]; // "28"
- const char* result_result_aqi_no224 = result_result_aqi["no224"]; // "33"
- const char* result_result_aqi_co = result_result_aqi["co"]; // "0.400"
- const char* result_result_aqi_co24 = result_result_aqi["co24"]; // "0.320"
- const char* result_result_aqi_o3 = result_result_aqi["o3"]; // "73"
- const char* result_result_aqi_o38 = result_result_aqi["o38"]; // "31"
- const char* result_result_aqi_o324 = result_result_aqi["o324"]; // "54"
- const char* result_result_aqi_pm10 = result_result_aqi["pm10"]; // "58"
- const char* result_result_aqi_pm1024 = result_result_aqi["pm1024"]; // "59"
- const char* result_result_aqi_pm2_5 = result_result_aqi["pm2_5"]; // "22"
- const char* result_result_aqi_pm2_524 = result_result_aqi["pm2_524"]; // "24"
- const char* result_result_aqi_iso2 = result_result_aqi["iso2"]; // "4"
- const char* result_result_aqi_ino2 = result_result_aqi["ino2"]; // "14"
- const char* result_result_aqi_ico = result_result_aqi["ico"]; // "4"
- const char* result_result_aqi_io3 = result_result_aqi["io3"]; // "24"
- const char* result_result_aqi_io38 = result_result_aqi["io38"]; // "16"
- const char* result_result_aqi_ipm10 = result_result_aqi["ipm10"]; // "54"
- const char* result_result_aqi_ipm2_5 = result_result_aqi["ipm2_5"]; // "32"
- const char* result_result_aqi_aqi = result_result_aqi["aqi"]; // "54"
- const char* result_result_aqi_primarypollutant = result_result_aqi["primarypollutant"]; // "PM10"
- const char* result_result_aqi_quality = result_result_aqi["quality"]; // "良"
- const char* result_result_aqi_timepoint = result_result_aqi["timepoint"]; // "2021-04-21 09:00:00"
- JsonObject result_result_aqi_aqiinfo = result_result_aqi["aqiinfo"];
- const char* result_result_aqi_aqiinfo_level = result_result_aqi_aqiinfo["level"]; // "二级"
- const char* result_result_aqi_aqiinfo_color = result_result_aqi_aqiinfo["color"]; // "#FFFF00"
- const char* result_result_aqi_aqiinfo_affect = result_result_aqi_aqiinfo["affect"];
- const char* result_result_aqi_aqiinfo_measure = result_result_aqi_aqiinfo["measure"];
- for (JsonObject elem : result_result["daily"].as<JsonArray>()) {
- const char* date = elem["date"]; // "2021-04-21", "2021-04-22", "2021-04-23", "2021-04-24", ...
- const char* week = elem["week"]; // "星期三", "星期四", "星期五", "星期六", "星期日", "星期一", "星期二"
- const char* sunrise = elem["sunrise"]; // "05:28", "05:27", "05:26", "05:25", "05:24", "05:23", "05:22"
- const char* sunset = elem["sunset"]; // "18:26", "18:26", "18:27", "18:27", "18:28", "18:28", "18:29"
- JsonObject night = elem["night"];
- const char* night_weather = night["weather"]; // "多云", "小雨", "小雨", "小雨", "小雨", "小雨", "中雨"
- const char* night_templow = night["templow"]; // "15", "18", "18", "17", "16", "17", "19"
- const char* night_img = night["img"]; // "1", "7", "7", "7", "7", "7", "8"
- const char* night_winddirect = night["winddirect"]; // "持续无风向", "持续无风向", "持续无风向", "持续无风向", "持续无风向", ...
- const char* night_windpower = night["windpower"]; // "微风", "微风", "微风", "微风", "微风", "微风", "微风"
- JsonObject day = elem["day"];
- const char* day_weather = day["weather"]; // "多云", "小雨", "小雨", "小雨", "中雨", "小雨", "小雨"
- const char* day_temphigh = day["temphigh"]; // "23", "23", "27", "23", "19", "19", "24"
- const char* day_img = day["img"]; // "1", "7", "7", "7", "8", "7", "7"
- const char* day_winddirect = day["winddirect"]; // "东南风", "持续无风向", "东风", "东南风", "东风", "东风", "持续无风向"
- const char* day_windpower = day["windpower"]; // "3-5级", "微风", "3-5级", "3-5级", "3-5级", "3-5级", "微风"
- }
- for (JsonObject elem : result_result["hourly"].as<JsonArray>()) {
- const char* time = elem["time"]; // "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", ...
- const char* weather = elem["weather"]; // "阴", "阴", "多云", "多云", "多云", "多云", "多云", "多云", "晴", "晴", "晴", ...
- const char* temp = elem["temp"]; // "22", "23", "23", "23", "23", "22", "22", "21", "20", "19", "18", ...
- const char* img = elem["img"]; // "2", "2", "1", "1", "1", "1", "1", "1", "0", "0", "0", "0", "0", "1", ...
- }
- const char* requestId = doc["requestId"]; // "526a4d0ac41e4eb8a2ef91dd9f262f11"
- // delay(5000);
- }
-
-
- }
复制代码
|
|