天氣預報顯示+mqtt+dashboard

 天氣預報顯示+mqtt+dashboard-專題作品(1)

我的構想是資訊完全由公開資訊API抓取下來,分成兩個部份顯示
一個是在node-red dashboard由網頁顯示出來
另一個是在TFT顯示器顯示出來

先來看看node-red的dashboard顯示畫面如下:

包含了
  • 日期
  • AQI空氣品質
  • 七日預報(我只截取了一整天每3小時的預報)
  • PM2.5
  • 溫濕度


TFT顯示


較麻煩的是TFT上顯示字型和圖形


關於本篇所使用的方式
在主程式同一個資料夾裡新增img.h和font.h(檔名可自設)
  •     img.h是放圖形轉換為16進位存放的地方
  •     font.h是放字型轉換為16進位的地方

先看圖片要如何轉換為16進位

教學影片
https://youtu.be/0s3azw74iDQ

img.h-->其中片段
#include <pgmspace.h>
const unsigned short sunnuAndCloudy [] PROGMEM ={//02d
0x0001, 0x0001, 0x0021, 0x0840, 0x0020, 0x0000, 0x0000, 0x0820, 0x0000, 0x0001, 0x0001, 0x0000, 0x0020, 0x0020, 0x0040, 0x0080, 0x0001, 0x0002, 0x0001, 0x0001, 0x0801, 0x0000, 0x0000, 0x0000, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0820, 0x0820, 0x0821, 0x0000, 0x0001, 0x0000, 0x0841, 0x0020, 0x0040, 0x0020, 0x0001, 0x0001, 0x0001, 0x0000, 0x0800, 0x0841, 0x0820, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x18c2, 0x0860, 0x0040, 0x0040, 0x0840, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0020, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0820, 0x0000, 0x0840, 0x0840, 0x0000, 0x3165, 0x18c2, 0x0840, 0x0820, 0x0020, 0x1081, 0x10a1, 0x0020, 0x0000, 0x0000, 0x0020, 0x0841, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0040, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x1082, 0x2104, 0x10a2, 0x0840, 0x0000, 0x0820, 0x4a27, 0x5268, 0x39a6, 0x1041, 0x0000, 0x4206, 0x4227, 0x1060, 0x0020, 0x0820, 0x0820, 0x0000, 0x0000, 0x0001, 0x0021, 0x0000, 0x0001, 0x0001, 0x0002, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0020, 0x0000, 0x0000, 0x0021, 0x0021, 0x0021, 0x10a3, 0x2945, 0x5aca, 0x3164, 0x1080, 0x0800, 0x41a5, 0x730b, 0x6289, 0x0800, 0x1080, 0x62e9, 0x5aca, 0x1040, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0021, 0x0021, 0x0000, 0x0000, 0x0021, 0x0021, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0020, 0x0041, 0x0021, 0x0021, 0x0841, 0x10a2, 0x6b4c, 0x5ac9, 0x39a4, 0x0820, 0x28e1, 0x62a8, 0x6aa8, 0x1840, 0x3122, 0x6b0a, 0x62a9, 0x0820, 0x0000, 0x0821, 0x1062, 0x0862, 0x0020, 0x0020, 0x0000, 0x0000, 0x0020, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0840, 0x5288, 0x7bcd, 0x630a, 0x1880, 0x1860, 0x49a3, 0x49a3, 0x2040, 0x3983, 0x734a, 0x62c9, 0x1040, 0x0820, 0x20e4, 0x2946, 0x18c3, 0x0841, 0x0000, 0x0000, 0x0020, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0861, 0x2944, 0x3185, 0x2123, 0x10c1, 0x0860, 0x0840, 0x18c1, 0x28e1, 0x28c0, 0x49c4, 0x51e3, 0x51e2, 0x4140, 0x20a0, 0x3101, 0x2080, 0x0800, 0x3165, 0x6b2d, 0x62ec, 0x1062, 0x0000, 0x0881, 0x0840, 0x0000, 0x0020, 0x0040, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0821, 0x0001, 0x0840, 0x18c2, 0x4a88, 0x632a, 0x5b09, 0x41e5, 0x1060, 0x3963, 0x62c8, 0x9c4d, 0xbd50, 0xbd2e, 0xb4ec, 0xb4cb, 0x7b67, 0x49e2, 0x2900, 0x20a0, 0x6b0b, 0x5aaa, 0x41c7, 0x0001, 0x0001, 0x0020, 0x0020, 0x0000, 0x0860, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0001, 0x0001, 0x0820, 0x1060, 0x4205, 0x5ac8, 0x6309, 0x4a25, 0x2901, 0x6b29, 0xacd0, 0xde75, 0xeed4, 0xf714, 0xeeb1, 0xeeb0, 0xb52c, 0x7b66, 0x49c1, 0x2900, 0x6b0a, 0x5268, 0x3165, 0x18c3, 0x18e4, 0x10c3, 0x0882, 0x0041, 0x0021, 0x0000, 0x0042, 0x0021, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0801, 0x0821, 0x0000, 0x0000, 0x0840, 0x1060, 0x1880, 0x18a0, 0x6b29, 0xbd92, 0xf717, 0xff98, 0xff34, 0xff73, 0xf710, 0xeeae, 0xd64f, 0xbd6d, 0x7b87, 0x2920, 0x3983, 0x39a5, 0x4228, 0x630c, 0x52ab, 0x4249, 0x2145, 0x10e4, 0x0001, 0x0001, 0x0002, 0x0002, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0020, 0x0000,
0x0000, 0x0000, 0x0000, 0x1060, 0x20c1, 0x18a0, 0x1880, 0x28e0, 0xd634, 0xf737, 0xffd8, 0xffb6, 0xff53, 0xff31, 0xff50, 0xff4f, 0xc5cc, 0xbdac, 0xc5cf, 0xb550, 0xded8, 0xef3b, 0xef7e, 0xef7e, 0xd6fd, 0xdf1d, 0xcedc, 0xbe5a, 0x6baf, 0x29c8, 0x0884, 0x0023, 0x0000, 0x0000, 0x0020, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x1062, 0x20c3, 0x3965, 0x5248, 0x6b2b, 0x5226, 0x41a3, 0x3941, 0xef16, 0xff56, 0xff95, 0xff94, 0xff72, 0xf6ee, 0xeecd, 0xe66b, 0xce2e, 0xd670, 0xe6f4, 0xe6f6, 0xe6f9, 0xef5c, 0xef7e, 0xef9f, 0xe79f, 0xd71d, 0xcefc, 0xc6bb, 0xadd8, 0x7c72, 0x4acd, 0x1106, 0x0021, 0x0021, 0x0021, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0820, 0x20e3, 0x41c7, 0x5a89, 0x732c, 0x5227, 0x49c4, 0x49e3, 0xff57, 0xff75, 0xff53, 0xf731, 0xf70f, 0xeecd, 0xe6ac, 0xd629, 0xce2e, 0xe6d2, 0xef15, 0xffda, 0xef5b, 0xf7df, 0xef9f, 0xdf5f, 0xe79f, 0xdf7e, 0xd73d, 0xc6db, 0xc6db, 0xae19, 0x8cd4, 0x4acc, 0x0882, 0x0041, 0x0021, 0x0021, 0x0021, 0x0000, 0x0000, 0x0000,
0x0800, 0x1881, 0x18a2, 0x28c3, 0x28c3, 0x1860, 0x28e1, 0x5204, 0xf716, 0xf734, 0xff52, 0xff71, 0xf72f, 0xe6ac, 0xe68b, 0xde6a, 0xe6f2, 0xef34, 0xef56, 0xf77a, 0xf7bd, 0xf7bf, 0xf7ff, 0xe79f, 0xe79f, 0xe7bf, 0xdf7e, 0xd75d, 0xcefb, 0xbe9a, 0xae19, 0x9555, 0x10c4, 0x0062, 0x0021, 0x0021, 0x0041, 0x0020, 0x0000, 0x0000,
0x0840, 0x0840, 0x0000, 0x0842, 0x0001, 0x1061, 0x20c1, 0x3960, 0xe6b1, 0xf6ef, 0xf70e, 0xe6ad, 0xd66d, 0xce2e, 0xbe0f, 0xc652, 0xe77d, 0xe77d, 0xdf3c, 0xe75d, 0xefdf, 0xf7df, 0xefdf, 0xf7ff, 0xe7bf, 0xdf9f, 0xd77f, 0xcf3e, 0xc6fd, 0xbedc, 0xbedc, 0xc71d, 0xdf5e, 0xc6bb, 0x9535, 0x5b6e, 0x0021, 0x0021, 0x0021, 0x0841,
0x0000, 0x0840, 0x0821, 0x0842, 0x3987, 0x528a, 0x4a26, 0x28e0, 0xb52c, 0xde2d, 0xeece, 0xe6ae, 0xd66e, 0xdef2, 0xdef4, 0xc653, 0xdf1c, 0xdf3c, 0xdf3c, 0xe75d, 0xefbf, 0xefbf, 0xe7bf, 0xefdf, 0xdf7e, 0xd75e, 0xd75e, 0xcf3e, 0xcefd, 0xc6fd, 0xcf3e, 0xd77f, 0xdf7e, 0xd73d, 0xcedc, 0xb639, 0x3a29, 0x10e4, 0x0021, 0x0000,
0x0820, 0x0840, 0x1041, 0x10a3, 0x5aac, 0x5aab, 0x4a27, 0x1880, 0x8387, 0xc5ad, 0xd64e, 0xde90, 0xe6d2, 0xef56, 0xdf17, 0xceb7, 0xcefc, 0xd71c, 0xdf5d, 0xdf7e, 0xe79f, 0xe7bf, 0xe7bf, 0xe7bf, 0xdf7f, 0xd75f, 0xcf1e, 0xc6dd, 0xc6dc, 0xc6dc, 0xcf3e, 0xd79f, 0xefff, 0xe79f, 0xd75d, 0xd71d, 0x7410, 0x2987, 0x0062, 0x0000,
0x1040, 0x0000, 0x18a3, 0x5aab, 0x83f1, 0x41e8, 0x20c1, 0x0800, 0x3120, 0x942a, 0xc5cf, 0xe6f4, 0xef57, 0xef9a, 0xdf3a, 0xcefa, 0xcedc, 0xcefd, 0xd73e, 0xd75e, 0xdf5f, 0xdf9f, 0xe7bf, 0xdf7f, 0xd75f, 0xd73e, 0xc6fd, 0xc6bc, 0xc6bc, 0xc6dc, 0xcf1e, 0xd75e, 0xdf9f, 0xdf7e, 0xd73d, 0xcefc, 0xadd8, 0x428a, 0x10c4, 0x0001,
0x0000, 0x1061, 0x18a3, 0x18c3, 0x0001, 0x0000, 0x18c2, 0x3163, 0x41e4, 0x4203, 0x738a, 0xe6f8, 0xf7dc, 0xe77c, 0xcefb, 0xbe5a, 0xc6bc, 0xc6dd, 0xcf1e, 0xcf3e, 0xcf3f, 0xd75f, 0xd75f, 0xcf1e, 0xbe9c, 0xbebc, 0xc6dd, 0xcefd, 0xd73e, 0xd75e, 0xd75e, 0xd75e, 0xcf3d, 0xd75e, 0xcf1d, 0xc6bb, 0xb639, 0x530d, 0x1925, 0x0001,
0x0820, 0x0820, 0x0800, 0x18a3, 0x0000, 0x0821, 0x2103, 0x5aa9, 0x630a, 0x738c, 0x9cf1, 0xdf1b, 0xe77d, 0xdf7e, 0xcf1e, 0xb67c, 0xb69d, 0xbedd, 0xc6fe, 0xc71e, 0xc71f, 0xc71e, 0xbedd, 0xbe9c, 0xb67b, 0xbe9c, 0xc6dd, 0xcf3e, 0xdf7f, 0xdf9f, 0xdf9e, 0xdf7e, 0xcf3e, 0xc6fd, 0xbe9b, 0xb65a, 0xa5d8, 0x84b4, 0x6bf1, 0x52ed,
0x0800, 0x0000, 0x0000, 0x0841, 0x0000, 0x0020, 0x2965, 0x8c70, 0x94b2, 0xad54, 0xbe18, 0xd6fd, 0xe79f, 0xd75f, 0xbebd, 0xa63c, 0xae5c, 0xb69d, 0xb6be, 0xbede, 0xbefe, 0xb6bd, 0xae5c, 0xae5c, 0xbebc, 0xbedd, 0xcefd, 0xcf3e, 0xdf7e, 0xdf9f, 0xe79f, 0xe79f, 0xd7bf, 0xcf3e, 0xb69b, 0xae3a, 0x9db8, 0xa5f9, 0xa5d8, 0x9556,
0x0000, 0x0800, 0x0841, 0x0000, 0x0020, 0x0840, 0x4208, 0xbe18, 0xdf3c, 0xd6dc, 0xd6dc, 0xcedd, 0xcf1f, 0xcf5f, 0xbeff, 0xa65d, 0x9e3b, 0xae7d, 0xae9d, 0xae9d, 0xb6bd, 0xae5c, 0xa61a, 0xae5b, 0xb69c, 0xbedd, 0xcf3e, 0xd75e, 0xdf9f, 0xe7bf, 0xe7df, 0xefdf, 0xd7bf, 0xcf5f, 0xbedd, 0xae3a, 0xae3a, 0xbebc, 0xcf1e, 0xdf9f,
0x0801, 0x0000, 0x0000, 0x0000, 0x0000, 0x18c2, 0x5aeb, 0xdf1c, 0xf7ff, 0xd71d, 0xc6bc, 0xbe9c, 0xbebe, 0xbeff, 0xbf1f, 0xae7d, 0xa67c, 0x9e3b, 0x9e1b, 0xa67c, 0x9e1b, 0x9dfa, 0x95da, 0xa63b, 0xb6bd, 0xc71d, 0xcf3e, 0xd75e, 0xdf9f, 0xe7df, 0xefdf, 0xefff, 0xdfdf, 0xcf7f, 0xbedd, 0xae7b, 0xbedd, 0xcf5f, 0xd79f, 0xdfbf,
0x0000, 0x0000, 0x0000, 0x0000, 0x0840, 0x18e3, 0x52eb, 0xd6fb, 0xe77e, 0xdf3e, 0xc6bc, 0xae3b, 0xb69d, 0xb6bd, 0xb6be, 0xae9d, 0x95fa, 0x95fa, 0x95fa, 0x9e5c, 0x95fa, 0x95fa, 0x95fa, 0x9e1a, 0xb6bc, 0xbefd, 0xc73d, 0xcf5e, 0xdf9f, 0xdfbf, 0xe7bf, 0xe7df, 0xd7bf, 0xcf7f, 0xc71e, 0xae7c, 0xbebd, 0xc71e, 0xcf3e, 0xd77f,
0x0000, 0x0000, 0x0000, 0x0000, 0x0040, 0x18e2, 0x5b0b, 0xdf3c, 0xe77d, 0xdf7e, 0xcefc, 0xae1a, 0xae3b, 0xae7c, 0xae7d, 0xae7d, 0x8dda, 0x8dda, 0x95fa, 0x9e1b, 0x95d9, 0x95fa, 0x9e1a, 0x9e1a, 0xb6bc, 0xbefd, 0xc71d, 0xcf5e, 0xd79f, 0xdfbf, 0xdf9f, 0xdf9f, 0xd77f, 0xcf5f, 0xc71e, 0xae5b, 0xae5b, 0xbebc, 0xc6fe, 0xd73e,
0x0021, 0x0841, 0x0020, 0x0000, 0x0020, 0x10a2, 0x52ca, 0xceba, 0xe77e, 0xd75d, 0xcefc, 0xb65a, 0xa5f9, 0xa61b, 0xae5c, 0xa61b, 0x95fa, 0x95da, 0x95fa, 0x95fa, 0x8db9, 0x95da, 0x9e3b, 0x9e3b, 0xae9c, 0xb6dd, 0xbefd, 0xc73e, 0xd77f, 0xd79f, 0xd77f, 0xd75f, 0xdf9f, 0xcf5f, 0xcf1e, 0xbe9c, 0xa5d9, 0xb65b, 0xbe9b, 0xbe7b,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2165, 0x7c31, 0xceba, 0xc6db, 0xc6dc, 0xbe9b, 0xa5f9, 0x9d99, 0x9db9, 0x9dba, 0x95d9, 0x8d99, 0x95b9, 0x95d9, 0x8db9, 0x8598, 0x8db9, 0x95da, 0xa65c, 0xae9d, 0xb6bd, 0xbede, 0xc71e, 0xc73f, 0xcf3f, 0xcf3f, 0xc6fd, 0xbebc, 0xb65b, 0xa5b8, 0x63d1, 0x7432, 0x7412, 0x6390,
0x0000, 0x0020, 0x0000, 0x0021, 0x0021, 0x0021, 0x0882, 0x31e8, 0x94f4, 0xa5d7, 0xadf8, 0xadf9, 0x9557, 0x7454, 0x7434, 0x9559, 0xa63b, 0x9e1a, 0xa63b, 0xae7c, 0xae9c, 0x95fa, 0x95da, 0x95fa, 0x9e1b, 0xa65c, 0xae7d, 0xae9d, 0xb6de, 0xbede, 0xbede, 0xbeff, 0xc6bc, 0xbe7b, 0xadd8, 0x7c52, 0x2188, 0x29a8, 0x2987, 0x1905,
0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0001, 0x0021, 0x0883, 0x52ec, 0x6bcf, 0x6c11, 0x7432, 0x5b90, 0x42ce, 0x5310, 0x8cb7, 0xa63b, 0xae5b, 0xb69d, 0xbede, 0xbf1f, 0xa63c, 0x8dba, 0x95ba, 0x95fb, 0x9e3c, 0xa63c, 0xa65d, 0xae7d, 0xae9e, 0xb69e, 0xb6be, 0xc67b, 0xbe5a, 0x94f5, 0x4aac, 0x0042, 0x0042, 0x0042, 0x0001,
0x0000, 0x0000, 0x0020, 0x0021, 0x0000, 0x0001, 0x0001, 0x0021, 0x0021, 0x0082, 0x08c4, 0x1125, 0x0063, 0x0044, 0x1969, 0x5b31, 0xae7c, 0xb6bd, 0xc71e, 0xc73f, 0xcf9f, 0xae9d, 0x95fa, 0x95da, 0x8dda, 0x95fb, 0x9e1c, 0x9e1c, 0xa65d, 0xa65d, 0xae5d, 0xae5d, 0xb5f9, 0xb5d8, 0x7c52, 0x2987, 0x0021, 0x0021, 0x0001, 0x0001,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0021, 0x0021, 0x0022, 0x0042, 0x4acb, 0x94f4, 0xc69b, 0xe77e, 0xdf7f, 0xcf1e, 0xc6bd, 0xa5f9, 0x9598, 0x9db9, 0x9db9, 0x9599, 0x95b9, 0x9dfa, 0xa61b, 0xa61b, 0xad76, 0x6b6e, 0x31c8, 0x0041, 0x0000, 0x0020, 0x0000, 0x0020,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0021, 0x0021, 0x0021, 0x10c3, 0x31e8, 0x52ec, 0x7c52, 0xa577, 0xadf9, 0xa5d8, 0x84f5, 0x84b5, 0x8d16, 0x9578, 0x9d99, 0x9db9, 0x9db9, 0x9578, 0x8517, 0x6b6e, 0x39e8, 0x18e4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0021, 0x0882, 0x10e3, 0x3208, 0x5b2d, 0x638f, 0x6bb0, 0x532e, 0x532e, 0x5bb0, 0x7433, 0x7c94, 0x7cb5, 0x7c74, 0x6bf2, 0x5b70, 0x2966, 0x10a3, 0x0842, 0x0000, 0x0021, 0x0841, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0000, 0x0021, 0x0021, 0x0001, 0x0021, 0x0001, 0x0083, 0x1126, 0x29c8, 0x322a, 0x3a4b, 0x29e9, 0x1947, 0x08c5, 0x0042, 0x0001, 0x0001, 0x0000, 0x0021, 0x0021, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0021, 0x0021, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0021, 0x0021, 0x0021, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0800, 0x0820, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0000, 0x0000, 0x0000, 0x0001, 0x0021, 0x0021, 0x0001, 0x0001, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0800, 0x0000, 0x0800, 0x0800, 0x0820, 0x0800, 0x0000, 0x0800, 0x0000, 0x0000, 0x0820, 0x0820, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0021, 0x0000, 0x0021, 0x0000, 0x0021, 0x0000, 0x0000
};

