作者: C_Law 時間: 2021-2-18 18:11 標題: LCD display library
本帖最後由 C_Law 於 2021-2-18 18:13 編輯
這塊 Display 是朋友好耐之前淘返來不識用就放埋一邊,最近執屋搵返出來,他不要就送給我玩。
我想試下用 Arduino UNO 或 ESP8266 去玩,應該用什麼 Library?
背面幾粒 Chip 的字又細又矇,老花眼的我用埋放大鏡都睇不到。
https://h0.hkepc.com/forum/attachment.php?aid=2249661&k=6025079730cc7e89613508d038e8452e&t=1781592527&sid=38c58EYhg6

https://h0.hkepc.com/forum/attachment.php?aid=2249663&k=48956bd6583d07d18c3d42aff44094dc&t=1781592527&sid=38c58EYhg6

作者: hon829 時間: 2021-2-18 18:25
行UART通訊, 似無lib.
https://www.aliexpress.com/i/32891203005.html
作者: xiao 時間: 2021-2-18 18:38
http://www.sun-lcm.com/a/guanyuwomen/ziliaoxiazai/kafagongju/
作者: Charcoal99 時間: 2021-2-18 18:56
模塊資料在樓上連結, 按 「集成串口屏模块」, 選 JC024 下載.
作者: C_Law 時間: 2021-2-18 19:21
Thanks all~~~~
研究下先。
作者: C_Law 時間: 2021-5-23 16:54
本帖最後由 C_Law 於 2021-5-23 22:23 編輯
唔該各位師兄!!
Ooops~~~~今日上不到圖
相隔好耐, 今日先到得閒拎出來玩, 搵塊 D1 mini 上網拎時間做個鐘玩下。再有時間玩就去埋天文台搵溫度,濕度之類。
via HKEPC IR Pro 3.6.1 - Android(3.3.1)
https://h0.hkepc.com/forum/attachment.php?aid=2264727&k=a46655a3232087122584da5f4caec870&t=1781592527&sid=38c58EYhg6

作者: xiao 時間: 2021-5-25 22:29
這厲害 請問哪裡買 多少銀兩
作者: C_Law 時間: 2021-5-26 05:40
這塊 LCD 係朋友給我,我都不知本來從哪裡買。不過上淘佬用 JC024 QVGA 做 Keywords 搵下,似係這個:
标准JC024串口屏集成字库图片功能UART指令驱动 HMI人机交互
https://item.taobao.com/item.htm?id=605375019156
https://detail.tmall.com/item.htm?id=620656642888
價錢好飄忽,同樣係塊 Display + 4 pin 線,一間賣 30 人仔,一間要 60!以上兩間都要另加大陸段運費。
作者: xiao 時間: 2021-5-26 07:59
謝謝你的資訊 看來不值這價位
作者: C_Law 時間: 2021-6-5 17:30
本帖最後由 C_Law 於 2021-6-5 17:42 編輯
今日得閒繼續玩,上天文台搵埋濕度/溫度放入個 Display。本來還想搵埋酷熱/寒冷/火災/暴雨/風球之類的警告,但今日什麼警告都無,無得睇個 json 檔的真正內容,只能憑天文台的說明檔去估。
暫時打算平時濕度/溫度用綠色字,有黃/紅火災警告時將濕度改用黃/紅色字,有酷熱/寒冷警告就將溫度改用紅/藍色字。目前濕度值左邊還有位剩,打算預留作風球、黑/紅/黃雨。
另外,之前玩開 irplusLAN(一個本來用來經 WiFi/BT 發射紅外線遙控訊號的 Android App),順手將以前做 IR 發射器的 Code 改一改加埋入個鐘,目前可以用手機經 irplusLAN 以 WiFi 控制個鐘改顏色、背光的光暗、手動即時上網更新時間/天氣。
分區溫度及天文台濕度:(後面的 &lang=xx,xx 可改為 en/tc/sc=英/繁/簡)
https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread&lang=en
天氣警告:
https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=warnsum&lang=tc
英文使用說明:
https://data.weather.gov.hk/weatherAPI/doc/HKO_Open_Data_API_Documentation.pdf
繁中使用說明:
https://data.weather.gov.hk/weatherAPI/doc/HKO_Open_Data_API_Documentation_tc.pdf
https://h0.hkepc.com/forum/attachment.php?aid=2266689&k=bac5f2dc88a34644ad3cd225392eaca6&t=1781592527&sid=38c58EYhg6

