diff --git a/.vscode/settings.json b/.vscode/settings.json index db234a4..fc183d7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,6 +14,7 @@ "unordered_map": "cpp", "vector": "cpp", "initializer_list": "cpp", - "unordered_set": "cpp" + "unordered_set": "cpp", + "*.cpp___": "cpp" } } \ No newline at end of file diff --git a/README.md b/README.md index 628234c..1167225 100644 --- a/README.md +++ b/README.md @@ -120,30 +120,45 @@ Maybe I can support ST7789 on ESP8266. but not in TODO. EnvBoyX has http API. -| METHOD | ENDPOINT | RETURN | description | -| ------ | ------------- | -------------------------- | -| GET | / | JSON | sensor value as JSON.| -| GET | /ping | TEXT | returns pong. | -| GET | /stastics | JSON | stastics JSON | -| GET | /brightness?value= | TEXT | set display brightness (0-255) 0 means OFF | -| GET | /display?value=<1 or 0> | TEXT | set display power (1 = ON / 0 = OFF) | -| POST | /goto_setup | TEXT | Go to setup mode at next boot | +| minVer | METHOD | ENDPOINT | RETURN | description | +| ------| ------ | ------------- | -------------------------- | -------| +| 2.0 | GET | / | JSON | sensor value as JSON.| +| 2.0 | GET | /ping | TEXT | returns pong. | +| 39.0 | GET | /stastics | JSON | stastics JSON | +| 3.4 | GET | /brightness?value= | TEXT | set display brightness (0-255) 0 means OFF | +| 3.4 | GET | /display?value=<1 or 0> | TEXT | set display power (1 = ON / 0 = OFF) | +| 40.0 | POST | /goto_setup | TEXT | Go to setup mode at next boot | +| 41.0 | POST | /mhz19b/abc | TEXT | value=1 ON value=0 OFF | +| 41.0 | POST | /mhz19b/zeroCalibration | TEXT | __DANGER__ Use if you know what you are doing | NOTE: There is no reboot API, because of security reason. -#### note +#### cURL examples -* brightness and display power function is NOT WORKING in ST7789 (v3.0) +These are example of calling API -## how to write +##### Simple get API -use esptools.py or PlatformIO IDE. +``` +curl http://[envboy IP or mDNShostname.local]/ +{"product":"EnvBoyX","uptime":"01:18:02","uptimeMills":4682994,"temparature":"28.60","humidity":"35.00","pressure":"976.81","luminous":"16","luminousIr":"2","co2ppm":"-999","co2ppmAccuracy":"","rssi":-12} +``` + +##### GET with parameter API ``` -esptool.py write_flash 0x1000 filename.bin +curl http://[envboy IP or mDNShostname.local]/brightness?value=100` +OK ``` -* Get binary from releases page. +##### POST without parameter API + +``` +$ curl -X POST http://[envboy IP or mDNShostname.local]/goto_setup +OK +``` + +# appendix ## Setups I am using @@ -164,7 +179,7 @@ esptool.py write_flash 0x1000 filename.bin * WeMos D1mini * NodeMCU V3 -## Version History +# Version History * BUGFIX: Bug fix * FIX: Fix not bug, but not friendly behavior @@ -173,13 +188,18 @@ esptool.py write_flash 0x1000 filename.bin * DROP: Delete some functions * NOTE: other things -### v40.1 +## v41.0: MH-Z19B update + +* ADD: API: MH-Z19B Auto Baseline Calibration ON/OFF +* ADD: API: MH-Z19B Zero Calibration + +## v40.1: Bugfix release for v40 * FIX: SSD1306: Missing unit when no alerts * CHANGE: Add minor version * CHANGE: Delete startup first screen -### v40 +## v40: Pressure Delta update * FIX: CO2 ppm alert value is not good. * ADD: Add POST /goto_setup API. @@ -193,14 +213,14 @@ esptool.py write_flash 0x1000 filename.bin * ADD: Pressure delta * CHANGE: ST7789: Normal: Dont show co2 when no co2 sensor. -### v39 +## v39: SH1106 Support release * CHANGE: CONFIG: Add SSD1306 / SH1106 switch * CHANGE: HTTP: ESP32: Stop Async Web server. back to standard webserver to reduce code duplicate #42 * ADD: WiFi RSSI to JSON * FIX: ST7789: T: header align -### v38 +## v38: Small update release * CHANGE: CONFIG: ESP32 now uses SPIFFS instead of LITTLEFS but no format or setup required (remove LITTLEFS to SPIFFS wrapper because of compile error) * CHANGE: SSD1306: Move to U8G2 graphic library @@ -209,7 +229,7 @@ esptool.py write_flash 0x1000 filename.bin * CHANGE: ST7789: Draw wait for reconfigure bar using graphics * BUGFIX: CONFIG: coution 2 High value is not saved. (due to insufficient buffer) -### v37 +## v37: Alert update. * VERSION: 37. next version is v38. * BUGFIX: Alert settings are not saved on ESP32. @@ -217,27 +237,27 @@ esptool.py write_flash 0x1000 filename.bin * CHANGE: Switch to squix78 -> thingpulse (same library) * CONFIG: Shorten JSON keys about alerts(reconfig required) -### v3.6 +## v3.6: Bugfix release. -* LICENSE: EnvBoyX is now under APL 2.0 , Affected to all versions. (license terms are not shown before) +* NOTE: LICENSE: EnvBoyX is now under APL 2.0 , Affected to all versions. (license terms are not shown before) * BUGFIX: TSL2561 can't enabled * CHANGE: Serial speed changed to 74880. (was 115200) * BUGFIX: ping API returns invalid JSON * BUGFIX: Display glitch when bigmode and show lux -### v3.5 +## v3.5 * CHANGE: Config: version 9 (was 8) and using JSON format * ADD: Config: Migration between versions -### v3.4 +## v3.4 * CHANGE: Config: version 8 (was 6) * BUGFIX: SSD1306 not shown in Setup Mode * ADD: Default Brightness setting * ADD: Screen Flip setting -### v3.3 +## v3.3 * BUGFIX: MH-Z19B wrong message * BUGFIX: Wrong uptime on JSON @@ -245,24 +265,24 @@ esptool.py write_flash 0x1000 filename.bin * ADD: Watchdog timer (ESP32 only) * CHANGE: Use TimerCall -### v3.2 +## v3.2 * FIX: Avoid using delay * ADD: I2C scan on startup. * BUGFIX: ESP8266: I2C not working * DROP: ESP8266: ST7789 is not supported (because of Pin config) -### v3.1 +## v3.1 * ADD: vertical display mode(bigger font. ST7789 only) * FIX: Refactoring -### v3.0 +## v3.0 * ADD: ST7789 Support (T-Display) * NOTE: ST7789 is initial support, some screens are simplifyed. -### v2.7: Display item change update +## v2.7: Display item change update * CHANGE: Delete alive indicator "*" after EnvBoyX string. * ADD: alive indicator. EnvBoyX's "X" character now blinks. @@ -270,35 +290,35 @@ esptool.py write_flash 0x1000 filename.bin * ADD: mDNS name display. IP/mDNS display switches 3 sec interval. * NOTE: Abort TFT display implementation. -### v2.6 +## v2.6 * BUGFIX: Fix mDNS not working -### v2.5 +## v2.5 * ADD: /display endpoint. -### v2.4 +## v2.4 * ADD: /brightness endpoint. -### v2.3 +## v2.3 * FIX: Unifing EnvBoyX (ESP8266) and EnvBoyX32 (ESP32) again. -### v2.2 +## v2.2 * missing version due to bug. -### v2.1 +## v2.1 * FIX: Split EnvBoyX (8266) and EnvBoyX32 (ESP32) -### v2.0 +## v2.0 * FIX: Move Arduino IDE to Platform.IO -### before v2.0 +## before v2.0 * https://github.com/yakumo-saki/envboy * https://github.com/yakumo-saki/EnvBoyMQTT diff --git a/cloc.sh b/cloc.sh new file mode 100755 index 0000000..c43fc1e --- /dev/null +++ b/cloc.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cloc --exclude-dir=.pio,.vscode,_release,.github . --by-file-by-lang \ No newline at end of file diff --git a/create_release.sh b/create_release.sh index 3028f1b..43198f9 100755 --- a/create_release.sh +++ b/create_release.sh @@ -44,8 +44,10 @@ cp ${MYDIR}/docs/how_to_write*.md ${RELEASE_DIR} banner "Creating Archive" +rm -f ${MYDIR}/EnvBoyX*.tar.gz + # git ブランチからファイル名判定 -branch=`git branch --contains | cut -b3-` +branch=`git symbolic-ref --short HEAD` if [ $branch = "master" ]; then RELEASE_FILE_PATH=${MYDIR}/EnvBoyX.tar.gz diff --git a/include/http_normal.h b/include/http_normal.h index f12d10d..1bc9853 100644 --- a/include/http_normal.h +++ b/include/http_normal.h @@ -1,16 +1,3 @@ -/* - * http_normal.cpp 非機種依存部分 - */ -String http_normal_not_found_html(); - -String http_normal_data_json(); - -String http_normal_ping_json(); - -/* - * http_normal_board.cpp 機種依存部分 - */ - /** * 初期化 */ diff --git a/include/network/http_api.h b/include/network/http_api.h new file mode 100644 index 0000000..954fb91 --- /dev/null +++ b/include/network/http_api.h @@ -0,0 +1,10 @@ + +#ifdef ESP32 +#include +typedef WebServer HTTPWEBSERVER; +#endif + +#ifdef ESP8266 +#include +typedef ESP8266WebServer HTTPWEBSERVER; +#endif diff --git a/include/network/http_api_base.h b/include/network/http_api_base.h new file mode 100644 index 0000000..11d17bc --- /dev/null +++ b/include/network/http_api_base.h @@ -0,0 +1,3 @@ +#include "network/http_api.h" + +void http_api_base_setup(); \ No newline at end of file diff --git a/include/network/http_api_base_json.h b/include/network/http_api_base_json.h new file mode 100644 index 0000000..ae38513 --- /dev/null +++ b/include/network/http_api_base_json.h @@ -0,0 +1,7 @@ +#include + +String http_normal_not_found_html(); + +String http_normal_data_json(); + +String http_normal_ping_json(); diff --git a/include/network/http_api_config.h b/include/network/http_api_config.h new file mode 100644 index 0000000..6047ba5 --- /dev/null +++ b/include/network/http_api_config.h @@ -0,0 +1,3 @@ +#include "network/http_api.h" + +void http_api_config_setup(); \ No newline at end of file diff --git a/include/network/http_api_display.h b/include/network/http_api_display.h new file mode 100644 index 0000000..f102c7a --- /dev/null +++ b/include/network/http_api_display.h @@ -0,0 +1,3 @@ +#include "network/http_api.h" + +void http_api_display_setup(); \ No newline at end of file diff --git a/include/network/http_api_mhz.h b/include/network/http_api_mhz.h new file mode 100644 index 0000000..2e7ed7c --- /dev/null +++ b/include/network/http_api_mhz.h @@ -0,0 +1,3 @@ +#include "network/http_api.h" + +void http_api_mhz_setup(); \ No newline at end of file diff --git a/include/network/http_api_util.h b/include/network/http_api_util.h new file mode 100644 index 0000000..7af8a66 --- /dev/null +++ b/include/network/http_api_util.h @@ -0,0 +1,3 @@ +#include + +bool parseBooleanString(const String value); \ No newline at end of file diff --git a/include/sensors/mhz19_uart.h b/include/sensors/mhz19_uart.h index 73bbfc7..2fac439 100644 --- a/include/sensors/mhz19_uart.h +++ b/include/sensors/mhz19_uart.h @@ -3,3 +3,21 @@ int mhz_read_data_uart(); void mhz_setup_uart(); + +/** + * Auto Baseline calibration を設定する + * @return 設定に成功したか否か + */ +bool mhz_set_abc(bool onoff); + +/** + * Auto Baseline calibration の状態を取得 + * @return ON or OFF + */ +bool mhz_get_abc(); + +/** + * Zero Calibration (現在のppmを400ppmとみなす) + * 外気で20分動作させたあとに実行する。 + */ +bool mhz_do_zero_calibration(); diff --git a/src/global.cpp b/src/global.cpp index 3a9c814..1b9f1be 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -10,8 +10,8 @@ extern const String product_short = "EBX"; // EnvBoyX extern const String product = "EnvBoyX"; -extern const String ver = "40"; -extern const String minorVer = "1"; +extern const String ver = "41"; +extern const String minorVer = "0"; extern const String ver_long = " Ver." + ver + "." + minorVer; // EnvBoyX Ver.53.0 diff --git a/src/main_normal.cpp b/src/main_normal.cpp index 125e65b..c8a91f7 100644 --- a/src/main_normal.cpp +++ b/src/main_normal.cpp @@ -209,6 +209,6 @@ void loop_normal() { http_loop_normal(); // mainlog("Wait for Next tick."); - + yield(); watchdog_feed(); } diff --git a/src/network/api/http_api_base.cpp b/src/network/api/http_api_base.cpp new file mode 100644 index 0000000..71bba54 --- /dev/null +++ b/src/network/api/http_api_base.cpp @@ -0,0 +1,46 @@ +#include + +#include "config.h" + +#include "global.h" +#include "display/display.h" +#include "network/http_api.h" +#include "network/http_api_base_json.h" + +extern HTTPWEBSERVER server; + +void http_handle_data() { + String message = http_normal_data_json(); + server.send(200, MIME_JSON, message); +} + +void http_handle_ping() { + String message = http_normal_ping_json(); + server.send(200, MIME_JSON, message); +} + +void http_handle_stastics() { + server.send(200, MIME_JSON, stasticsJSON); +} + +void http_handle_goto_setup() { + + remove_configure_flag_file(); + + String message = "OK. Entering setup mode at next boot."; + server.send( 200, MIME_TEXT, message ); +} + +void http_handle_not_found() { + String message = http_normal_not_found_html(); + server.send(404, MIME_HTML, message); +} + +void http_api_base_setup() { + server.on ( "/ping", HTTP_GET, http_handle_ping); + server.on ( "/", HTTP_GET, http_handle_data ); + server.on ( "/stastics", HTTP_GET, http_handle_stastics ); + server.on ( "/goto_setup", HTTP_POST, http_handle_goto_setup ); + + server.onNotFound ( http_handle_not_found ); +} \ No newline at end of file diff --git a/src/network/http_normal.cpp b/src/network/api/http_api_base_json.cpp similarity index 99% rename from src/network/http_normal.cpp rename to src/network/api/http_api_base_json.cpp index 10b993d..d02adf0 100644 --- a/src/network/http_normal.cpp +++ b/src/network/api/http_api_base_json.cpp @@ -64,4 +64,3 @@ String http_normal_ping_json() { httplog(json); return json; } - diff --git a/src/network/api/http_api_config.cpp b/src/network/api/http_api_config.cpp new file mode 100644 index 0000000..3c1753a --- /dev/null +++ b/src/network/api/http_api_config.cpp @@ -0,0 +1,40 @@ +#include + +#include "global.h" +#include "network/http_api.h" +#include "network/http_api_util.h" +#include "sensors/mhz19_uart.h" + +extern HTTPWEBSERVER server; + + +void _get_config() { + if (config.mhz19b != MHZ_USE_UART) { + server.send(500, MIME_TEXT, F("MHZ19B IS DISABLED\n")); + return; + } + + bool abc = mhz_get_abc(); + + if (abc) { + server.send(200, MIME_TEXT, "ON\n"); + } else { + server.send(200, MIME_TEXT, "OFF\n"); + } +} + +void _set_config() { + + bool success = true; + + if (success) { + server.send(200, MIME_TEXT, "OK\n"); + } else { + server.send(200, MIME_TEXT, "FAILED\n"); + } +} + +void http_api_config_setup() { + server.on ( "/config", HTTP_GET, _get_config ); + server.on ( "/config", HTTP_POST, _set_config ); +} \ No newline at end of file diff --git a/src/network/api/http_api_display.cpp b/src/network/api/http_api_display.cpp new file mode 100644 index 0000000..351693a --- /dev/null +++ b/src/network/api/http_api_display.cpp @@ -0,0 +1,32 @@ +#include + +#include "global.h" +#include "display/display.h" +#include "network/http_api.h" + +extern HTTPWEBSERVER server; + +void http_handle_power() { + String power = server.arg("value"); + + if (power == "1") { + disp_set_power(true); + } else { + disp_set_power(false); + } + + String message = "OK"; + server.send( 200, MIME_TEXT, message ); +} + +void http_handle_brightness() { + String value = server.arg("value"); + int brightness = value.toInt(); + String msg = disp_set_brightness(brightness); + server.send(200, MIME_TEXT, "OK\n" + msg); +} + +void http_api_display_setup() { + server.on ( "/brightness", HTTP_GET, http_handle_brightness ); + server.on ( "/display", HTTP_GET, http_handle_power ); +} \ No newline at end of file diff --git a/src/network/api/http_api_mhz.cpp b/src/network/api/http_api_mhz.cpp new file mode 100644 index 0000000..b70cd69 --- /dev/null +++ b/src/network/api/http_api_mhz.cpp @@ -0,0 +1,72 @@ +#include + +#include "global.h" +#include "network/http_api.h" +#include "network/http_api_util.h" +#include "sensors/mhz19_uart.h" + +extern HTTPWEBSERVER server; + + +void _set_mhz_abc() { + if (config.mhz19b != MHZ_USE_UART) { + server.send(500, MIME_TEXT, F("MHZ19B IS DISABLED\n")); + return; + } + + String abc = server.arg("value"); + if (!abc || abc == "") { + server.send(400, MIME_TEXT, F("'value' parameter is missing.\n")); + return; + } + + bool onoff = parseBooleanString(abc); + + bool success = mhz_set_abc(onoff); + + if (success) { + if (onoff) { + server.send( 200, MIME_TEXT, "OK. ABC is enabled. value=" + abc); + } else { + server.send( 200, MIME_TEXT, "OK. ABC is disabled. value=" + abc); + } + } else { + server.send( 500, MIME_TEXT, "Setting failed." ); + } +} + +void _get_mhz_abc() { + if (config.mhz19b != MHZ_USE_UART) { + server.send(500, MIME_TEXT, F("MHZ19B IS DISABLED\n")); + return; + } + + bool abc = mhz_get_abc(); + + if (abc) { + server.send(200, MIME_TEXT, "ON\n"); + } else { + server.send(200, MIME_TEXT, "OFF\n"); + } +} + +void _mhz_zero_calibration() { + if (config.mhz19b != MHZ_USE_UART) { + server.send(500, MIME_TEXT, F("MHZ19B IS DISABLED\n")); + return; + } + + bool success = mhz_do_zero_calibration(); + + if (success) { + server.send(200, MIME_TEXT, "OK\n"); + } else { + server.send(200, MIME_TEXT, "FAILED\n"); + } +} + +void http_api_mhz_setup() { + server.on ( "/mhz19b/abc", HTTP_GET, _get_mhz_abc ); + server.on ( "/mhz19b/abc", HTTP_POST, _set_mhz_abc ); + server.on ( "/mhz19b/zeroCalibration", HTTP_POST, _mhz_zero_calibration ); +} \ No newline at end of file diff --git a/src/network/api/http_api_util.cpp b/src/network/api/http_api_util.cpp new file mode 100644 index 0000000..e890563 --- /dev/null +++ b/src/network/api/http_api_util.cpp @@ -0,0 +1,22 @@ +#include + +bool parseBooleanString(const String val) { + + // String is null or invalid + if (!val) return false; + + String v = String(val); + v.toUpperCase(); + + if (v == "TRUE" ) return true; + if (v == "1") return true; + if (v == "ON") return true; + if (v == "YES") return true; + + if (v == "FALSE" ) return false; + if (v == "0") return false; + if (v == "OFF") return false; + if (v == "NO") return false; + + return false; +} \ No newline at end of file diff --git a/src/network/http.cpp b/src/network/http.cpp index 9a63046..b169a7e 100644 --- a/src/network/http.cpp +++ b/src/network/http.cpp @@ -4,11 +4,14 @@ #include #include -WebServer server(80); +typedef WebServer HTTPWEBSERVER; + +HTTPWEBSERVER server(80); #endif #ifdef ESP8266 #include +typedef ESP8266WebServer HTTPWEBSERVER; -ESP8266WebServer server(80); +HTTPWEBSERVER server(80); #endif diff --git a/src/network/http_normal_web.cpp b/src/network/http_normal_web.cpp index ede0019..b026cb9 100644 --- a/src/network/http_normal_web.cpp +++ b/src/network/http_normal_web.cpp @@ -6,76 +6,21 @@ #include "config.h" #include "http_normal.h" -#include "display/display.h" -#include "config.h" - -#ifdef ESP32 -#include -extern WebServer server; -#endif - -#ifdef ESP8266 -#include -extern ESP8266WebServer server; -#endif - -void http_handle_not_found() { - String message = http_normal_not_found_html(); - server.send(200, MIME_HTML, message); -} - -void http_handle_data() { - String message = http_normal_data_json(); - server.send(200, MIME_JSON, message); -} - -void http_handle_ping() { - String message = http_normal_ping_json(); - server.send(200, MIME_JSON, message); -} - -void http_handle_stastics() { - server.send(200, MIME_JSON, stasticsJSON); -} - -void http_handle_brightness() { - String value = server.arg("value"); - int brightness = value.toInt(); - String msg = disp_set_brightness(brightness); - server.send(200, MIME_TEXT, "OK\n" + msg); -} - -void http_handle_power() { - String power = server.arg("value"); - - if (power == "1") { - disp_set_power(true); - } else { - disp_set_power(false); - } - String message = "OK"; - server.send( 200, MIME_TEXT, message ); -} +#include "network/http_api.h" +#include "network/http_api_base.h" +#include "network/http_api_display.h" +#include "network/http_api_mhz.h" -void http_handle_goto_setup() { - - remove_configure_flag_file(); - - String message = "OK. Entering setup mode at next boot."; - server.send( 200, MIME_TEXT, message ); -} +extern HTTPWEBSERVER server; void http_setup_normal() { httplog("HTTP web server initializing"); - server.on ( "/ping", HTTP_GET, http_handle_ping); - server.on ( "/", HTTP_GET, http_handle_data ); - server.on ( "/brightness", HTTP_GET, http_handle_brightness ); - server.on ( "/display", HTTP_GET, http_handle_power ); - server.on ( "/stastics", HTTP_GET, http_handle_stastics ); - server.on ( "/goto_setup", HTTP_POST, http_handle_goto_setup ); - server.onNotFound ( http_handle_not_found ); + http_api_display_setup(); + http_api_base_setup(); + http_api_mhz_setup(); + server.begin(); httplog("HTTP web server initialized"); } diff --git a/src/sensors/mhz19b/mhz19_uart.cpp b/src/sensors/mhz19b/mhz19_uart.cpp index 64337d3..6ed7b22 100644 --- a/src/sensors/mhz19b/mhz19_uart.cpp +++ b/src/sensors/mhz19b/mhz19_uart.cpp @@ -19,8 +19,6 @@ bool AUTO_BASELINE_CORRECTION = false; SoftwareSerial mhzSerial(14, 0); #endif -unsigned long mhzGetDataTimer = 0; - MHZ19 mhz19; void printErrorCode() { @@ -68,7 +66,7 @@ bool mhz_setup_uart() { mhz19.begin(mhzSerial); - mhz19.setRange(5000); + mhz19.setRange(2000); printErrorCode(); // mhzlog("setSpan()"); @@ -79,24 +77,51 @@ bool mhz_setup_uart() { mhz19.autoCalibration(AUTO_BASELINE_CORRECTION); printErrorCode(); - if (AUTO_BASELINE_CORRECTION) { - mhzlog(F("WARNING -------------------------- WARNING")); - mhzlog(F(" Auto Baseline Correction is ON!")); - mhzlog(F("WARNING -------------------------- WARNING")); - } - mhz_setup_check_device_uart(); - mhzlog(F("initialized.")); + mhzlog(F("initialized.")); return true; } -void mhz_read_data_uart() { +// For API +bool mhz_do_zero_calibration() { + if (config.mhz19b != MHZ_USE_UART) return false; + mhz19.calibrate(); + if (mhz19.errorCode != 1) { + mhzlog("API: ZeroCalibration: Error " + mhz19_code_to_msg(mhz19.errorCode)); + return false; + } - if ( (millis() - mhzGetDataTimer) < 3000) { - return; + mhzlog(F("API: ZeroCalibration: done")); + return true; +} + +// For API +bool mhz_get_abc() { + if (config.mhz19b != MHZ_USE_UART) return false; + return mhz19.getABC(); +} + +// For API +bool mhz_set_abc(bool onoff) { + if (config.mhz19b != MHZ_USE_UART) return false; + mhz19.autoCalibration(onoff); + if (mhz19.errorCode != 1) { + mhzlog("API: " + mhz19_code_to_msg(mhz19.errorCode)); + return false; + } + + if (onoff) { + mhzlog(F("API: ABC is now ON")); + } else { + mhzlog(F("API: ABC is now OFF")); } + return true; +} + +void mhz_read_data_uart() { + mhz19.verify(); if (mhz19.errorCode != MHZ_RESULT_OK) { printErrorCode(); @@ -105,9 +130,7 @@ void mhz_read_data_uart() { } int co2ppm = mhz19.getCO2(); - if (mhz19.errorCode == 1) { - mhzGetDataTimer = millis(); - } else { + if (mhz19.errorCode != 1) { printErrorCode(); }