字模软件


教學影片

font.h-->其中片段
#include <pgmspace.h>

const unsigned char comma PROGMEM[]={
  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x20,0x20,0x40,/*",",0*/
};
struct FNT_HZ // 汉字字模数据结构
{
  char  Index[4];              // 汉字内码索引,存放内码,如"中",在UTF-8编码下,每个汉字占3个字节,第四个是结束符0
  const unsigned char* hz_Id;  // 点阵码数据      存放内码后对应的 点阵序列  每个字需要32个字节的点阵序列
  unsigned char hz_width;
};
PROGMEM const FNT_HZ hz[] =
{
  {"溫", t,16},
  {"濕", h,16},
  {"多", dou, 16},
  {"云", yun, 16},
  {"晴", qing, 16},
  {"雨", yu, 16},
  {"小", sou, 16},
  {"阴", yin, 16},
  {"度", spend, 16},
  {"少", shao, 16},
  {",", comma, 16},
  {"薄", bo, 16},
  {"霧", wu, 16},
};

Node-red(有空再補)

這裡我們主要用到
openweathrMap的API取得進七日的天氣



主程式

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <PubSubClient.h>
#include <SPI.h>
#include <TFT_eSPI.h>
#include "font.h"
#include "bmp.h"

TFT_eSPI tft=TFT_eSPI();

