数码之家

 找回密码
 立即注册
搜索
查看: 4966|回复: 18

[Arduino] 在ARDUINO中输出GB2312编码中文

[复制链接]
发表于 2022-5-26 12:17:02 | 显示全部楼层 |阅读模式

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 mckk520 于 2022-5-26 12:18 编辑

在ARDUINO中输出GB2312编码中文
8266驱动LCD,显示中文,,GB2312编码, 可以用数据存储方式,也可以用串口打印方式,输出GB2312中文编码+Unicode 字符数组,英文,符号, 非常方便ARDUINO输出到中文串口屏幕显示方面,ARDUINO中LCD显示GB2312全中文,
,
,
gb23333.jpg

打赏

参与人数 1家元 +10 收起 理由
jf201006 + 10 謝謝分享

查看全部打赏

 楼主| 发表于 2022-5-26 12:21:04 | 显示全部楼层
主要用到这两个文件,
#include "cp936.h"
#include "UTF-8toGB2312.h"
==============================
如下程序,把ARDUINO中的中英文 ,字符串 转换成,GB2312的中英文的 数据组, 或者,串口直接打印,
===========

//=============================================================
   char  ch_dat_all [ 200];


   


bool cc_gb2312( String strutf8   , int comch  ) // //=0串口=1数据
{

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;  
       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)//串口
      //  ch_dat_all [ upget_id   ]  =   str_alll[ki] ;
        Serial.write(   str_alll[ki]  );


      
        
        upget_id ++;
      ki++;
       }
       else
       {

      if(   kpp==3   )
       {
                      //这里就开始进行UTF8->Unicode
                      //[1]  = [0]&0x0f  | [1]>>2&0x0f
                      //[0] =  [1]&0x03<<6  +[2]&0x3f
                     
                // temp[j + 1] = ((utf8[i] & 0x0F) << 4) | ((utf8[i + 1] >> 2) & 0x0F);
                // temp[j] = ((utf8[i + 1] & 0x03) << 6) + (utf8[i + 2] & 0x3F);

                 //   str_alll[ki]
                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);

//strcpy(p, p1) 复制字符串
//strncpy(p, p1, n) 复制指定长度字符串
                //取得Unicode的值
               //  memcpy(&unicodeKey, gbdat_hh, 2);


  
                  //根据这个值查表取得对应的GB2312的值
                gbKey = SearchCodeTable(unicodeKey);
                //printf("gbKey=0x%X\n",gbKey);
               // gbArray[k++]=gbKey;
               //  gbKey  = 中文  0x3a4f
  
     /**
  ch_dat_all [ upget_id  ]  = 92;            
ch_dat_all [ upget_id +1  ]  = gbKey>>8 ;
ch_dat_all [ upget_id  +2  ]  = 92;
ch_dat_all [ upget_id  +3  ]  = gbKey&0xff ;
      
   // upget_id +=4;//4=ok
   **/



        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  );


        }



   
upget_id +=2;


ki+=  3  ;  // 3

       }

        
       }





  
       }


      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;

}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-5-26 12:35:49 | 显示全部楼层
在加上 ,HZK16.bin 等各种字库, 在点阵,或者任何LCD上显示中文,
回复 支持 反对

使用道具 举报

发表于 2022-5-26 22:33:33 | 显示全部楼层
文件附件有吗?
回复 支持 反对

使用道具 举报

发表于 2022-5-27 10:42:51 | 显示全部楼层

要字符串中的中文,arduino IDE 是java开发的,java天生是支持utf-8的。。。。所以
回复 支持 反对

使用道具 举报

