DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

WifiStuff.cpp 38KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. /*
  2. * Copyright (c) 2021 Thomas Buck <thomas@xythobuz.de>
  3. *
  4. * This file is part of Giess-o-mat.
  5. *
  6. * Giess-o-mat is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Giess-o-mat is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Giess-o-mat. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #include <Arduino.h>
  20. #ifdef PLATFORM_ESP
  21. #if defined(ARDUINO_ARCH_ESP8266)
  22. #include <ESP8266WiFi.h>
  23. #include <ESP8266WebServer.h>
  24. #include <ESP8266mDNS.h>
  25. #elif defined(ARDUINO_ARCH_ESP32)
  26. #include <WiFi.h>
  27. #include <WebServer.h>
  28. #include <ESPmDNS.h>
  29. #endif
  30. #include <WebSocketsServer.h>
  31. #include "wifi.h"
  32. #include "config.h"
  33. #include "config_pins.h"
  34. #include "Functionality.h"
  35. #include "SimpleUpdater.h"
  36. #include "DebugLog.h"
  37. #include "BoolField.h"
  38. #include "WifiStuff.h"
  39. #ifdef TELEGRAM_TOKEN
  40. #include <WiFiClientSecure.h>
  41. #include <UniversalTelegramBot.h>
  42. //#define TELEGRAM_LOG_TIMINGS
  43. #if defined(ARDUINO_ARCH_ESP8266)
  44. X509List cert(TELEGRAM_CERTIFICATE_ROOT);
  45. #endif
  46. WiFiClientSecure secured_client;
  47. UniversalTelegramBot bot(TELEGRAM_TOKEN, secured_client);
  48. unsigned long last_telegram_time = 0;
  49. String trusted_chat_ids[] = TRUSTED_IDS;
  50. #endif // TELEGRAM_TOKEN
  51. UPDATE_WEB_SERVER server(80);
  52. WebSocketsServer socket = WebSocketsServer(81);
  53. SimpleUpdater updater;
  54. unsigned long last_server_handle_time = 0;
  55. unsigned long last_websocket_update_time = 0;
  56. int wifi_ok = 0;
  57. String message_buffer_a;
  58. String message_buffer_b;
  59. String message_buffer_c;
  60. String message_buffer_d;
  61. #ifdef ENABLE_GPIO_TEST
  62. static bool runningGpioTest = false;
  63. static bool gpioTestState = false;
  64. unsigned long lastGpioTime = 0;
  65. #endif // ENABLE_GPIO_TEST
  66. #ifdef ENABLE_INFLUXDB_LOGGING
  67. #include <InfluxDb.h>
  68. Influxdb influx(INFLUXDB_HOST, INFLUXDB_PORT);
  69. #endif // ENABLE_INFLUXDB_LOGGING
  70. #ifdef ENABLE_GPIO_TEST
  71. void runGpioTest(bool state) {
  72. lastGpioTime = millis();
  73. for (int i = 0; i < VALVE_COUNT; i++) {
  74. get_plants()->getValves()->setPin(i, state);
  75. delay(GPIO_TEST_DELAY);
  76. }
  77. for (int i = 0; i < PUMP_COUNT; i++) {
  78. get_plants()->getPumps()->setPin(i, state);
  79. if (i < (PUMP_COUNT - 1)) {
  80. delay(GPIO_TEST_DELAY);
  81. }
  82. }
  83. }
  84. void handleGpioTest() {
  85. runningGpioTest = !runningGpioTest;
  86. gpioTestState = runningGpioTest;
  87. String message = F("GPIOs turned ");
  88. message += runningGpioTest ? "on" : "off";
  89. server.send(200, "text/html", message);
  90. runGpioTest(gpioTestState);
  91. }
  92. #endif // ENABLE_GPIO_TEST
  93. void wifi_broadcast_state_change(const char *s) {
  94. #ifdef TELEGRAM_TOKEN
  95. for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
  96. bot.sendMessage(trusted_chat_ids[n], "New state: " + String(s), "");
  97. }
  98. #endif // TELEGRAM_TOKEN
  99. }
  100. #ifdef TELEGRAM_TOKEN
  101. enum telegram_state {
  102. BOT_IDLE,
  103. BOT_ASKED_FERT,
  104. BOT_ASKED_PLANTS,
  105. BOT_ASKED_CONFIRM
  106. };
  107. enum telegram_state bot_state = BOT_IDLE;
  108. String bot_lock = "";
  109. BoolField bot_plants(VALVE_COUNT - 1);
  110. BoolField bot_ferts(PUMP_COUNT);
  111. unsigned long telegram_update_interval() {
  112. if (bot_state == BOT_IDLE) {
  113. return TELEGRAM_UPDATE_INTERVAL_SLOW;
  114. } else {
  115. return TELEGRAM_UPDATE_INTERVAL_FAST;
  116. }
  117. }
  118. String telegram_help() {
  119. String s = "Usage:\n";
  120. s += "Send /auto and follow prompts.\n";
  121. s += "Send /abort to cancel menus.\n";
  122. s += "Send /none to skip menus.\n";
  123. s += "Send /begin to confirm menus.";
  124. return s;
  125. }
  126. void telegram_handle_message(int message_id) {
  127. if (!sm_is_idle()) {
  128. debug.println("Telegram: message while machine in use");
  129. if (bot.messages[message_id].text == "/abort") {
  130. sm_bot_abort();
  131. bot.sendMessage(bot.messages[message_id].chat_id, "Aborted current cycle!", "");
  132. } else {
  133. bot.sendMessage(bot.messages[message_id].chat_id, "Machine is already in use.\nPlease try again later.", "");
  134. }
  135. return;
  136. }
  137. if ((bot_state == BOT_IDLE) && (bot_lock == "")) {
  138. bot_lock = bot.messages[message_id].chat_id;
  139. debug.println("Telegram: locked to " + bot_lock);
  140. }
  141. if (bot_lock != bot.messages[message_id].chat_id) {
  142. debug.println("Telegram: bot locked. abort for chat " + bot.messages[message_id].chat_id);
  143. bot.sendMessage(bot.messages[message_id].chat_id, "Bot is already in use.\nPlease try again later.", "");
  144. return;
  145. }
  146. if (bot_state == BOT_IDLE) {
  147. if (bot.messages[message_id].text == "/auto") {
  148. String s = "Please enter fertilizer numbers.\n";
  149. s += "Valid numbers: 1 to " + String(PUMP_COUNT) + "\n";
  150. s += "Send /none to skip.\n";
  151. s += "Send /abort to cancel.";
  152. bot_ferts.clear();
  153. bot_state = BOT_ASKED_FERT;
  154. bot.sendMessage(bot.messages[message_id].chat_id, s, "");
  155. } else if (bot.messages[message_id].text == "/abort") {
  156. bot_lock = "";
  157. bot.sendMessage(bot.messages[message_id].chat_id, "Nothing to abort.", "");
  158. } else {
  159. bot_lock = "";
  160. bot.sendMessage(bot.messages[message_id].chat_id, telegram_help(), "");
  161. }
  162. } else if (bot_state == BOT_ASKED_FERT) {
  163. if (bot.messages[message_id].text == "/abort") {
  164. bot_state = BOT_IDLE;
  165. bot_lock = "";
  166. bot.sendMessage(bot.messages[message_id].chat_id, "Aborted.", "");
  167. return;
  168. } else if (bot.messages[message_id].text != "/none") {
  169. String buff;
  170. for (int i = 0; i < bot.messages[message_id].text.length() + 1; i++) {
  171. if ((i == bot.messages[message_id].text.length()) || (bot.messages[message_id].text[i] == ' ')) {
  172. if (buff.length() > 0) {
  173. int n = buff.toInt() - 1;
  174. buff = "";
  175. bot_ferts.set(n);
  176. }
  177. } else if ((bot.messages[message_id].text[i] >= '0') && (bot.messages[message_id].text[i] <= '9')) {
  178. buff += bot.messages[message_id].text[i];
  179. } else {
  180. bot_state = BOT_IDLE;
  181. bot_lock = "";
  182. bot.sendMessage(bot.messages[message_id].chat_id, "Invalid input.\nAborted.", "");
  183. return;
  184. }
  185. }
  186. }
  187. String s = "Please enter plant numbers.\n";
  188. s += "Valid numbers: 1 to " + String(VALVE_COUNT - 1) + "\n";
  189. s += "Send /abort to cancel.";
  190. bot_plants.clear();
  191. bot_state = BOT_ASKED_PLANTS;
  192. bot.sendMessage(bot.messages[message_id].chat_id, s, "");
  193. } else if (bot_state == BOT_ASKED_PLANTS) {
  194. if (bot.messages[message_id].text == "/abort") {
  195. bot_state = BOT_IDLE;
  196. bot_lock = "";
  197. bot.sendMessage(bot.messages[message_id].chat_id, "Aborted.", "");
  198. return;
  199. }
  200. String buff;
  201. for (int i = 0; i < bot.messages[message_id].text.length() + 1; i++) {
  202. if ((i == bot.messages[message_id].text.length()) || (bot.messages[message_id].text[i] == ' ')) {
  203. if (buff.length() > 0) {
  204. int n = buff.toInt() - 1;
  205. buff = "";
  206. bot_plants.set(n);
  207. }
  208. } else if ((bot.messages[message_id].text[i] >= '0') && (bot.messages[message_id].text[i] <= '9')) {
  209. buff += bot.messages[message_id].text[i];
  210. } else {
  211. bot_state = BOT_IDLE;
  212. bot_lock = "";
  213. bot.sendMessage(bot.messages[message_id].chat_id, "Invalid input.\nAborted.", "");
  214. return;
  215. }
  216. }
  217. if (bot_plants.countSet() <= 0) {
  218. bot_state = BOT_IDLE;
  219. bot_lock = "";
  220. bot.sendMessage(bot.messages[message_id].chat_id, "No plants selected.\nAborted.", "");
  221. return;
  222. }
  223. #ifdef FULLAUTO_MIN_PLANT_COUNT
  224. if (bot_plants.countSet() < FULLAUTO_MIN_PLANT_COUNT) {
  225. bot_state = BOT_IDLE;
  226. bot_lock = "";
  227. bot.sendMessage(bot.messages[message_id].chat_id, "Select at least " + String(FULLAUTO_MIN_PLANT_COUNT) + " plants.\nAborted.", "");
  228. return;
  229. }
  230. #endif
  231. String s = "Input accepted.\nFertilizers:";
  232. for (int i = 0; i < PUMP_COUNT; i++) {
  233. if (bot_ferts.isSet(i)) {
  234. s += " " + String(i + 1);
  235. }
  236. }
  237. s += "\nPlants:";
  238. for (int i = 0; i < (VALVE_COUNT - 1); i++) {
  239. if (bot_plants.isSet(i)) {
  240. s += " " + String(i + 1);
  241. }
  242. }
  243. s += "\nOk? Send /begin to start or /abort to cancel.";
  244. bot_state = BOT_ASKED_CONFIRM;
  245. bot.sendMessage(bot.messages[message_id].chat_id, s, "");
  246. } else if (bot_state == BOT_ASKED_CONFIRM) {
  247. if (bot.messages[message_id].text == "/abort") {
  248. bot_state = BOT_IDLE;
  249. bot_lock = "";
  250. bot.sendMessage(bot.messages[message_id].chat_id, "Aborted.", "");
  251. } else if (bot.messages[message_id].text == "/begin") {
  252. bot_state = BOT_IDLE;
  253. bot_lock = "";
  254. bot.sendMessage(bot.messages[message_id].chat_id, "Auto watering cycle started.", "");
  255. sm_bot_start_auto(bot_ferts, bot_plants);
  256. } else {
  257. bot_state = BOT_IDLE;
  258. bot_lock = "";
  259. bot.sendMessage(bot.messages[message_id].chat_id, "Unknown message.\nAborted.", "");
  260. }
  261. } else {
  262. debug.println("Telegram: invalid state");
  263. bot_state = BOT_IDLE;
  264. bot_lock = "";
  265. bot.sendMessage(bot.messages[message_id].chat_id, "Internal error.\nPlease try again.", "");
  266. }
  267. }
  268. void telegram_handler(int message_id) {
  269. debug.println("Telegram: rx " + bot.messages[message_id].chat_id + " \"" + bot.messages[message_id].text + "\"");
  270. bool found = false;
  271. for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
  272. if (trusted_chat_ids[n] == bot.messages[message_id].chat_id) {
  273. found = true;
  274. break;
  275. }
  276. }
  277. if (!found) {
  278. bot.sendMessage(bot.messages[message_id].chat_id, "Sorry, not authorized!", "");
  279. return;
  280. }
  281. telegram_handle_message(message_id);
  282. }
  283. void telegram_poll() {
  284. #ifdef TELEGRAM_LOG_TIMINGS
  285. unsigned long start = millis();
  286. #endif // TELEGRAM_LOG_TIMINGS
  287. while (int count = bot.getUpdates(bot.last_message_received + 1)) {
  288. for (int i = 0; i < count; i++) {
  289. telegram_handler(i);
  290. }
  291. }
  292. #ifdef TELEGRAM_LOG_TIMINGS
  293. unsigned long end = millis();
  294. debug.println("Telegram: took " + String(end - start) + "ms");
  295. #endif // TELEGRAM_LOG_TIMINGS
  296. }
  297. void telegram_hello() {
  298. for (int n = 0; n < (sizeof(trusted_chat_ids) / sizeof(trusted_chat_ids[0])); n++) {
  299. bot.sendMessage(trusted_chat_ids[n], "Giess-o-mat v" FIRMWARE_VERSION " initialized.\nSend /auto to begin.", "");
  300. }
  301. }
  302. #endif // TELEGRAM_TOKEN
  303. bool wifi_write_database(int duration, const char *type, int id) {
  304. bool success = false;
  305. #ifdef ENABLE_INFLUXDB_LOGGING
  306. // we still want to be locally usable / have a snappy ui
  307. // even when the wifi connection is broken.
  308. if (WiFi.status() != WL_CONNECTED) {
  309. debug.println("Won't attempt db write, no WiFi connection.");
  310. return success;
  311. }
  312. InfluxData measurement(type);
  313. measurement.addTag("version", FIRMWARE_VERSION);
  314. measurement.addTag("device", WiFi.macAddress());
  315. measurement.addTag("id", String(id));
  316. measurement.addValue("duration", duration);
  317. success = influx.write(measurement);
  318. #endif // ENABLE_INFLUXDB_LOGGING
  319. if (!success) {
  320. debug.print("Error writing to InfluxDB ");
  321. debug.print(INFLUXDB_HOST);
  322. debug.print(":");
  323. debug.print(INFLUXDB_PORT);
  324. debug.print("/");
  325. debug.print(INFLUXDB_DATABASE);
  326. debug.print("/");
  327. debug.println(type);
  328. }
  329. return success;
  330. }
  331. void wifi_set_message_buffer(String a, String b, String c, String d) {
  332. message_buffer_a = a;
  333. message_buffer_b = b;
  334. message_buffer_c = c;
  335. message_buffer_d = d;
  336. }
  337. void wifi_schedule_websocket(void) {
  338. last_websocket_update_time = 0;
  339. }
  340. void wifi_send_status_broadcast(void) {
  341. if (WiFi.status() != WL_CONNECTED) {
  342. return;
  343. }
  344. if (socket.connectedClients() <= 0) {
  345. return;
  346. }
  347. String a = message_buffer_a ;
  348. String b = message_buffer_b;
  349. String c = message_buffer_c;
  350. String d = message_buffer_d;
  351. a.replace("\"", "'");
  352. b.replace("\"", "'");
  353. c.replace("\"", "'");
  354. d.replace("\"", "'");
  355. String ws = "{\n";
  356. ws += "\"a\": \"" + a + "\",\n";
  357. ws += "\"b\": \"" + b + "\",\n";
  358. ws += "\"c\": \"" + c + "\",\n";
  359. ws += "\"d\": \"" + d + "\",\n";
  360. ws += "\"state\": \"" + String(control_state_name()) + "\",\n";
  361. ws += F("\"valves\": [ ");
  362. for (int i = 0; i < VALVE_COUNT; i++) {
  363. ws += "\"";
  364. ws += get_plants()->getValves()->getPin(i) ? "1" : "0";
  365. ws += "\"";
  366. if (i < (VALVE_COUNT - 1)) {
  367. ws += ", ";
  368. }
  369. }
  370. ws += " ],\n";
  371. ws += F("\"pumps\": [ ");
  372. for (int i = 0; i < PUMP_COUNT; i++) {
  373. ws += "\"";
  374. ws += get_plants()->getPumps()->getPin(i) ? "1" : "0";
  375. ws += "\"";
  376. if (i < (PUMP_COUNT - 1)) {
  377. ws += ", ";
  378. }
  379. }
  380. ws += " ],\n";
  381. ws += F("\"switches\": [ ");
  382. for (int i = 0; i < SWITCH_COUNT; i++) {
  383. bool v = get_plants()->getSwitches()->getPin(i);
  384. #ifdef INVERT_SENSOR_BOTTOM
  385. if (i == 0) {
  386. v = !v;
  387. }
  388. #endif // INVERT_SENSOR_BOTTOM
  389. #ifdef INVERT_SENSOR_TOP
  390. if (i == 1) {
  391. v = !v;
  392. }
  393. #endif // INVERT_SENSOR_TOP
  394. ws += "\"";
  395. ws += v ? "1" : "0";
  396. ws += "\"";
  397. if (i < (SWITCH_COUNT - 1)) {
  398. ws += ", ";
  399. }
  400. }
  401. ws += " ],\n";
  402. ws += F("\"aux\": [ ");
  403. for (int i = 0; i < AUX_COUNT; i++) {
  404. ws += "\"";
  405. ws += get_plants()->getAux()->getPin(i) ? "1" : "0";
  406. ws += "\"";
  407. if (i < (AUX_COUNT - 1)) {
  408. ws += ", ";
  409. }
  410. }
  411. ws += " ],\n";
  412. ws += F("\"kickstart\": [ ");
  413. for (int i = 0; i < VALVE_COUNT - 1; i++) {
  414. ws += "\"";
  415. ws += get_plants()->getKickstart()->getPin(i) ? "1" : "0";
  416. ws += "\"";
  417. if (i < (VALVE_COUNT - 2)) {
  418. ws += ", ";
  419. }
  420. }
  421. ws += " ],\n";
  422. ws += "\"switchstate\": \"";
  423. Plants::Waterlevel wl = get_plants()->getWaterlevel();
  424. if (wl == Plants::empty) {
  425. ws += F("tank empty");
  426. } else if (wl == Plants::inbetween) {
  427. ws += F("tank half-filled");
  428. } else if (wl == Plants::full) {
  429. ws += F("tank full");
  430. } else {
  431. ws += F("invalid sensor state");
  432. }
  433. ws += "\"\n";
  434. ws += "}";
  435. wifi_send_websocket(ws);
  436. }
  437. void wifi_send_websocket(String s) {
  438. socket.broadcastTXT(s);
  439. }
  440. void handleRoot() {
  441. String message = F("<!DOCTYPE html>\n");
  442. message += F("<html><head>\n");
  443. message += F("<meta charset='utf-8'/>\n");
  444. message += F("<meta name='viewport' content='width=device-width, initial-scale=1'/>\n");
  445. message += F("<title>Gieß-o-mat</title>\n");
  446. message += F("<style type='text/css'>\n");
  447. message += F(".head {\n");
  448. message += F("text-align: center;\n");
  449. message += F("}\n");
  450. message += F(".container {\n");
  451. message += F("display: flex;\n");
  452. message += F("max-width: 1200px;\n");
  453. message += F("margin: auto;\n");
  454. message += F("}\n");
  455. message += F(".ui {\n");
  456. message += F("width: max-content;\n");
  457. message += F("height: max-content;\n");
  458. message += F("margin-right: 1em;\n");
  459. message += F("padding: 0 1.0em;\n");
  460. message += F("border: 1px dashed black;\n");
  461. message += F("}\n");
  462. message += F(".io {\n");
  463. message += F("width: max-content;\n");
  464. message += F("height: max-content;\n");
  465. message += F("margin-right: 1em;\n");
  466. message += F("padding: 0.8em 1.0em;\n");
  467. message += F("border: 1px dashed black;\n");
  468. message += F("font-family: monospace;\n");
  469. message += F("}\n");
  470. message += F(".ioelem {\n");
  471. message += F("width: max-content;\n");
  472. message += F("border: 1px solid black;\n");
  473. message += F("border-radius: 50%;\n");
  474. message += F("padding: 1em;\n");
  475. message += F("margin: 0.5em;\n");
  476. message += F("}\n");
  477. message += F(".info {\n");
  478. message += F("width: max-content;\n");
  479. message += F("height: max-content;\n");
  480. message += F("padding: 0 1.0em;\n");
  481. message += F("border: 1px dashed black;\n");
  482. message += F("font-family: monospace;\n");
  483. message += F("}\n");
  484. message += F(".log {\n");
  485. message += F("max-height: 300px;\n");
  486. message += F("padding: 0 1.0em;\n");
  487. message += F("max-width: 1200px;\n");
  488. message += F("margin: auto;\n");
  489. message += F("margin-top: 1.5em;\n");
  490. message += F("border: 1px dashed black;\n");
  491. message += F("font-family: monospace;\n");
  492. message += F("overflow-y: scroll;\n");
  493. message += F("word-break: break-all;\n");
  494. message += F("}\n");
  495. message += F("#logbuf {\n");
  496. message += F("white-space: break-spaces;\n");
  497. message += F("}\n");
  498. message += F(".pad {\n");
  499. message += F("background: black;\n");
  500. message += F("border: 3px solid black;\n");
  501. message += F("border-radius: 20px;\n");
  502. message += F("width: max-content;\n");
  503. message += F("padding: 1.5em;\n");
  504. message += F("margin-left: auto;\n");
  505. message += F("margin-right: auto;\n");
  506. message += F("}\n");
  507. message += F(".pad input {\n");
  508. message += F("background: #fff0cf;\n");
  509. message += F("border-radius: 6px;\n");
  510. message += F("font-weight: bold;\n");
  511. message += F("font-family: monospace;\n");
  512. message += F("font-size: 1.2em;\n");
  513. message += F("padding: 0.5em 1em;\n");
  514. message += F("margin: 0.5em;\n");
  515. message += F("}\n");
  516. // https://codepen.io/hawkz/pres/RpPaGK
  517. message += F(".lcd {\n");
  518. //message += F("background: #9ea18c;\n");
  519. message += F("background: #9ed18c;\n");
  520. message += F("border: 5px solid black;\n");
  521. message += F("border-radius: 10px;\n");
  522. message += F("width: max-content;\n");
  523. message += F("padding: 0.65em 1em;\n");
  524. message += F("box-shadow: inset 0 0 5px 5px rgba(0,0,0,.1);\n");
  525. message += F("font-weight: bold;\n");
  526. message += F("font-family: monospace;\n");
  527. message += F("letter-spacing: 0.1em;\n");
  528. message += F("font-size: 1.2em;\n");
  529. message += F("line-height: 160%;\n");
  530. message += F("color: #21230e;\n");
  531. message += F("text-shadow: -1px 2px 1px rgba(0,0,0,.1);\n");
  532. message += F("margin-left: auto;\n");
  533. message += F("margin-right: auto;\n");
  534. message += F("}\n");
  535. message += F("#state {\n");
  536. message += F("text-align: center;\n");
  537. message += F("}\n");
  538. message += F("@media (prefers-color-scheme: dark) {\n");
  539. message += F("body {\n");
  540. message += F("background-color: black;\n");
  541. message += F("color: white;\n");
  542. message += F("}\n");
  543. message += F(".ui {\n");
  544. message += F("border: 1px dashed white;\n");
  545. message += F("}\n");
  546. message += F(".io {\n");
  547. message += F("border: 1px dashed white;\n");
  548. message += F("}\n");
  549. message += F(".ioelem {\n");
  550. message += F("border: 1px solid white;\n");
  551. message += F("}\n");
  552. message += F(".info {\n");
  553. message += F("border: 1px dashed white;\n");
  554. message += F("}\n");
  555. message += F(".log {\n");
  556. message += F("border: 1px dashed white;\n");
  557. message += F("}\n");
  558. message += F(".pad {\n");
  559. message += F("background: #222222;\n");
  560. message += F("border: 3px solid white;\n");
  561. message += F("}\n");
  562. message += F(".lcd {\n");
  563. message += F("border: 5px solid white;\n");
  564. message += F("}\n");
  565. message += F("}\n");
  566. message += F("</style>\n");
  567. message += F("</head><body>\n");
  568. message += F("<h1 class='head'>Gieß-o-mat</h1>\n");
  569. message += F("<div class='container'>\n");
  570. message += F("<div class='ui'>\n");
  571. message += F("<pre class='lcd'>\n");
  572. message += message_buffer_a + '\n';
  573. message += message_buffer_b + '\n';
  574. message += message_buffer_c + '\n';
  575. message += message_buffer_d + '\n';
  576. message += F("</pre>\n");
  577. message += F("<form class='pad'>\n");
  578. message += F("<input type='button' value='1'>");
  579. message += F("<input type='button' value='2'>");
  580. message += F("<input type='button' value='3'>");
  581. message += F("<br>\n");
  582. message += F("<input type='button' value='4'>");
  583. message += F("<input type='button' value='5'>");
  584. message += F("<input type='button' value='6'>");
  585. message += F("<br>\n");
  586. message += F("<input type='button' value='7'>");
  587. message += F("<input type='button' value='8'>");
  588. message += F("<input type='button' value='9'>");
  589. message += F("<br>\n");
  590. message += F("<input type='button' value='*'>");
  591. message += F("<input type='button' value='0'>");
  592. message += F("<input type='button' value='#'>");
  593. message += F("</form>\n");
  594. message += F("<p id='state'>\n");
  595. message += F("State: ");
  596. message += control_state_name();
  597. message += F("</p></div>\n");
  598. message += F("<div class='io'>\n");
  599. message += F("Switches: <span id='switchstate'>");
  600. Plants::Waterlevel wl = get_plants()->getWaterlevel();
  601. if (wl == Plants::empty) {
  602. message += F("tank empty");
  603. } else if (wl == Plants::inbetween) {
  604. message += F("tank half-filled");
  605. } else if (wl == Plants::full) {
  606. message += F("tank full");
  607. } else {
  608. message += F("invalid sensor state");
  609. }
  610. message += F("</span>");
  611. message += F("<div class='container'>\n");
  612. for (int i = 0; i < SWITCH_COUNT; i++) {
  613. message += F("<div class='ioelem switch' style='background-color: ");
  614. bool v = get_plants()->getSwitches()->getPin(i);
  615. #ifdef INVERT_SENSOR_BOTTOM
  616. if (i == 0) {
  617. v = !v;
  618. }
  619. #endif // INVERT_SENSOR_BOTTOM
  620. #ifdef INVERT_SENSOR_TOP
  621. if (i == 1) {
  622. v = !v;
  623. }
  624. #endif // INVERT_SENSOR_TOP
  625. if (v) {
  626. message += F("red");
  627. } else {
  628. message += F("green");
  629. }
  630. message += F(";'>S");
  631. message += String(i + 1);
  632. message += F("</div>");
  633. }
  634. message += F("</div><hr>\n");
  635. message += F("Kickstart:\n");
  636. message += F("<div class='container'>\n");
  637. for (int i = 0; i < VALVE_COUNT - 1; i++) {
  638. message += F("<div class='ioelem kickstart' style='background-color: ");
  639. if (get_plants()->getKickstart()->getPin(i)) {
  640. message += F("red");
  641. } else {
  642. message += F("green");
  643. }
  644. message += F(";'>A");
  645. message += String(i + 1);
  646. message += F("</div>");
  647. }
  648. message += F("</div><hr>\n");
  649. message += F("Valves:\n");
  650. message += F("<div class='container'>\n");
  651. for (int i = 0; i < VALVE_COUNT; i++) {
  652. message += F("<div class='ioelem valve' style='background-color: ");
  653. if (get_plants()->getValves()->getPin(i)) {
  654. message += F("red");
  655. } else {
  656. message += F("green");
  657. }
  658. message += F(";'>V");
  659. message += String(i + 1);
  660. message += F("</div>");
  661. }
  662. message += F("</div><hr>\n");
  663. message += F("Pumps:\n");
  664. message += F("<div class='container'>\n");
  665. for (int i = 0; i < PUMP_COUNT; i++) {
  666. message += F("<div class='ioelem pump' style='background-color: ");
  667. if (get_plants()->getPumps()->getPin(i)) {
  668. message += F("red");
  669. } else {
  670. message += F("green");
  671. }
  672. message += F(";'>P");
  673. message += String(i + 1);
  674. message += F("</div>");
  675. }
  676. message += F("</div><hr>\n");
  677. message += F("Aux:\n");
  678. message += F("<div class='container'>\n");
  679. for (int i = 0; i < AUX_COUNT; i++) {
  680. message += F("<div class='ioelem aux' style='background-color: ");
  681. if (get_plants()->getAux()->getPin(i)) {
  682. message += F("red");
  683. } else {
  684. message += F("green");
  685. }
  686. message += F(";'>A");
  687. message += String(i + 1);
  688. message += F("</div>");
  689. }
  690. message += F("</div><hr>\n");
  691. message += F("Green means valve is closed / pump is off / switch is not submersed.\n");
  692. message += F("<br>\n");
  693. message += F("Red means valve is open / pump is running / switch is submersed.</div>\n");
  694. message += F("<div class='info'><p>\n");
  695. message += F("Version: ");
  696. message += FIRMWARE_VERSION;
  697. message += F("\n<br>\n");
  698. message += F("Build Date: ");
  699. message += __DATE__;
  700. message += F("\n<br>\n");
  701. message += F("Build Time: ");
  702. message += __TIME__;
  703. message += F("\n</p><p>\n");
  704. message += F("MAC: ");
  705. message += WiFi.macAddress();
  706. message += F("\n<br>\n");
  707. message += F("IPv4: ");
  708. message += WiFi.localIP().toString();
  709. message += F("\n</p>\n");
  710. #if defined(ARDUINO_ARCH_ESP8266)
  711. message += F("\n<p>\n");
  712. message += F("Reset reason: ");
  713. message += ESP.getResetReason();
  714. message += F("\n<br>\n");
  715. message += F("Free heap: ");
  716. message += String(ESP.getFreeHeap());
  717. message += F(" (");
  718. message += String(ESP.getHeapFragmentation());
  719. message += F("% fragmentation)");
  720. message += F("\n<br>\n");
  721. message += F("Free sketch space: ");
  722. message += String(ESP.getFreeSketchSpace());
  723. message += F("\n<br>\n");
  724. message += F("Flash chip real size: ");
  725. message += String(ESP.getFlashChipRealSize());
  726. if (ESP.getFlashChipSize() != ESP.getFlashChipRealSize()) {
  727. message += F("\n<br>\n");
  728. message += F("WARNING: sdk chip size (");
  729. message += (ESP.getFlashChipSize());
  730. message += F(") does not match!");
  731. }
  732. message += F("\n</p>\n");
  733. #elif defined(ARDUINO_ARCH_ESP32)
  734. message += F("\n<p>\n");
  735. message += F("Free heap: ");
  736. message += String(ESP.getFreeHeap() / 1024.0);
  737. message += F("k\n<br>\n");
  738. message += F("Free sketch space: ");
  739. message += String(ESP.getFreeSketchSpace() / 1024.0);
  740. message += F("k\n<br>\n");
  741. message += F("Flash chip size: ");
  742. message += String(ESP.getFlashChipSize() / 1024.0);
  743. message += F("k\n</p>\n");
  744. #endif
  745. message += F("<p>\n");
  746. #ifdef TELEGRAM_TOKEN
  747. message += F("Telegram: ");
  748. message += TELEGRAM_UPDATE_INTERVAL_SLOW;
  749. message += F("ms / ");
  750. message += TELEGRAM_UPDATE_INTERVAL_FAST;
  751. message += F("ms\n");
  752. #else
  753. message += F("Telegram bot not enabled!\n");
  754. #endif
  755. message += F("</p>\n");
  756. message += F("<p>\n");
  757. #ifdef ENABLE_INFLUXDB_LOGGING
  758. message += F("InfluxDB: ");
  759. message += INFLUXDB_DATABASE;
  760. message += F(" @ ");
  761. message += INFLUXDB_HOST;
  762. message += F(":");
  763. message += String(INFLUXDB_PORT);
  764. message += F("\n");
  765. #else
  766. message += F("InfluxDB logging not enabled!\n");
  767. #endif
  768. message += F("</p>\n");
  769. message += F("<p>Try <a href='/update'>/update</a> for OTA firmware updates!</p>\n");
  770. message += F("<p>Made by <a href='https://xythobuz.de'>xythobuz</a></p>\n");
  771. message += F("<p><a href='https://git.xythobuz.de/thomas/giess-o-mat'>Project Repository</a></p>\n");
  772. #ifdef ENABLE_GPIO_TEST
  773. message += F("<p><a href='/gpiotest'>GPIO Test</a></p>\n");
  774. #endif // ENABLE_GPIO_TEST
  775. message += F("</div></div>\n");
  776. message += F("<div class='log'><pre id='logbuf'>\n");
  777. message += debug.getBuffer();
  778. message += F("</pre></div>\n");
  779. message += F("</body>\n");
  780. message += F("<script type='text/javascript'>\n");
  781. message += F("var socket = new WebSocket('ws://' + window.location.hostname + ':81');\n");
  782. message += F("socket.onmessage = function(e) {\n");
  783. message += F( "if (e.data.startsWith('log:')) {\n");
  784. message += F( "var log = document.getElementById('logbuf');\n");
  785. message += F( "var div = document.getElementsByClassName('log')[0];\n");
  786. message += F( "log.innerHTML += e.data.substring(4);\n");
  787. message += F( "if (log.innerHTML.length > (1024 * 1024)) {\n");
  788. message += F( "log.innerHTML = log.innerHTML.substring(1024 * 1024);\n");
  789. message += F( "}\n");
  790. message += F( "div.scrollTop = div.scrollHeight;\n");
  791. message += F( "return;\n");
  792. message += F( "}\n");
  793. message += F( "var msg = JSON.parse(e.data);\n");
  794. message += F( "var str = msg.a + '\\n' + msg.b + '\\n' + msg.c + '\\n' + msg.d;\n");
  795. //message += F( "console.log(str);\n");
  796. message += F( "var lcd = document.getElementsByClassName('lcd');\n");
  797. message += F( "lcd[0].innerHTML = str;\n");
  798. message += F( "var state = document.getElementById('state');\n");
  799. message += F( "state.innerHTML = \"State: \" + msg.state;\n");
  800. message += F( "for (let i = 0; i < ");
  801. message += String(VALVE_COUNT);
  802. message += F("; i++) {\n");
  803. message += F( "var valves = document.getElementsByClassName('valve');\n");
  804. message += F( "if (msg.valves[i] == '0') {\n");
  805. message += F( "valves[i].style = 'background-color: green;';\n");
  806. message += F( "} else {\n");
  807. message += F( "valves[i].style = 'background-color: red;';\n");
  808. message += F( "}\n");
  809. message += F( "}\n");
  810. message += F( "for (let i = 0; i < ");
  811. message += String(PUMP_COUNT);
  812. message += F("; i++) {\n");
  813. message += F( "var pumps = document.getElementsByClassName('pump');\n");
  814. message += F( "if (msg.pumps[i] == '0') {\n");
  815. message += F( "pumps[i].style = 'background-color: green;';\n");
  816. message += F( "} else {\n");
  817. message += F( "pumps[i].style = 'background-color: red;';\n");
  818. message += F( "}\n");
  819. message += F( "}\n");
  820. message += F( "for (let i = 0; i < ");
  821. message += String(SWITCH_COUNT);
  822. message += F("; i++) {\n");
  823. message += F( "var switches = document.getElementsByClassName('switch');\n");
  824. message += F( "if (msg.switches[i] == '0') {\n");
  825. message += F( "switches[i].style = 'background-color: green;';\n");
  826. message += F( "} else {\n");
  827. message += F( "switches[i].style = 'background-color: red;';\n");
  828. message += F( "}\n");
  829. message += F( "}\n");
  830. message += F( "for (let i = 0; i < ");
  831. message += String(AUX_COUNT);
  832. message += F("; i++) {\n");
  833. message += F( "var aux = document.getElementsByClassName('aux');\n");
  834. message += F( "if (msg.aux[i] == '0') {\n");
  835. message += F( "aux[i].style = 'background-color: green;';\n");
  836. message += F( "} else {\n");
  837. message += F( "aux[i].style = 'background-color: red;';\n");
  838. message += F( "}\n");
  839. message += F( "}\n");
  840. message += F( "for (let i = 0; i < ");
  841. message += String(VALVE_COUNT - 1);
  842. message += F("; i++) {\n");
  843. message += F( "var kickstart = document.getElementsByClassName('kickstart');\n");
  844. message += F( "if (msg.kickstart[i] == '0') {\n");
  845. message += F( "kickstart[i].style = 'background-color: green;';\n");
  846. message += F( "} else {\n");
  847. message += F( "kickstart[i].style = 'background-color: red;';\n");
  848. message += F( "}\n");
  849. message += F( "}\n");
  850. message += F( "var switchstate = document.getElementById('switchstate');\n");
  851. message += F( "switchstate.innerHTML = msg.switchstate;\n");
  852. message += F("};\n");
  853. message += F("var hist = document.getElementsByClassName('log')[0];\n");
  854. message += F("hist.scrollTop = hist.scrollHeight;\n");
  855. message += F("var buttons = document.getElementsByTagName('input');\n");
  856. message += F("for (let i = 0; i < buttons.length; i++) {\n");
  857. message += F( "buttons[i].addEventListener('click', updateButton);\n");
  858. message += F("}\n");
  859. message += F("function updateButton() {\n");
  860. message += F( "socket.send(this.value);\n");
  861. message += F("}\n");
  862. message += F("</script>\n");
  863. message += F("</html>\n");
  864. server.send(200, "text/html", message);
  865. }
  866. void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length) {
  867. if ((type != WStype_TEXT) || (length != 1)) {
  868. debug.println("Websocket: invalid type=" + String(type) + " len=" + String(length) + " data=" + String((char *)payload));
  869. return;
  870. }
  871. char c = payload[0];
  872. if ((c >= '0') && (c <= '9')) {
  873. control_act_input(c - '0');
  874. } else if (c == '*') {
  875. control_act_input(-1);
  876. } else if (c == '#') {
  877. control_act_input(-2);
  878. }
  879. }
  880. void wifi_setup() {
  881. // Build hostname string
  882. String hostname = "giess-o-mat";
  883. int ws = 0, connect_attempts = 0;
  884. #if defined(ARDUINO_ARCH_ESP8266)
  885. // Connect to WiFi AP
  886. debug.println("WiFi: initializing");
  887. WiFi.hostname(hostname);
  888. WiFi.mode(WIFI_STA);
  889. debug.print("WiFi: connecting");
  890. WiFi.begin(WIFI_SSID, WIFI_PW);
  891. #ifdef TELEGRAM_TOKEN
  892. secured_client.setTrustAnchors(&cert);
  893. #endif // TELEGRAM_TOKEN
  894. while (((ws = WiFi.status()) != WL_CONNECTED) && (connect_attempts < MAX_WIFI_CONNECT_ATTEMPTS)) {
  895. connect_attempts++;
  896. debug.print(String(" ") + String(ws));
  897. delay(LED_CONNECT_BLINK_INTERVAL);
  898. digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
  899. }
  900. debug.println();
  901. debug.println(String("WiFi: status=") + String(WiFi.status()));
  902. #elif defined(ARDUINO_ARCH_ESP32)
  903. // Set hostname workaround
  904. debug.println("WiFi: set hostname");
  905. WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE);
  906. WiFi.setHostname(hostname.c_str());
  907. // Workaround for WiFi connecting only every 2nd reset
  908. // https://github.com/espressif/arduino-esp32/issues/2501#issuecomment-513602522
  909. debug.println("WiFi: connection work-around");
  910. WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
  911. if (info.disconnected.reason == 202) {
  912. esp_sleep_enable_timer_wakeup(10);
  913. esp_deep_sleep_start();
  914. delay(100);
  915. }
  916. }, WiFiEvent_t::SYSTEM_EVENT_STA_DISCONNECTED);
  917. // Connect to WiFi AP
  918. debug.println("WiFi: SSID=" WIFI_SSID);
  919. debug.print("WiFi: connecting");
  920. WiFi.mode(WIFI_STA);
  921. WiFi.begin(WIFI_SSID, WIFI_PW);
  922. #ifdef TELEGRAM_TOKEN
  923. secured_client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
  924. #endif // TELEGRAM_TOKEN
  925. while (((ws = WiFi.status()) != WL_CONNECTED) && (connect_attempts < MAX_WIFI_CONNECT_ATTEMPTS)) {
  926. connect_attempts++;
  927. debug.print(String(" ") + String(ws));
  928. delay(LED_CONNECT_BLINK_INTERVAL);
  929. digitalWrite(BUILTIN_LED_PIN, !digitalRead(BUILTIN_LED_PIN));
  930. }
  931. debug.println();
  932. debug.println(String("WiFi: status=") + String(WiFi.status()));
  933. // Set hostname workaround
  934. debug.println("WiFi: set hostname work-around");
  935. WiFi.setHostname(hostname.c_str());
  936. #endif
  937. if ((connect_attempts >= MAX_WIFI_CONNECT_ATTEMPTS)
  938. || (WiFi.status() != WL_CONNECTED)) {
  939. debug.println("WiFi: init failed!");
  940. wifi_ok = 0;
  941. return;
  942. }
  943. wifi_ok = 1;
  944. debug.print("WiFi: got IPv4: ");
  945. debug.println(WiFi.localIP().toString());
  946. #ifdef ENABLE_INFLUXDB_LOGGING
  947. // Setup InfluxDB Client
  948. debug.println("WiFi: set InfluxDB database");
  949. influx.setDb(INFLUXDB_DATABASE);
  950. #endif // ENABLE_INFLUXDB_LOGGING
  951. // Setup HTTP Server
  952. debug.println("WiFi: initializing HTTP server");
  953. MDNS.begin(hostname.c_str());
  954. updater.setup(&server);
  955. server.on("/", handleRoot);
  956. #ifdef ENABLE_GPIO_TEST
  957. server.on("/gpiotest", handleGpioTest);
  958. #endif // ENABLE_GPIO_TEST
  959. #ifdef TELEGRAM_TOKEN
  960. debug.print("WiFi: getting NTP time");
  961. configTime(0, 0, "pool.ntp.org");
  962. time_t now = time(nullptr);
  963. while (now < 24 * 60 * 60) {
  964. debug.print(".");
  965. delay(100);
  966. now = time(nullptr);
  967. }
  968. debug.println(" done!");
  969. debug.println("WiFi: time is " + String(now));
  970. debug.println("WiFi: initializing Telegram");
  971. const String commands = F("["
  972. "{\"command\":\"auto\", \"description\":\"Start automatic watering cycle\"},"
  973. "{\"command\":\"confirm\", \"description\":\"Proceed with any menu inputs\"},"
  974. "{\"command\":\"none\", \"description\":\"Proceed without menu input\"},"
  975. "{\"command\":\"abort\", \"description\":\"Cancel any menu inputs\"}"
  976. "]");
  977. bot.setMyCommands(commands);
  978. telegram_hello();
  979. #endif // TELEGRAM_TOKEN
  980. server.begin();
  981. MDNS.addService("http", "tcp", 80);
  982. MDNS.addService("http", "tcp", 81);
  983. socket.begin();
  984. socket.onEvent(webSocketEvent);
  985. debug.println("WiFi: setup done");
  986. }
  987. void wifi_run() {
  988. // reset ESP every 6h to be safe
  989. if ((millis() >= (6UL * 60UL * 60UL * 1000UL)) && (sm_is_idle())) {
  990. ESP.restart();
  991. }
  992. if (!wifi_ok) {
  993. // nothing to handle
  994. return;
  995. }
  996. if ((millis() - last_server_handle_time) >= SERVER_HANDLE_INTERVAL) {
  997. last_server_handle_time = millis();
  998. server.handleClient();
  999. socket.loop();
  1000. #ifdef ARDUINO_ARCH_ESP8266
  1001. MDNS.update();
  1002. #endif // ARDUINO_ARCH_ESP8266
  1003. }
  1004. if ((millis() - last_websocket_update_time) >= WEBSOCKET_UPDATE_INTERVAL) {
  1005. last_websocket_update_time = millis();
  1006. wifi_send_status_broadcast();
  1007. }
  1008. #ifdef ENABLE_GPIO_TEST
  1009. if (runningGpioTest && ((millis() - lastGpioTime) >= GPIO_TEST_INTERVAL)) {
  1010. gpioTestState = !gpioTestState;
  1011. runGpioTest(gpioTestState);
  1012. }
  1013. #endif // ENABLE_GPIO_TEST
  1014. #ifdef TELEGRAM_TOKEN
  1015. if ((millis() - last_telegram_time) >= telegram_update_interval()) {
  1016. telegram_poll();
  1017. last_telegram_time = millis();
  1018. }
  1019. #endif // TELEGRAM_TOKEN
  1020. }
  1021. #endif // PLATFORM_ESP