作者: royc 時間: 2021-6-10 11:10
師兄請教一下,小弟正想試下整個香港地區溫度,用你上面個天文台api。
請問有冇參考連結例程可以用到香港地區data,改小小就用得。我用D1mini的
謝謝
via HKEPC IR Pro 3.6.1 - iOS(3.0.0)
作者: C_Law 時間: 2021-6-13 01:57
本帖最後由 C_Law 於 2021-6-13 02:35 編輯
以下係我玩緊個鐘的部份 Code,可以用 rhrread 搵到:
閃電
分區氣溫
天文台濕度
以及用 warnsum 搵到
風球
紅黑黃雨
雷暴警告
寒冷/酷熱警告
紅/黃火災警告
上載到 ESP8266 前要先修改 PortNo, WiFi 的 SSID/PASSWORD。
(好似改返正)
- #ifndef UNIT_TEST
- #include <Arduino.h>
- #endif
- #include <ESP8266WiFi.h>
- #include <ESP8266WiFiMulti.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- #include <WiFiClient.h>
- #include <ESP8266HTTPClient.h>
- // some parameters used for WiFi
- const unsigned int PortNo = 80;
- const char* SSID1 = "yourSSID1"; // SSID and Password for WiFi connection
- const char* PW1 = "yourPASSWORD1";
- const char* SSID2 = "yourSSID2";
- const char* PW2 = "yourPASSWORD2";
- const char* SSID3 = "yourSSID3";
- const char* PW3 = "yourPASSWORD3";
- const uint16_t LED = 2; // OnChipLED(Pull_Up)=D4 for D1 mini
- const bool LEDon = false; // false for Pull_Up, otherwise true
- // some variables for weather
- String weatherJSON;
- String TempC;
- String MaxMinTempC;
- String HumPercent;
- String WTCSGNL; // Tropical Cyclone Warning Signal: None, TC1, TC3, TC8xx, TC9, TC10
- bool Lightning;
- bool WTS = false; //Thunderstorm warning
- int wFire; // Fire warning: 0,1,2=Normal, Yellow, Red
- int wCH; // Cold/Hot warning: 0,1,2,=Normal,Cold,Hot
- int wRAIN; // Rain warning: 0,1,2,3=None,Amber,Red,Black
- ESP8266WiFiMulti wifiMulti;
- ESP8266WebServer server(PortNo);
- void setup() {
- pinMode(LED, OUTPUT);
- digitalWrite(LED, LEDon);
-
- Serial.begin(115200);
- Serial.println("");
-
- WiFi.mode(WIFI_STA);
- wifiMulti.addAP(SSID1, PW1);
- wifiMulti.addAP(SSID2, PW2);
- wifiMulti.addAP(SSID3, PW3);
-
- // waiting for WiFi connection
- while (wifiMulti.run() != WL_CONNECTED) {
- delay(500);
- }
-
- Serial.println("");
- Serial.print("Connected to: ");
- Serial.println(WiFi.SSID());
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP().toString());
- Serial.print("Port no.: ");
- Serial.println(PortNo);
- digitalWrite(LED, !LEDon);
-
- server.on("/", handleRoot);
- server.on("/rhrread", handleRhrread);
- server.on("/warnsum", handleWarnSum);
- server.on("/rhrread2", handleRhrread2);
- server.on("/warnsum2", handleWarnSum2);
- server.onNotFound(handleNotFound);
- server.begin();
- }
- void loop() {
- server.handleClient();
- }
- void handleRoot() {
- String message = "";
- message = "<HTML>\n" \
- " <HEAD>\n" \
- " <TITLE>Get weather information by ESP8266</TITLE>\n" \
- " </HEAD>\n" \
- " <body>\n" \
- " Get weather information by ESP8266<p>\n";
- message += " </body>\n" \
- "</HTLM>";
- server.send(200, "text/html", message);
- }
- void handleRhrread() {
- String message = "";
- if (GetJson("rhrread")){
- int StartPos = 0;
- int EndPos = weatherJSON.length() - 1;
- int ResultStart = 0;
- int ResultEnd = EndPos;
- String sTemp;
- String Location;
- message = weatherJSON;
-
- // Get Lightning warning for "Hong Kong and Kowloon"
- Location = "Hong Kong and Kowloon";
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- ResultStart = StartPos;
- ResultEnd = EndPos;
- Lightning = false;
- if (GetJsonRange("\"lightning\":{", "]", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"" + Location + "\",\"occur\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- Lightning = (weatherJSON.substring(ResultStart, ResultEnd) == "true");
- }
- }
- message += "\n\rLightning=";
- if (Lightning) message += "true";
- else message += "false";
-
- // Get "Kowloon City" temperture
- Location = "Kowloon City";
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- TempC = "";
- if (GetJsonRange("\"temperature\":{\"data\":[", "]", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"" + Location + "\",\"value\":", ",", StartPos, EndPos, &ResultStart, &ResultEnd)){
- TempC = weatherJSON.substring(ResultStart, ResultEnd) + "C";
- }
- }
- message += "\n\rTempC=" + TempC;
-
- // Get Humidity
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- ResultStart = StartPos;
- ResultEnd = EndPos;
- if (GetJsonRange("\"humidity\":{", "]", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"value\":", ",", StartPos, EndPos, &ResultStart, &ResultEnd)){
- HumPercent = weatherJSON.substring(ResultStart, ResultEnd) + "%";
- }
- }
- message += "\n\rHumidity=" +HumPercent;
- }
-
- server.send(200, "text/plain", message);
- }
- void handleRhrread2() {
- String message = "";
- if (true){
- weatherJSON = "{\"lightning\":{\"data\":[{\"place\":\"Lantau\",\"occur\":\"true\"},{\"place\":\"Hong Kong and Kowloon\",\"occur\":\"true\"}],\"startTime\":\"2021-06-11T18:45:00+08:00\",\"endTime\":\"2021-06-11T19:45:00+08:00\"},\"rainfall\":{\"data\":[{\"unit\":\"mm\",\"place\":\"Central & Western District\",\"max\":9,\"min\":1,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Eastern District\",\"max\":8,\"min\":1,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Kwai Tsing\",\"max\":2,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Islands District\",\"max\":12,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"North District\",\"max\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Sai Kung\",\"max\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Sha Tin\",\"max\":1,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Southern District\",\"max\":15,\"min\":7,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Tai Po\",\"max\":1,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Tsuen Wan\",\"max\":2,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Tuen Mun\",\"max\":3,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Wan Chai\",\"max\":10,\"min\":5,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Yuen Long\",\"max\":2,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Yau Tsim Mong\",\"max\":4,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Sham Shui Po\",\"max\":2,\"min\":1,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Kowloon City\",\"max\":1,\"min\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Wong Tai Sin\",\"max\":0,\"main\":\"FALSE\"},{\"unit\":\"mm\",\"place\":\"Kwun Tong\",\"max\":1,\"min\":0,\"main\":\"FALSE\"}],\"startTime\":\"2021-06-11T18:45:00+08:00\",\"endTime\":\"2021-06-11T19:45:00+08:00\"},\"icon\":[64],\"iconUpdateTime\":\"2021-06-11T20:25:00+08:00\",\"uvindex\":\"\",\"updateTime\":\"2021-06-11T20:26:00+08:00\",\"temperature\":{\"data\":[{\"place\":\"King's Park\",\"value\":27,\"unit\":\"C\"},{\"place\":\"Hong Kong Observatory\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Wong Chuk Hang\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Ta Kwu Ling\",\"value\":29,\"unit\":\"C\"},{\"place\":\"Lau Fau Shan\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Tai Po\",\"value\":29,\"unit\":\"C\"},{\"place\":\"Sha Tin\",\"value\":29,\"unit\":\"C\"},{\"place\":\"Tuen Mun\",\"value\":27,\"unit\":\"C\"},{\"place\":\"Tseung Kwan O\",\"value\":27,\"unit\":\"C\"},{\"place\":\"Sai Kung\",\"value\":29,\"unit\":\"C\"},{\"place\":\"Cheung Chau\",\"value\":26,\"unit\":\"C\"},{\"place\":\"Chek Lap Kok\",\"value\":27,\"unit\":\"C\"},{\"place\":\"Tsing Yi\",\"value\":29,\"unit\":\"C\"},{\"place\":\"Shek Kong\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Tsuen Wan Ho Koon\",\"value\":26,\"unit\":\"C\"},{\"place\":\"Tsuen Wan Shing Mun Valley\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Hong Kong Park\",\"value\":27,\"unit\":\"C\"},{\"place\":\"Shau Kei Wan\",\"value\":27,\"unit\":\"C\"},{\"place\":\"Kowloon City\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Happy Valley\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Wong Tai Sin\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Stanley\",\"value\":27,\"unit\":\"C\"},{\"place\":\"Kwun Tong\",\"value\":27,\"unit\":\"C\"},{\"place\":\"Sham Shui Po\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Kai Tak Runway Park\",\"value\":28,\"unit\":\"C\"},{\"place\":\"Yuen Long Park\",\"value\":29,\"unit\":\"C\"},{\"place\":\"Tai Mei Tuk\",\"value\":29,\"unit\":\"C\"}],\"recordTime\":\"2021-06-11T20:00:00+08:00\"},\"warningMessage\":[\"The Tropical Cyclone Signal No. 1 has been issued.\",\"The Amber Rainstorm Warning Signal was issued at 8:25 p.m.\",\"The Thunderstorm Warning has been issued. It will remain effective until 11:00 p.m. today. Occasional thunderstorms are expected to occur over Hong Kong.\"],\"mintempFrom00To09\":\"\",\"rainfallFrom00To12\":\"\",\"rainfallLastMonth\":\"\",\"rainfallJanuaryToLastMonth\":\"\",\"tcmessage\":[\"Here is the information on Tropical Depression:\nLocation: 18.3 degrees north, 112.3 degrees east; Maximum sustained wind near its centre: 45 km\/h.\"],\"humidity\":{\"recordTime\":\"2021-06-11T20:00:00+08:00\",\"data\":[{\"unit\":\"percent\",\"value\":88,\"place\":\"Hong Kong Observatory\"}]}}";
- int StartPos = 0;
- int EndPos = weatherJSON.length() - 1;
- int ResultStart = 0;
- int ResultEnd = EndPos;
- String sTemp;
- String Location;
- message = weatherJSON;
-
- // Get Lightning warning for "Hong Kong and Kowloon"
- Location = "Hong Kong and Kowloon";
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- ResultStart = StartPos;
- ResultEnd = EndPos;
- Lightning = false;
- if (GetJsonRange("\"lightning\":{", "]", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"" + Location + "\",\"occur\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- Lightning = (weatherJSON.substring(ResultStart, ResultEnd) == "true");
- }
- }
- message += "\n\rLightning=";
- if (Lightning) message += "true";
- else message += "false";
-
- // Get "Kowloon City" temperture
- Location = "Kowloon City";
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- TempC = "";
- if (GetJsonRange("\"temperature\":{\"data\":[", "]", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"" + Location + "\",\"value\":", ",", StartPos, EndPos, &ResultStart, &ResultEnd)){
- TempC = weatherJSON.substring(ResultStart, ResultEnd) + "C";
- }
- }
- message += "\n\rTempC=" + TempC;
-
- // Get Humidity
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- ResultStart = StartPos;
- ResultEnd = EndPos;
- if (GetJsonRange("\"humidity\":{", "]", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"value\":", ",", StartPos, EndPos, &ResultStart, &ResultEnd)){
- HumPercent = weatherJSON.substring(ResultStart, ResultEnd) + "%";
- }
- }
- message += "\n\rHumidity=" +HumPercent;
- }
-
- server.send(200, "text/plain", message);
- }
- void handleWarnSum() {
- String message ="";
- if (GetJson("warnsum")) {
- int StartPos = 0;
- int EndPos = weatherJSON.length() - 1;
- int ResultStart = 0;
- int ResultEnd = EndPos;
- String sTemp;
-
- // Check WRAIN
- wRAIN = 0;
- if (GetJsonRange("\"WRAIN\":{", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- sTemp = weatherJSON.substring(ResultStart, ResultEnd);
- if ((sTemp != "CANCEL") && (GetJsonRange("\"code\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd))){
- sTemp = weatherJSON.substring(ResultStart, ResultEnd);
- if (sTemp == "WRAINA") wRAIN = 1;
- else if (sTemp == "WRAINR") wRAIN = 2;
- else if (sTemp == "WRAINB") wRAIN = 3;
- }
- }
- }
- message = "\n\r\n\rwRAIN=";
- message += wRAIN;
-
- // Check Thunderstorm warning WTS
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- WTS = false;
- if (GetJsonRange("\"WTS\":{", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
-
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- sTemp = weatherJSON.substring(ResultStart, ResultEnd);
- if (sTemp != "CANCEL") WTS = true;
- }
- }
- message += "\n\rWTS=";
- if (WTS) message += "true";
- else message += "false";
-
- // Check Tropical Cyclone Warning Signal WTCSGNL
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- WTCSGNL = "None";
- if (GetJsonRange("\"WTCSGNL\":{\"", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- if (weatherJSON.substring(ResultStart, ResultEnd) != "CANCEL") {
- if (GetJsonRange("\"code\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- WTCSGNL = weatherJSON.substring(ResultStart, ResultEnd);
- }
- }
- }
- }
- message += "\n\rWTCSGNL=" + WTCSGNL;
-
- // Check WHOT
- wCH = 0;
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- if (GetJsonRange("\"WHOT\":{\"", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- if (weatherJSON.substring(ResultStart, ResultEnd) != "CANCEL") wCH = 2;
- }
- }
-
- // Check WCOLD
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- // wCH already reset before WHOT check, no need to reset in here
- if (GetJsonRange("\"COLD\":{\"", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- if (weatherJSON.substring(ResultStart, ResultEnd) != "CANCEL") wCH = 1;
- }
- }
- message += "\n\rwCH=";
- message += wCH;
-
- // Get WFIRE
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- wFire = 0;
- if (GetJsonRange("\"WFIRE\":{\"", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- if (weatherJSON.substring(ResultStart, ResultEnd) != "CANCEL") {
- if (GetJsonRange("\"code\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- sTemp = weatherJSON.substring(ResultStart, ResultEnd);
- if (sTemp == "WFIREY") wFire = 1; // yellow
- else if (sTemp == "WFIRER") wFire = 2; // red
- }
- }
- }
- }
- message += "\n\rwFire=";
- message += wFire;
- }
-
- message = weatherJSON + message;
- server.send(200, "text/plain", message);
- }
- void handleWarnSum2() {
- String message ="";
- if (true) {
- weatherJSON = "{\"WRAIN\":{\"name\":\"Rainstorm Warning Signal\",\"code\":\"WRAINA\",\"type\":\"Amber\",\"actionCode\":\"ISSUE\",\"issueTime\":\"2021-06-11T20:25:00+08:00\",\"updateTime\":\"2021-06-11T20:25:00+08:00\"},\"WTS\":{\"name\":\"Thunderstorm Warning\",\"code\":\"WTS\",\"actionCode\":\"UPDATE\",\"issueTime\":\"2021-06-11T18:35:00+08:00\",\"expireTime\":\"2021-06-11T23:00:00+08:00\",\"updateTime\":\"2021-06-11T21:10:00+08:00\"},\"WTCSGNL\":{\"name\":\"Tropical Cyclone Warning Signal\",\"code\":\"TC1\",\"actionCode\":\"ISSUE\",\"type\":\"Standby Signal No. 1\",\"issueTime\":\"2021-06-11T16:15:00+08:00\",\"updateTime\":\"2021-06-11T16:15:00+08:00\"}}";
- int StartPos = 0;
- int EndPos = weatherJSON.length() - 1;
- int ResultStart = 0;
- int ResultEnd = EndPos;
- String sTemp;
-
- // Check WRAIN
- wRAIN = 0;
- if (GetJsonRange("\"WRAIN\":{", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- sTemp = weatherJSON.substring(ResultStart, ResultEnd);
- if ((sTemp != "CANCEL") && (GetJsonRange("\"code\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd))){
- sTemp = weatherJSON.substring(ResultStart, ResultEnd);
- if (sTemp == "WRAINA") wRAIN = 1;
- else if (sTemp == "WRAINR") wRAIN = 2;
- else if (sTemp == "WRAINB") wRAIN = 3;
- }
- }
- }
- message = "\n\r\n\rwRAIN=";
- message += wRAIN;
-
- // Check Thunderstorm warning WTS
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- WTS = false;
- if (GetJsonRange("\"WTS\":{", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
-
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- sTemp = weatherJSON.substring(ResultStart, ResultEnd);
- if (sTemp != "CANCEL") WTS = true;
- }
- }
- message += "\n\rWTS=";
- if (WTS) message += "true";
- else message += "false";
-
- // Check Tropical Cyclone Warning Signal WTCSGNL
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- WTCSGNL = "None";
- if (GetJsonRange("\"WTCSGNL\":{\"", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- if (weatherJSON.substring(ResultStart, ResultEnd) != "CANCEL") {
- if (GetJsonRange("\"code\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- WTCSGNL = weatherJSON.substring(ResultStart, ResultEnd);
- }
- }
- }
- }
- message += "\n\rWTCSGNL=" + WTCSGNL;
-
- // Check WHOT
- wCH = 0;
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- if (GetJsonRange("\"WHOT\":{\"", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- if (weatherJSON.substring(ResultStart, ResultEnd) != "CANCEL") wCH = 2;
- }
- }
-
- // Check WCOLD
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- // wCH already reset before WHOT check, no need to reset in here
- if (GetJsonRange("\"COLD\":{\"", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- if (weatherJSON.substring(ResultStart, ResultEnd) != "CANCEL") wCH = 1;
- }
- }
- message += "\n\rwCH=";
- message += wCH;
-
- // Get WFIRE
- StartPos = 0;
- EndPos = weatherJSON.length() - 1;
- wFire = 0;
- if (GetJsonRange("\"WFIRE\":{\"", "}", StartPos, EndPos, &ResultStart, &ResultEnd)){
- StartPos = ResultStart;
- EndPos = ResultEnd;
- if (GetJsonRange("\"actionCode\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- if (weatherJSON.substring(ResultStart, ResultEnd) != "CANCEL") {
- if (GetJsonRange("\"code\":\"", "\"", StartPos, EndPos, &ResultStart, &ResultEnd)){
- sTemp = weatherJSON.substring(ResultStart, ResultEnd);
- if (sTemp == "WFIREY") wFire = 1; // yellow
- else if (sTemp == "WFIRER") wFire = 2; // red
- }
- }
- }
- }
- message += "\n\rwFire=";
- message += wFire;
- }
-
- message = weatherJSON + message;
- server.send(200, "text/plain", message);
- }
- void handleNotFound() {
- String message = "File Not Found\n\n";
- message += "URI: ";
- message += server.uri();
- message += "\nMethod: ";
- message += (server.method() == HTTP_GET)?"GET":"POST";
- message += "\nArguments: ";
- message += server.args();
- message += "\n";
- for (uint8_t i = 0; i < server.args(); i++)
- message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
- server.send(404, "text/plain", message);
- }
- bool GetJson(String dataType){
- /*
- dataType can be: rhrread, warnsum, fnd...etc
- */
- bool Result = false;
- HTTPClient http;
- WiFiClientSecure client;
- client.setInsecure(); // use with caution
- weatherJSON = ""; // clear previous JSON
-
- http.begin(client, "https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=" + dataType + "&lang=en");
- if (http.GET() == HTTP_CODE_OK) {
- weatherJSON = http.getString();
- Result = true;
- }
- return Result;
- }
- bool GetJsonRange(String StartString, String EndString, int StartPos, int EndPos, int *SectionStart, int *SectionEnd) {
- bool Good = true;
- int ResultStart = StartPos;
- int ResultEnd = EndPos;
- String message = "";
- // initial check
- if ((StartString == "") || (EndString =="")) Good = false;
- if (!Good || (StartPos < 0) || (StartPos > weatherJSON.length() - 1)) Good = false;
- if (!Good || (EndPos <= StartPos) || (EndPos > weatherJSON.length() -1)) Good = false;
-
- if (Good) {
- ResultStart = weatherJSON.indexOf(StartString, StartPos);
- if (ResultStart < 0) Good =false;
- else {
- ResultStart += StartString.length();
- if (ResultStart > EndPos) Good =false;
- else {
- ResultEnd = weatherJSON.indexOf(EndString, ResultStart);
- if (ResultEnd > EndPos) Good = false;
- }
- }
- }
- if (Good) {
- *SectionStart = ResultStart;
- *SectionEnd = ResultEnd;
- }
- return Good;
- }
好似寫了好多行,實際有百幾行係重複
上載及連到 WiFi 後(LED 會熄),可以用以用 Web browser 經以下網址讀取資料:
http://ip-address:PortNo/xxxx
ip-address 係 Router 派給 ESP8266 的 ip
PortNo 係程式開頭由你自定的 Port number
xxxx 可以係 rhrread 或 warnsum。(以及 rhrread2 或 warnsum2)
主要係經 GetJson() 去下載天文台的 JSON 檔。
至於由 JSON 搵出想要的資料,應該係有 Library 去解讀內容,但我懶得睇 Library 的說明,寧願自己寫,我用 GetJsonRange() 去搵我想要的數值。
例如搵九龍城氣溫,氣溫必定係以下一段之內:
"temperature":{"data":[{...},{...},...{九龍城資料},...{...}]}
我先用 GetJsonRange() 去搵 "temperature":{"data":[ 以及 ] 的位置(ResultStart, ResultEnd)。
然後係上次搵到的範圍內再搵九龍城資料,這資料會類似係:
{"place":"Kowloon City","value":28,"unit":"C"}
而溫度就夾係 "place":"Kowloon City","value": 同後面的逗號之間,可以再用 GetJsonRange() 去搵這兩個位置,最後就可以用substring 從 weatherJSON 之中抽出溫度數值(String)。
不過有些資料,例如暴雨警告,除了搵 WRAIN 同個 code 之外,還是睇埋 actionCode 是否 CANCEL。
作者: marlin12 時間: 2021-6-13 12:22
本帖最後由 marlin12 於 2021-6-13 15:38 編輯
有時間的話,可以試用ArduinoJson v6。
這個程式庫是雙向的,可以把陣列(array)轉為JSON,或者JSON轉為陣列。
ArduinoJson
Deserialize with ArduinoJson (JSON轉array)
還有ArduinoJson Assistant,教埋你點用。
只需要揀啱Processor(ESP8266)、Mode(Deserialize)、Input Type(String),然後放你個JSON字串入去,相關的程式便會自動產生出來。
作者: C_Law 時間: 2021-6-13 16:16
Thx~~~
其實我都有裝 ArduinoJson,不過無心機睇 Tutorial
作者: royc 時間: 2021-6-13 21:23
多謝各位師兄資料,都要時間消代一下。
Thanks
via HKEPC IR Pro 3.6.1 - iOS(3.0.0)
作者: xiao 時間: 2021-6-16 09:16
厲害, 結果看似簡單, 原來寫碼要這麼長
作者: C_Law 時間: 2021-6-18 21:33
其實我無學過 C++,亂寫一通
大致上完成我心目中想做的事。係差在不知怎去整黑雨警告,事關不想睇電視時被個鐘的光度吸引了視線,所以個鐘用黑色做底色,但黑底加個黑色雨字就即係無字!不想雨字改其他顏色,唯有係個雨字加底色,但試了好組合,還未試到個效果好的底色可以配到黃/紅黑。暫時用個「雨」字頂檔,遲下得閒會畫公仔。
ps.個 LCD 內置字庫同畫圖指令,話就話有 64 色可揀,但好多色重複,實際可用顏色其實好小。
https://h0.hkepc.com/forum/attachment.php?aid=2268755&k=54a980f010b8366ebcce72fe6b285755&t=1781592527&sid=38c58EYhg6