const char *ssid="";
const char *password="";
const char *mqttServer="";

WiFiClient espClient;
PubSubClient client(espClient);

String MqttTemp="338/temp";
String MqttHumi="338/humi";
String date="esp32/date";
String icons="338/weather";
String detail="338/detail";
String pm="esp32/pm25";

void showHanzi(int32_t x, int32_t y, const char c[], uint32_t color) {
  for (int k = 0; k < 20; k++)// 根据字库的字数调节循环的次数
    if (hz[k].Index[0] == c[0] && hz[k].Index[1] == c[1] && hz[k].Index[2] == c[2])
    { tft.drawBitmap(x, y, hz[k].hz_Id, hz[k].hz_width, 16, color);
    }
}

void wifiConn(){
  WiFi.begin(ssid, password);
  while (WiFi.isConnected()==false){
    Serial.print(".");
    delay(1000);
  }
  Serial.println("WiFi connected success!");
  Serial.println(WiFi.localIP());
}

void callback(char *topic, byte *message, unsigned long lengh){
  String msg;
  Serial.print("topic: ");
  Serial.println(topic);
  Serial.print("msg: ");
  for (int i=0; i<lengh; i++){
    Serial.print(char(message[i]));
    msg+=char(message[i]);
  }
  Serial.println();
  if (String(topic)==MqttTemp){
    Serial.println(msg);
    tft.setTextSize(2);
    tft.setTextColor(tft.color565(112,157,255));
    tft.fillScreen(TFT_BLACK);
    tft.setCursor(55, 60);
    tft.print(msg);
    showHanzi(105, 60, "度", tft.color565(112,157,255));
  }
  if (String(topic)==MqttHumi){
    Serial.println(msg);
    tft.setTextColor(tft.color565(255,87,87));
    tft.setTextSize(2);
    tft.setCursor(55, 80);
    tft.print(msg+"%");
  }
  if (String(topic)==date){
    Serial.println(msg);
    tft.setTextColor(TFT_VIOLET);//年月日
    tft.setTextSize(2);
    tft.setCursor(5, 10);
    tft.print(msg.substring(0,10));
    tft.setTextColor(tft.color565(255, 252, 87));//星期
    tft.setTextSize(2);
    tft.setCursor(90, 30);
    tft.print(msg.substring(20,23));
  }
  if (String(topic)==pm){
    Serial.println(msg);
    tft.setTextSize(2);
    tft.setCursor(5, 110);
    tft.print("pm2.5:"+msg+"ug");
    tft.setTextColor(tft.color565(193, 255, 128));//aqi
  }

  if (String(topic)==icons){
    Serial.println(msg);
    if (msg=="04d"){
      tft.setSwapBytes(true);
      tft.pushImage(10, 60, 40, 40, partly_cloud);
      showHanzi(10,30,"多",TFT_WHITE);
      showHanzi(30,30,"云",TFT_WHITE);
    }
    else if (msg=="10d"){
      tft.setSwapBytes(true);
      tft.pushImage(10, 50, 40, 40, littleRain);
      showHanzi(10,30,"小",TFT_WHITE);
      showHanzi(30,30,"雨",TFT_WHITE);
    }
    else if (msg="02d"){
      tft.setSwapBytes(true);
      tft.pushImage(10, 50, 40, 40, sunnuAndCloudy);
      showHanzi(10,30,"晴",TFT_WHITE);
      showHanzi(40,30,"少",TFT_WHITE);
      showHanzi(60,30,"云",TFT_WHITE);
    }
    else if (msg="03d"){
      tft.setSwapBytes(true);
      tft.pushImage(10, 50, 40, 40, scattered_clouds);
      showHanzi(10,30,"少",TFT_WHITE);
      showHanzi(30,30,"云",TFT_WHITE);
    }
    else if (msg="50d"){
      tft.setSwapBytes(true);
      tft.pushImage(10, 50, 40, 40, mist);
      showHanzi(10,30,"薄",tft.color565(184, 181, 191));
      showHanzi(30,30,"霧",tft.color565(184, 181, 191));
    }
  }
}