发表于 2022-5-27 11:50:04 | 显示全部楼层
这个要看你的源文件保存的什么格式吧?
我现在一般都是保存成UTF8格式,文件中的中文字符直接输出UTF8输出到u8g2控件显示中文。
以前那种自带中文字库的LCD显示屏,源文件就要保存GB格式,也是直接输出就能显示。
都无需转换。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-5-28 12:10:47 | 显示全部楼层
8266联网获取天气.用LCD打印出来,
,
66tttt.jpg ,
,
网址获取的是UTF8编码,转换后,用字库HZK16,打印显示在LCD上,实现了,全中文,英文,显示,无乱码.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-5-28 12:14:40 | 显示全部楼层
=============
获取天气并且显示7789LCD代码,
,
  1. /*


  2. code        color
  3. 0x0000        Black
  4. 0xFFFF        White
  5. 0xBDF7        Light Gray
  6. 0x7BEF        Dark Gray
  7. 0xF800        Red
  8. 0xFFE0        Yellow
  9. 0xFBE0        Orange
  10. 0x79E0        Brown
  11. 0x7E0        Green
  12. 0x7FF        Cyan
  13. 0x1F        Blue
  14. 0xF81F        Pink


  15. A1E6=  ℃   //2103
  16. A1E7=钱,

  17. //====================
  18. A3A1=!   33 ++
  19. A3A2="

  20. A3B0=0    48  ++

  21. */




  22. #include <ArduinoJson.h>

  23. //#include <ArduinoJson.h> //使用ArduinoJson库

  24. #include <ESP8266WiFi.h>
  25. #include <TimeLib.h>
  26. #include <WiFiUdp.h>

  27. #include <WiFiClient.h>
  28. #include <ESP8266WebServer.h>
  29. #include <ESP8266mDNS.h>
  30.   WiFiClient client;

  31.   ESP8266WebServer webServer(80);





  32. #include <ESP8266WiFiMulti.h>
  33. #include <ESP8266HTTPClient.h>



  34. //#include "cp936.h"
  35. #include "UTF-8toGB2312.h"

  36. #include "Solar2Luner.h"

  37. Solar2Luner S2L;


  38. typedef unsigned char uchar;
  39. typedef unsigned int uint;



  40. //========直接替换WIFI网络,密码
  41. #define WIFI_SSID "4FFF"
  42. #define WIFI_PASSWORD "666688888"









  43. #include <FS.h>

  44. FSInfo fs_info;

  45. File f;


  46. #include <TFT_eSPI.h> // Hardware-specific library
  47. #include <SPI.h>

  48. #define TFT_GREY 0x5AEB

  49. TFT_eSPI tft = TFT_eSPI();       // Invoke custom library


  50. uint32_t targetTime = 0;                    // for next 1 second timeout

  51. static uint8_t conv2d(const char* p); // Forward declaration needed for IDE 1.6.x

  52. uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time

  53. byte omm = 99, oss = 99;
  54. byte xcolon = 0, xsecs = 0;
  55. unsigned int colour = 0;




  56. int KKI;










  57.   bool tq_fff ;//





  58. /***

  59.      diqu  =   result_result_city  ;//温州

  60.       dangtian_ch   =  result_result_weather ;// 晴转多云
  61.   dangqian_tq = result_result_temp ;/22
  62.   dang_tian_l =  result_result_templow  ;//18
  63.   dang_tian_h =  result_result_temphigh ;//23

  64. **/

  65. String    diqu  = "";

  66. String    dangtian_ch = "";
  67.   String    dangqian_tq  = "";
  68.    String     dang_tian_l  = "";
  69.     String     dang_tian_h  = "";
  70.    




  71.   String   ttqq_all="";



  72.   String duan_tq_all="";










  73. int   xit_wk;

  74. int  xit_nn,xit_yy,xit_rr,xit_hh,xit_mm,xit_ss;


  75. int bk_ss ;

  76. int xit_up_ss;

  77. int urat_up_ss;





  78. //---------------------------


  79. //星期
  80. String week(int xqik )
  81. {
  82.   //1-7,7=星期天   ""   1    2   3    4   5   6    7
  83.   String wk[8] = {"日","一","二","三","四","五","六","天"};
  84.   String s = "星期" + wk[  xqik ];//wk==4
  85.   return s;
  86. }


  87. String wk_ch="";


  88. void  get_new_time(void )
  89. {


  90. int xq =  weekday();//5==星期4
  91. xq=xq-1; //0=天 ,123456
  92. //0=星期天
  93. if(xq==0)
  94. xq=7;

  95. //===  1=星期1 --- 7=星期日
  96. xit_wk = xq ;//1-7

  97. wk_ch="";
  98.   wk_ch =   week( xit_wk  );

  99. xit_nn = year() ;
  100. xit_yy =month()  ;
  101. xit_rr = day();
  102. xit_hh =hour() ;
  103. xit_mm =minute()  ;
  104. xit_ss =second();



  105.   
  106. }

  107. //=============================================================
  108. //---------------------------ntp


  109. time_t prevDisplay = 0; // 显示时间
  110. unsigned long weaterTime = 0;

  111. //=========

  112. //NTP服务器
  113. static const char ntpServerName[] = "ntp6.aliyun.com";
  114.   int timeZone = 8;     //东八区  ===修改时区


  115. WiFiUDP Udp;
  116. unsigned int localPort = 8000;

  117. time_t getNtpTime();
  118. void digitalClockDisplay();
  119. void printDigits(int digits);
  120. String num2str(int digits);
  121. void sendNTPpacket(IPAddress &address);


  122. //=============================================================
  123. //=============================================================
















  124. void drawchar(u16 chr,int x,int y){
  125. if(chr>=0xa1a0){
  126. u8 high,low;u8 buf[32];
  127. high=chr>>8;
  128. low=chr&0xff;

  129.   f.seek(32*((high-0xa0-1)*94+(low-0xa0-1)),SeekSet);
  130.   f.read(buf,32);
  131.   for(int i=0;i<16;i++)
  132.   {
  133.     u8 readr=buf[i*2];
  134.     for(int j=0;j<8;j++) {if(readr&(0x80>>j)) tft.drawPixel(x+j,y+i,TFT_MAGENTA );}
  135.     readr=buf[i*2+1];
  136.     for(int j=0;j<8;j++) if(readr&(0x80>>j)) tft.drawPixel(x+j+8,y+i,TFT_MAGENTA );
  137.   }
  138.   
  139. }
  140. }



  141. bool printchs(String str,int x,int y)
  142. {


  143.   
  144.     int num=str.length();
  145. int  n=num/3+10;
  146.   u16 s[n+1];
  147. bool pd=false;

  148.   Utf8ToGb2312(str.c_str(),num,s);


  149. int j=0;
  150.   for(int i=0;i<n;i++)
  151.   {
  152.     if(s[i]==0xffff) break;
  153.     if(x+i*16+16<241)
  154.     drawchar(s[i],x+i*16,y);
  155.     else
  156.     {
  157.       drawchar(s[i],j*16,y+16);j++;
  158.       
  159.       pd=true;
  160.       
  161.       }

  162.       
  163.   }



  164.   
  165.   return pd;

  166.   
  167. }




  168. //=============================================





  169. //=============================================================
  170.    char  ch_dat_all [ 4000];



  171. void drawchar22(u16 chr,int x,int y , u16 bjk )  // bjk TFT_MAGENTA
  172. {

  173.   
  174. if(chr>=0xa1a0)
  175. {
  176. u8 high,low;u8 buf[32];
  177. high=chr>>8;
  178. low=chr&0xff;

  179.   f.seek(32*((high-0xa0-1)*94+(low-0xa0-1)),SeekSet);
  180.   f.read(buf,32);
  181.   for(int i=0;i<16;i++)
  182.   {
  183.     u8 readr=buf[i*2];
  184.     for(int j=0;j<8;j++) {if(readr&(0x80>>j)) tft.drawPixel(x+j,y+i,bjk );}
  185.     readr=buf[i*2+1];
  186.     for(int j=0;j<8;j++) if(readr&(0x80>>j)) tft.drawPixel(x+j+8,y+i,bjk );
  187.   }
  188.   
  189. }



  190. }

  191. //----------------------------


  192. //  drawchar_zf22(  str_alll[ki]   ,x,y+yid ); // 写点阵




  193.   //   tft.drawString("open-lcd", 0, 0 ,4);

  194. void  drawchar_zf22(u16 chr,int x,int y , u16 bjk)
  195. {

  196. // bjk

  197. // tft.setTextColor( bjk  , TFT_BLACK  );
  198.     tft.setTextColor(  bjk  );
  199. // tft.drawString( chr, x, y ,4);
  200. tft.drawChar( chr, x, y , 2 );

  201. }

  202. void  drawchar_zf223(u16 chr,int x,int y, u16 bjk)
  203. {

  204.   
  205. //if(chr>=0xa1a0)


  206. if(chr>=33)// A3A1  A3A2
  207. {
  208. u8 high,low;u8 buf[32];
  209. u8 dum;

  210. dum=chr-33;

  211. high=0xa3;
  212. low=0xa1 + dum ;
  213. //A3A1 ++


  214. //  f.seek(16*((high-0xa0-1)*94+(low-0xa0-1)),SeekSet);

  215. f.seek(16*  ((high-0xa0-1)*94+(low-0xa0-1)  )  ,SeekSet);
  216.   f.read(buf,16);

  217.     for(int i=0;i<16;i++)
  218.   {
  219.     u8 readr=buf[i];
  220.     for(int j=0;j<8;j++)
  221.     {
  222.       if(readr&(0x80>>j))
  223.       tft.drawPixel(x+j,y+i, bjk );
  224.       
  225.       }

  226.       
  227.    // readr=buf[i*2+1];
  228.    // for(int j=0;j<8;j++) if(readr&(0x80>>j)) tft.drawPixel(x+j+8,y+i,TFT_MAGENTA );
  229.   }
  230.   

  231. }



  232. }

  233. //----------------------------












  234. bool cc_gb2312( String strutf8   , int comch  ,int x  ,int y  , u16 bjk  ) // //=0串口=1数据 3=写LCD
  235. {

  236. int str_len = strutf8.length() + 1;
  237. char str_alll[  str_len  ];


  238. strutf8.toCharArray(  str_alll , str_len);

  239.      //循环解析
  240.      int  ki=0;
  241.      int  kpp;

  242.      int endd_len=0;

  243.   int   upget_id =0;
  244.       u16 unicodeKey = 0;
  245.         u16 gbKey = 0;  


  246. int yid=0;
  247. int xid=0;
  248.         
  249.        while (ki < str_len )
  250.        {  

  251.    
  252.       
  253.         
  254.        kpp =  GetUtf8ByteNumForWord( str_alll[ki]   );


  255.        if(   kpp==0 )
  256.        {
  257.         if(comch==1)//数据
  258.         {

  259.         ch_dat_all [ upget_id   ]  =   str_alll[ki] ;

  260.         }
  261.         else  if(comch==0)//串口
  262.         {
  263.      
  264.    
  265.         Serial.write(   str_alll[ki]  );


  266.         }
  267.          else  if(comch==3)// 写LCD
  268.          {
  269.           //   gbKey   u16  gb2312

  270.         //  drawchar22(u16 chr,int x,int y); // 写点阵

  271.          drawchar_zf22(  str_alll[ki]   ,x+xid,y+yid , bjk ); // 写点阵

  272.        //   yid=yid+17;
  273.        xid=xid+9;
  274.        if(xid>239-5)
  275.        {
  276.         xid=0;
  277.         yid=yid+17;
  278.         
  279.        }


  280.          
  281.          }

  282.       
  283.         
  284.         upget_id ++;
  285.       ki++;
  286.        }
  287.        else
  288.        {

  289.       if(   kpp==3   )
  290.        {
  291.                     
  292.                 unicodeKey = (( str_alll[ki] & 0x0F) << 4) | (( str_alll[ki+1] >> 2) & 0x0F);
  293.                 unicodeKey =unicodeKey<<8;
  294.                 unicodeKey |= ((str_alll[ki + 1] & 0x03) << 6) + (str_alll[ki + 2] & 0x3F);

  295.   
  296.                   //根据这个值查表取得对应的GB2312的值
  297.                 gbKey = SearchCodeTable(unicodeKey);
  298.            

  299.         if(comch==1)//数据
  300.         {
  301. ch_dat_all [ upget_id   ]  = gbKey>>8 ;
  302. ch_dat_all [ upget_id  +1  ]  = gbKey&0xff ;

  303.          
  304.         }
  305.    
  306.         else  if(comch==0)//串口
  307.         {
  308.          Serial.write(  gbKey>>8  );
  309.          Serial.write(  gbKey&0xff  );


  310.         }
  311.          else  if(comch==3)// 写LCD
  312.          {
  313.           //   gbKey   u16  gb2312

  314.         //  drawchar22(u16 chr,int x,int y); // 写点阵

  315.          drawchar22(gbKey  ,x+xid,y+yid , bjk ); // 写点阵

  316.          // yid=yid+33;
  317.          xid=xid+17;
  318.       if(xid>239-5)
  319.        {
  320.         xid=0;
  321.         yid=yid+17;
  322.         
  323.        }

  324.          
  325.          }

  326. //=========================================



  327.    
  328. upget_id +=2;


  329. ki+=  3  ;  // 3

  330.        }
  331.        else
  332.        {
  333.     //  ki++;
  334.         
  335.        }
  336.       

  337.         
  338.        }





  339.   
  340.        }


  341.       if(comch==1)//数据
  342.         {

  343. //ch_dat_all [ upget_id    ]=0;
  344. //ch_dat_all [ upget_id  +1  ]=0;

  345.         }
  346.           else  if(comch==0)//串口
  347.         {

  348. //ch_dat_all [0   ]=0;
  349. //ch_dat_all [ 1  ]=0;

  350.          
  351.         }
  352.         

  353.   return 1;

  354. }







  355. //========================================






















  356. void setup(void)
  357. {
  358.   delay(80);
  359.   Serial.begin(115200);
  360.   delay(80);

  361.     Serial.println("");
  362.   Serial.println("=======8266================");
  363.     Serial.println("=======8266================");
  364.    Serial.println("");



  365.   SPIFFS.begin();       //启动SPIFFS
  366.   Serial.println("");
  367.   Serial.println("SPIFFS Started.");

  368.   // 闪存文件系统信息
  369.   SPIFFS.info(fs_info);

  370.   // 可用空间总和(单位:字节)
  371.   Serial.print("totalBytes: ");     
  372.   Serial.print(fs_info.totalBytes);
  373.   Serial.println(" Bytes");

  374.   // 已用空间(单位:字节)
  375.   Serial.print("usedBytes: ");
  376.   Serial.print(fs_info.usedBytes);
  377.   Serial.println(" Bytes");

  378.   // 最大文件名字符限制(含路径和'\0')
  379.   Serial.print("maxPathLength: ");
  380.   Serial.println(fs_info.maxPathLength);

  381.   // 最多允许打开文件数量
  382.   Serial.print("maxOpenFiles: ");
  383.   Serial.println(fs_info.maxOpenFiles);

  384.   // 存储块大小
  385.   Serial.print("blockSize: ");
  386.   Serial.println(fs_info.blockSize);

  387.   // 存储页大小
  388.   Serial.print("pageSize: ");
  389.   Serial.println(fs_info.pageSize);





  390.   Serial.println("=====all=======");
  391. Dir dir = SPIFFS.openDir("/");  // 開啟“/data”目錄
  392. while (dir.next())

  393. {   // 只要還有檔案…
  394.     Serial.print(dir.fileName());  // 顯示檔名
  395.     File f = dir.openFile("r");    // 以「唯讀」模式開啟檔案
  396.     Serial.println(f.size());      // 顯示檔案大小
  397. }
  398.      Serial.println("=====allned=======");

  399.         delay(100);
  400.         
  401.    f = SPIFFS.open("/hzk16.bin", "r");
  402.   delay(100);
  403.    if (!f) {
  404.     Serial.println("file open ==11111=not 文件打开失败");
  405.        Serial.println("======11111111111======");
  406.        f = SPIFFS.open("/hzk16.bin", "r");
  407.          delay(100);
  408.           if (!f) {
  409.     Serial.println("file open =222222==not 文件打开失败");
  410.        Serial.println("======22222222222======");
  411.    
  412.         }
  413.         else
  414.         {
  415.   Serial.println("file open ===OKkkkkk ");
  416.      Serial.println("=====222222222222=======");
  417.          
  418.         }


  419.         }
  420.         else
  421.         {
  422.   Serial.println("file open ===OKkkkkk ");
  423.          
  424.         }



  425.      WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  426.   tft.init();
  427.   tft.setRotation(1);
  428.   tft.fillScreen(TFT_BLACK);

  429.   tft.setTextSize(1);
  430.   tft.setTextColor(TFT_YELLOW, TFT_BLACK);

  431.   targetTime = millis() + 1000;



  432. tft.setTextColor(TFT_GREEN  );
  433.   tft.drawString("open-lcd", 0, 0 ,4);



  434.   delay(2000);



  435.   tft.fillScreen( TFT_BLACK );//清屏 ,背景全黑

  436. tft.setCursor(10, 40);  //显示位置

  437. tft.setTextSize(  1   );//字号


  438. tft.setTextColor( TFT_YELLOW ); //文字颜色
  439. tft.println("===========================");
  440. tft.println("==SPIFFS.open  /HZK16.bin==");
  441. tft.println("===========================");


  442.   delay(2000);



  443.   tft.fillScreen( TFT_BLACK );//清屏 ,背景全黑

  444.   
  445.      String bx="我是ESP8266中文屏幕";


  446. printchs(bx,5,30);


  447.     while (WiFi.status() != WL_CONNECTED)
  448.     {
  449.         Serial.println("==正在链接网络==");
  450.         delay(500);
  451.     }

  452.      Serial.println("");
  453.     Serial.print("链接成功 IP地址=: ");
  454.     Serial.println(WiFi.localIP());
  455.      Serial.println("");


  456.          delay(200);





  457.     tft.setTextWrap( 1 );   //打开(关闭)屏幕宽度(高度)中的文本换行
  458.   //textwrap.fill(text, width=70, **kwargs)

  459.     tft.setCursor(0 , 0);
  460.     tft.setTextSize(1);

  461.    tft.fillScreen( TFT_BLACK );//清屏 ,背景全黑

  462.    
  463.     tft.setTextColor( TFT_RED  );
  464.      tft.print(   "===open==="   );
  465.      

  466.   delay(45);



  467. //----------------------------
  468. //----------ntp-------



  469.   timeZone = 8;     //东八区


  470. //Serial.println("启动UDP");
  471.   Udp.begin(localPort);
  472.   //Serial.print("端口号: ");
  473.   //Serial.println(Udp.localPort());
  474.   //Serial.println("等待同步...");
  475. // setSyncProvider(getNtpTime);
  476. // setSyncInterval(300);

  477. setSyncProvider( getNtpTime );//设置同步提供程序
  478. // setSyncInterval(300);              //设置同步间隔



  479. //----------------------------


  480.   tq_fff=1;

  481.   
  482. }




  483. void loop()
  484. {



  485.     webServer.handleClient();


  486.   
  487.   // put your main code here, to run repeatedly:

  488. get_new_time();
  489. //更新...
  490. //  xit_wk;

  491. // xit_nn,xit_yy,xit_rr,xit_hh,xit_mm,xit_ss;

  492. // String     wk_ch="";//中文星期 UTF8

  493. //--------------------



  494.    jd_tianqi() ;  //   tq_fff


  495.    

  496.    //  ttqq_all




  497.   tft.fillScreen(TFT_BLACK);

  498. //  void setTextWrap(bool wrapX, bool wrapY = false);   //打开(关闭)屏幕宽度(高度)中的文本换行

  499.   //  tft.setTextWrap( 1 );   //打开(关闭)屏幕宽度(高度)中的文本换行
  500.   //textwrap.fill(text, width=70, **kwargs)

  501.     tft.setCursor(0 , 0);
  502.     tft.setTextSize(1);


  503.     tft.setTextColor( TFT_RED  );
  504.   //   tft.print(   "TFT_REdfgwerty4567yuy5fgh====ghhnfgbhtre4ry57y654jhbgfrbhhdr===222D"   );
  505.      
  506. // tft.print(     ch_dat_all    );

  507. cc_gb2312(  ttqq_all  , 3,  0 , 0 , TFT_MAGENTA  ); // //=0串口=1数据 3=写LCD
  508. //   
  509.   
  510.   delay(45);





  511. //===================


  512. /*******
  513.   String bx="我是ESP, 68:2;34=中文屏幕";


  514.   //  printchs(bx, 5 ,  KKI  );
  515. // cc_gb2312( String strutf8   , int comch  ,int x  ,int y   ); // //=0串口=1数据 3=写LCD


  516. cc_gb2312( bx , 3,  1 , KKI , TFT_MAGENTA  ); // //=0串口=1数据 3=写LCD


  517. KKI += 33 ;

  518. if( KKI >240)
  519. {
  520. KKI=0;
  521.   tft.fillScreen( TFT_BLACK );//清屏 ,背景全黑
  522.   

  523. tft.setCursor(0, 0);  

  524.   
  525. }

  526. **********/

  527.   delay(1000);

  528.   delay(1000);
  529.   delay(1000);

  530. }


  531. // Function to extract numbers from compile time string
  532. static uint8_t conv2d(const char* p) {
  533.   uint8_t v = 0;
  534.   if ('0' <= *p && *p <= '9')
  535.     v = *p - '0';
  536.   return 10 * v + *++p - '0';
  537. }





















  538. //=============================================================



  539. /*-------- NTP code ----------*/

  540. const int NTP_PACKET_SIZE = 48; // NTP时间在消息的前48字节中
  541. byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets





  542. time_t getNtpTime()
  543. {


  544.   
  545.   IPAddress ntpServerIP; // NTP server's ip address

  546.   while (Udp.parsePacket() > 0) ; // discard any previously received packets
  547.   //Serial.println("Transmit NTP Request");
  548.   // get a random server from the pool
  549.   WiFi.hostByName(ntpServerName, ntpServerIP);
  550.   //Serial.print(ntpServerName);
  551.   //Serial.print(": ");
  552.   //Serial.println(ntpServerIP);
  553.   sendNTPpacket(ntpServerIP);
  554.   uint32_t beginWait = millis();
  555.   while (millis() - beginWait < 1500)
  556.   {

  557.    
  558.     int size = Udp.parsePacket();
  559.    
  560.     if (size >= NTP_PACKET_SIZE)
  561.     {

  562.       
  563.     //  Serial.println("Receive NTP Response"); // 接收NTP响应

  564.     Serial.println("Receive NTP Response"); // 接收NTP响应
  565.      Serial.println("接收NTP响应"); // 接收NTP响应
  566.       Serial.println("==更新NTP网络时间=OK==="); // 接收NTP响应
  567.       
  568.       Udp.read(packetBuffer, NTP_PACKET_SIZE);  // read packet into the buffer
  569.       unsigned long secsSince1900;
  570.       // convert four bytes starting at location 40 to a long integer
  571.       secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
  572.       secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
  573.       secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
  574.       secsSince1900 |= (unsigned long)packetBuffer[43];
  575.       //Serial.println(secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR);
  576.       return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
  577.     }
  578.   }
  579. //  Serial.println("No NTP Response :-(");

  580.    Serial.println("=====No NTP ====没有NTP时间数据=====");
  581.   return 0; // 无法获取时间时返回0
  582. }

  583. // 向NTP服务器发送请求
  584. void sendNTPpacket(IPAddress &address)
  585. {
  586.   // set all bytes in the buffer to 0
  587.   memset(packetBuffer, 0, NTP_PACKET_SIZE);
  588.   // Initialize values needed to form NTP request
  589.   // (see URL above for details on the packets)
  590.   packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  591.   packetBuffer[1] = 0;     // Stratum, or type of clock
  592.   packetBuffer[2] = 6;     // Polling Interval
  593.   packetBuffer[3] = 0xEC;  // Peer Clock Precision
  594.   // 8 bytes of zero for Root Delay & Root Dispersion
  595.   packetBuffer[12] = 49;
  596.   packetBuffer[13] = 0x4E;
  597.   packetBuffer[14] = 49;
  598.   packetBuffer[15] = 52;
  599.   // all NTP fields have been given values, now
  600.   // you can send a packet requesting a timestamp:
  601.   Udp.beginPacket(address, 123); //NTP requests are to port 123
  602.   Udp.write(packetBuffer, NTP_PACKET_SIZE);
  603.   Udp.endPacket();
  604. }




  605. //=============================================================



















































  606. //  bool tq_fff ;//

  607. void jd_tianqi(void) //   tq_fff

  608.   {




  609. if(tq_fff)
  610.      {



  611.      // API server
  612. const char* host22 = "way.jd.com";
  613.    

  614.   // Connect to API
  615.   Serial.print("连接网站:   ");
  616.   Serial.println(host22);

  617.     Serial.println("");
  618.    
  619.   // Use WiFiClient class to create TCP connections
  620.   WiFiClient client;


  621.   
  622.   const int httpPort = 80;
  623.   
  624.   if (!client.connect(host22, httpPort))
  625.   {
  626.     Serial.println("网站连接没有数据  not http datta  ");
  627.     Serial.println("");
  628.     return;
  629.   }

  630.   
  631.   // We now create a URI for the request

  632.          String url = "/jisuapi/weather?city=温州&cityid=111&citycode=101260301&appkey=389直接注册京东的APK替换此处";


  633.   Serial.println("连接  URL : ");
  634.   Serial.println(url);
  635.    Serial.println("");

  636.    
  637.   // This will send the request to the server
  638.   client.print(String("GET ") + url + " HTTP/1.1\r\n" +
  639.                "Host: " + host22 + "\r\n" +
  640.                "Connection: close\r\n\r\n");
  641.   delay(600);
  642.   
  643.       //定义answer变量用来存放请求网络服务器后返回的数据
  644.     String answer;
  645.    
  646.     while(client.available())
  647.     {
  648.       String line = client.readStringUntil('\r');
  649.       answer += line;
  650.     }

  651.    
  652.     //断开服务器连接
  653.   client.stop();
  654.   Serial.println();
  655.   Serial.println("closing 断开服务器连接 connection");


  656. //====================
  657.   
  658.   //获得json格式的数据
  659.   String jsonAnswer;
  660.   int jsonIndex;
  661.   
  662.   //找到有用的返回数据位置i 返回头不要
  663.   for (int i = 0; i < answer.length(); i++)
  664.   {
  665.     if (answer[i] == '{')
  666.     {
  667.       jsonIndex = i;
  668.       break;
  669.     }
  670.   }

  671.   
  672.   jsonAnswer = answer.substring(jsonIndex);



  673.   
  674.   Serial.println();


  675.    Serial.println("");
  676.     Serial.println("");

  677.    Serial.println("======URL 网站 返回的全部数据--经过 json 处理 删除没用的 ====");
  678.      Serial.println("");
  679.    
  680. //   Serial.println( jsonAnswer);


  681.       Serial.println("");
  682.     Serial.println("");

  683. Serial.println("================= ");




  684. //   str=str.substring(int startIndex,int endIndex);截取str中从startIndex开始至endIndex结束时的字符串,并将其赋值给str;


  685.      ttqq_all="";
  686. ttqq_all +=    jsonAnswer.substring(373,1500 );

  687. // ttqq_all

  688.        Serial.println("");
  689.     Serial.println("");

  690.       Serial.println("===73-1500数据=:");
  691.     Serial.println(  ttqq_all  );


  692.           Serial.println("");
  693.     Serial.println("");
  694.          //   ttqq_all +=jsonAnswer;


  695. //y":"温州",
  696. //"cityid":390,"citycode":101210701,"date":"2022-05-26",
  697. //"week":"星期四","weather":"小到中雨","temp":"19","temphigh":"22","templow":"16",
  698. //"img":"21","humidity":"99","pressure":"1005","windspeed":"1.7","winddirect":
  699. //"西南风","windpower":"2级","updatetime":"2022-05-26 13:38:00","index":
  700. //[{"iname":"空调指数","ivalue":"较少开启","detail":"您将感到
  701. //500   

  702. //很舒适,一般不需要开启空调。"},
  703. //{"iname":"运动指数","ivalue":"较不宜","detail":"有降水,且风力较强,较适宜在户内进行各种健身休闲运动
  704. //;若坚持户外运动,请注意保暖。"},{"iname":"紫外线指数","ivalue":"最弱","detail":"属弱紫外线辐射天气,
  705. //无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。"},{"iname":"感冒指数","ivalue":
  706. //"易发","detail":"相对于今天将会出现大幅度降温,易发生感冒,请注意适当增加衣服,加强自我防护避免感冒。
  707. //"},{"iname":"洗车指数","ivalue":"不宜","detail":"不宜洗车,未来24小时内有雨,如果在此期间洗车,
  708. //雨水和路上的泥水可能会再次弄脏您的爱车。"},{"iname":"空气污染扩散指数","ivalue":"良","detail":"气
  709. //象条件有利于空气污染物稀释、扩散和清除,可在室外正常活动。"},{"iname":"穿衣指数","ivalue":"较舒适"
  710. //,"detail":"建议着薄外套、开衫牛仔衫裤等服装。年老体弱者应适当添加衣物,宜着夹克衫、薄毛衣等。"}],"aq
  711. //i":{"so2":"6","so224":"0","no2":"34","no224":"0","co":"0.520","co24":"0.000","o3":"64","o
  712. //38":"0","o324":"0","pm10":"38","pm1024":"0","pm2_5":"22","pm2_524":"0","iso2":"2","ino2":
  713. //"17","ico":"6","io3":"21","io38":"0","ipm10":"38","ipm2_5":"32","aqi":"38","primarypolluta
  714. //nt":"PM10","quality":"优","timepoint":"2022-05-26 13:00:00","aqiinfo":{"level":"一级","color
  715. //":"#00e400","affect":"空气质量令人满意,基本无空气污染","measure":"各类人群可正常活动"}},"daily":[
  716. //{"date":"2022-05-26","week":"星期四","sunrise":"05:03","sunset":"18:46","night":{"weather":"
  717. //阴","templow":"16","img":"2","winddirect":"持续无风向","windpower":"微风"},"day":{"weather":"
  718. //小到中雨","temphigh":"22","img":"21","winddirect":"持续无风向","windpower":"微风"}},{"date":"20
  719. //22-05-27","week":"星期五","sunrise":"05:03","sunset":"18:46","night":{"weather":"小到中雨","te
  720. //mplow":"18","img":"21","winddirect":"持续无风向","windpower":"微风"},"day":{"weather":"阴","te
  721. //mphigh":"26","img":"2","winddirect":"东南风","windpower":"3-5级"}},{"date":"2022-05-28","week
  722. //":"星期六","sunrise":"05:03","sunset":"18:47","night":{"weather":"小雨","templow":"19","img":
  723. //"7","winddirect":"持续无风向","windpower":"微风"},"day":{"weather":"中到大雨","temphigh":"20","
  724. //img":"22","winddirect":"持续无风向","windpower":"微风"}},{"date":"2022-05-29","week":"星期日","
  725. //sunrise":"05:02","sunset":"18:47","night":{"weather":"小雨","templow":"20","img":"7","winddir
  726. //ect":"持续无风向","windpower":"微风"},"day":{"weather":"小雨","temphigh":"28","img":"7","winddi
  727. //rect":"持续无风向","windpower":"微风"}},{"date":"2022-05-30","week":"星期一","sunrise":"05:02","
  728. //sunset":"18:48","night":{"weather":"小到中雨","templow":"21","img":"21","winddirect":"持续无风向
  729. //","windpower":"微风"},"day":{"weather":"小到中雨","temphigh":"28","img":"21","winddirect":"持续无
  730. //风向","windpower":"微风"}},{"date":"2022-05-31","week":"星期二","sunrise":"05:02","sunset":"18:48","night":{"weather":"小到中雨","templow":"20","img":"21","winddirect":"持续无风向","windpower":"微风"},"day":{"weather":"中到大

  731. 雨","temphigh":"26","img":"22","winddirect":"持续无风向","windpower":"微风"}},{"date":"2022-06-01","week":"星期三","sunrise":"05:01","sunset":"18:49","night":{"weather":"小雨","templow":"21","img":"7","winddirect":"持续无风

  732. 向","windpower":"微风"},"day":{"weather":"小到中雨","temphigh":"28","img":"21","winddirect":"东南风","windpower":"3-5级"}}],"hourly":[{"time":"13:00","weather":"小雨","temp":"22","img":"7"},{"time":"14:00","weather":"小

  733. 雨","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":"多

  734. 云","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"},

  735. {"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"},

  736. {"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"},

  737. {"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"},

  738. {"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);





  739. //===================================================






  740.   DynamicJsonDocument doc(9000);




  741.   deserializeJson(doc,jsonAnswer);
  742.   JsonObject obj = doc.as<JsonObject>();

  743. /********
  744. String input = "{"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}";
  745.   deserializeJson(doc, input);
  746.   JsonObject obj = doc.as<JsonObject>();

  747.   // You can use a String to get an element of a JsonObject
  748.   // No duplication is done.
  749.   //反序列化
  750.   long time = obj[String("time")];
  751.   String sensor = obj["sensor"];
  752.   double latitude = doc["data"][0];
  753.   double longitude = doc["data"][1];
  754.   **********/

  755.   



  756.   

  757. const char* code = doc["code"]; // "10000"


  758.     Serial.println("");
  759.     Serial.println("===code数据=:   ");   
  760.   Serial.print( code  );
  761.    Serial.println("");
  762. Serial.println("=====end====== ");
  763.   Serial.println("");


  764.   

  765. bool charge = doc["charge"]; // false
  766. const char* msg = doc["msg"]; // "查询成功"

  767. JsonObject result = doc["result"];
  768. int result_status = result["status"]; // 0
  769. const char* result_msg = result["msg"]; // "ok"

  770. String okstrr = result_msg ;

  771. String okbjj = "ok";


  772.   if( okstrr == okbjj  )
  773.   {

  774.    Serial.println("");
  775. Serial.println("   result['msg'];  ok  == 成功退出 ============================ ");
  776.   Serial.println("");

  777. tq_fff=0;
  778.    
  779.   }


  780. JsonObject result_result = result["result"];
  781. const char* result_result_city = result_result["city"]; // "温州"


  782.     Serial.println("");
  783.     Serial.println("=== 地区=:   ");   
  784.   Serial.print( result_result_city  );
  785.    Serial.println("");
  786. Serial.println("=====end====== ");
  787.   Serial.println("");

  788.    diqu  =   result_result_city  ;//温州



  789. int result_result_cityid = result_result["cityid"]; // 390
  790. const char* result_result_citycode = result_result["citycode"]; // "101210701"
  791. const char* result_result_date = result_result["date"]; // "2021-04-21"
  792. const char* result_result_week = result_result["week"]; // "星期三"
  793. const char* result_result_weather = result_result["weather"]; // "阴"
  794. const char* result_result_temp = result_result["temp"]; // "22"
  795. const char* result_result_temphigh = result_result["temphigh"]; // "23"
  796. const char* result_result_templow = result_result["templow"]; // "15"


  797.     Serial.println("");
  798.     Serial.println("==日期天气数据=:      ");   

  799.    
  800.   Serial.print( result_result_date );
  801.    Serial.print(",");
  802.   Serial.print( result_result_week  );
  803.    Serial.print(",");
  804.     Serial.print( result_result_weather  );
  805.      Serial.print(",");
  806. Serial.print(" 当前");
  807.       Serial.print( result_result_temp );
  808. Serial.print("度");
  809.   Serial.print(",");

  810. Serial.print("当天: ");
  811.       Serial.print( result_result_templow  );
  812. Serial.print("~");


  813. Serial.print(result_result_temphigh);
  814.      
  815. Serial.println("度");

  816.   Serial.print(",");

  817.   Serial.println("");

  818.   
  819.    Serial.println("");
  820. Serial.println("=====end====== ");
  821.   Serial.println("");

  822.   Serial.println("");


  823.    dangtian_ch   =  result_result_weather ;// 晴转多云
  824.   dangqian_tq = result_result_temp ;//22
  825.   dang_tian_l =  result_result_templow  ;//18
  826.   dang_tian_h =  result_result_temphigh ;//23


  827.      String DAOJJK  ="";


  828.    DAOJJK  = String( result_result_templow)    +"~" +  String( result_result_temphigh )  ;

  829.   

  830.   

  831. const char* result_result_img = result_result["img"]; // "2"
  832. const char* result_result_humidity = result_result["humidity"]; // "65"
  833. const char* result_result_pressure = result_result["pressure"]; // "1015"
  834. const char* result_result_windspeed = result_result["windspeed"]; // "2.5"
  835. const char* result_result_winddirect = result_result["winddirect"]; // "东风"
  836. const char* result_result_windpower = result_result["windpower"]; // "1级"
  837. const char* result_result_updatetime = result_result["updatetime"]; // "2021-04-21 10:00:00"







  838. for (JsonObject elem : result_result["index"].as<JsonArray>()) {

  839.   const char* iname = elem["iname"]; // "空调指数", "运动指数", "紫外线指数", "感冒指数", "洗车指数", "空气污染扩散指数", "穿衣指数"
  840.   const char* ivalue = elem["ivalue"]; // "较少开启", "较不宜", "最弱", "较易发", "不宜", "良", "较舒适"
  841.   const char* detail = elem["detail"]; // "您将感到很舒适,一般不需要开启空调。", ...

  842. }

  843. JsonObject result_result_aqi = result_result["aqi"];
  844. const char* result_result_aqi_so2 = result_result_aqi["so2"]; // "9"
  845. const char* result_result_aqi_so224 = result_result_aqi["so224"]; // "7"
  846. const char* result_result_aqi_no2 = result_result_aqi["no2"]; // "28"
  847. const char* result_result_aqi_no224 = result_result_aqi["no224"]; // "33"
  848. const char* result_result_aqi_co = result_result_aqi["co"]; // "0.400"
  849. const char* result_result_aqi_co24 = result_result_aqi["co24"]; // "0.320"
  850. const char* result_result_aqi_o3 = result_result_aqi["o3"]; // "73"
  851. const char* result_result_aqi_o38 = result_result_aqi["o38"]; // "31"
  852. const char* result_result_aqi_o324 = result_result_aqi["o324"]; // "54"
  853. const char* result_result_aqi_pm10 = result_result_aqi["pm10"]; // "58"
  854. const char* result_result_aqi_pm1024 = result_result_aqi["pm1024"]; // "59"
  855. const char* result_result_aqi_pm2_5 = result_result_aqi["pm2_5"]; // "22"
  856. const char* result_result_aqi_pm2_524 = result_result_aqi["pm2_524"]; // "24"
  857. const char* result_result_aqi_iso2 = result_result_aqi["iso2"]; // "4"
  858. const char* result_result_aqi_ino2 = result_result_aqi["ino2"]; // "14"
  859. const char* result_result_aqi_ico = result_result_aqi["ico"]; // "4"
  860. const char* result_result_aqi_io3 = result_result_aqi["io3"]; // "24"
  861. const char* result_result_aqi_io38 = result_result_aqi["io38"]; // "16"
  862. const char* result_result_aqi_ipm10 = result_result_aqi["ipm10"]; // "54"
  863. const char* result_result_aqi_ipm2_5 = result_result_aqi["ipm2_5"]; // "32"
  864. const char* result_result_aqi_aqi = result_result_aqi["aqi"]; // "54"
  865. const char* result_result_aqi_primarypollutant = result_result_aqi["primarypollutant"]; // "PM10"
  866. const char* result_result_aqi_quality = result_result_aqi["quality"]; // "良"
  867. const char* result_result_aqi_timepoint = result_result_aqi["timepoint"]; // "2021-04-21 09:00:00"

  868. JsonObject result_result_aqi_aqiinfo = result_result_aqi["aqiinfo"];
  869. const char* result_result_aqi_aqiinfo_level = result_result_aqi_aqiinfo["level"]; // "二级"
  870. const char* result_result_aqi_aqiinfo_color = result_result_aqi_aqiinfo["color"]; // "#FFFF00"
  871. const char* result_result_aqi_aqiinfo_affect = result_result_aqi_aqiinfo["affect"];
  872. const char* result_result_aqi_aqiinfo_measure = result_result_aqi_aqiinfo["measure"];

  873. for (JsonObject elem : result_result["daily"].as<JsonArray>()) {

  874.   const char* date = elem["date"]; // "2021-04-21", "2021-04-22", "2021-04-23", "2021-04-24", ...
  875.   const char* week = elem["week"]; // "星期三", "星期四", "星期五", "星期六", "星期日", "星期一", "星期二"
  876.   const char* sunrise = elem["sunrise"]; // "05:28", "05:27", "05:26", "05:25", "05:24", "05:23", "05:22"
  877.   const char* sunset = elem["sunset"]; // "18:26", "18:26", "18:27", "18:27", "18:28", "18:28", "18:29"

  878.   JsonObject night = elem["night"];
  879.   const char* night_weather = night["weather"]; // "多云", "小雨", "小雨", "小雨", "小雨", "小雨", "中雨"
  880.   const char* night_templow = night["templow"]; // "15", "18", "18", "17", "16", "17", "19"
  881.   const char* night_img = night["img"]; // "1", "7", "7", "7", "7", "7", "8"
  882.   const char* night_winddirect = night["winddirect"]; // "持续无风向", "持续无风向", "持续无风向", "持续无风向", "持续无风向", ...
  883.   const char* night_windpower = night["windpower"]; // "微风", "微风", "微风", "微风", "微风", "微风", "微风"

  884.   JsonObject day = elem["day"];
  885.   const char* day_weather = day["weather"]; // "多云", "小雨", "小雨", "小雨", "中雨", "小雨", "小雨"
  886.   const char* day_temphigh = day["temphigh"]; // "23", "23", "27", "23", "19", "19", "24"
  887.   const char* day_img = day["img"]; // "1", "7", "7", "7", "8", "7", "7"
  888.   const char* day_winddirect = day["winddirect"]; // "东南风", "持续无风向", "东风", "东南风", "东风", "东风", "持续无风向"
  889.   const char* day_windpower = day["windpower"]; // "3-5级", "微风", "3-5级", "3-5级", "3-5级", "3-5级", "微风"

  890. }

  891. for (JsonObject elem : result_result["hourly"].as<JsonArray>()) {

  892.   const char* time = elem["time"]; // "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", ...
  893.   const char* weather = elem["weather"]; // "阴", "阴", "多云", "多云", "多云", "多云", "多云", "多云", "晴", "晴", "晴", ...
  894.   const char* temp = elem["temp"]; // "22", "23", "23", "23", "23", "22", "22", "21", "20", "19", "18", ...
  895.   const char* img = elem["img"]; // "2", "2", "1", "1", "1", "1", "1", "1", "0", "0", "0", "0", "0", "1", ...

  896. }

  897. const char* requestId = doc["requestId"]; // "526a4d0ac41e4eb8a2ef91dd9f262f11"


  898.   // delay(5000);

  899.   }



  900.   


  901. }
复制代码


回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-5-28 12:16:06 | 显示全部楼层
fryefryefrye 发表于 2022-5-27 11:50
这个要看你的源文件保存的什么格式吧?
我现在一般都是保存成UTF8格式,文件中的中文字符直接输出UTF8输出 ...

原文件是网站获取的动态数据,无法确定是哪几个固定文字,所以需要全部的中文编码,
回复 支持 反对

使用道具 举报

发表于 2022-5-28 19:09:50 | 显示全部楼层
mckk520 发表于 2022-5-28 12:16
原文件是网站获取的动态数据,无法确定是哪几个固定文字,所以需要全部的中文编码, ...

天气之类的网页,现在都是UTF-8了。
这时候,对于ESP8266运行Arduino的话,直接引用u8g2库就行了,这个库自带utf8编码的中文16*16字库。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-5-29 06:57:56 来自手机浏览器 | 显示全部楼层
fryefryefrye 发表于 2022-5-28 19:09
天气之类的网页,现在都是UTF-8了。
这时候,对于ESP8266运行Arduino的话,直接引用u8g2库就行了,这个库 ...

那可是精简库,很多字显示不出来
回复 支持 反对

使用道具 举报

发表于 2022-6-7 08:47:47 | 显示全部楼层
mckk520 发表于 2022-5-29 06:57
那可是精简库,很多字显示不出来

u8g2有GB2312字库,但是太大了一般单片机装不下。
回复 支持 反对

使用道具 举报

发表于 2022-10-18 00:35:30 | 显示全部楼层
最近在学习这个,学习分享资料
回复 支持 反对

使用道具 举报

发表于 2023-2-19 20:27:16 | 显示全部楼层
一般都是用u8g2,还能实现局部刷屏
回复 支持 反对

使用道具 举报

发表于 2023-6-20 12:05:24 | 显示全部楼层
mckk520 发表于 2022-5-29 06:57
那可是精简库,很多字显示不出来

就是。在用一个阉割版的GB2312点阵字库,中文标点无法显示!
楼主这个能显示绝大多数中文的,请问能分享一下这个字库吗
谢谢!
回复 支持 反对

使用道具 举报

发表于 2023-9-15 23:54:42 | 显示全部楼层
感谢分享
楼主能不能把有关的文件打包分享一下 .h文件和HZK16.bin这些
最近是在看怎么做字库方面的

回复 支持 反对

使用道具 举报

发表于 2023-9-16 16:08:30 来自手机浏览器 | 显示全部楼层
能用单片机看小说吗
回复 支持 反对

使用道具 举报

发表于 2023-11-7 21:27:44 | 显示全部楼层
kpp =  GetUtf8ByteNumForWord( str_alll[ki]   );

编译到这里就出错了,无效的转换,为何?

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

闽公网安备35020502000485号

闽ICP备2021002735号-2

GMT+8, 2024-4-23 22:50 , Processed in 0.156000 second(s), 12 queries , Redis On.

Powered by Discuz!

© 2006-2023 smzj.net

快速回复 返回顶部 返回列表