void reConnMqtt(){
  while (! client.connected()){
    Serial.println("正在連線mqtt...");
    if (client.connect("esp32Client")){
    client.subscribe("338/temp");
    client.subscribe("338/humi");
    client.subscribe("esp32/date");
    client.subscribe("338/weather");
    client.subscribe("338/detail");
    client.subscribe("esp32/pm25");
    }else{
      Serial.print("無法連線的原因: ");
      Serial.println(client.state());
      delay(2000);
    }
  }
}

void setup() {
  Serial.begin(115200);
  wifiConn();
  tft.init();
  tft.begin();
  tft.setRotation(3);//螢幕方向
  tft.fillScreen(TFT_BLACK);
 
  client.setServer(mqttServer, 1883);
  client.setCallback(callback);

  // showHanzi(5,110,"溫",(TFT_BROWN));
  // showHanzi(65,110,"濕",TFT_DARKCYAN);
  // tft.drawFastHLine(5,100,120,tft.alphaBlend(0, TFT_BLACK, tft.color565(255, 255, 255)));//上直線
  // tft.drawFastHLine(5,30,120,tft.alphaBlend(0, TFT_BLACK, tft.color565(255, 255, 255)));//下直線
  //tft.drawFastVLine(60, 100,120,tft.alphaBlend(0, TFT_BLACK, tft.color565(255, 255, 255)));
}

void loop() {
  if (! client.connected()){
    reConnMqtt();
  }
  client.loop();
 
}































留言

這個網誌中的熱門文章