From a26dd0d44bf61c804b2df7812455ab07fd7fb3b1 Mon Sep 17 00:00:00 2001 From: Yakumo Saki Date: Tue, 5 Jan 2021 17:36:57 +0900 Subject: [PATCH 1/7] fix: reboot bug at MHZ software serial on 8266 --- README.md | 4 ++++ src/main_normal.cpp | 28 +++++++++++++++------------- src/sensors/mhz19b/mhz19_uart.cpp | 1 - 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 003d10e..8ad6ed7 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,10 @@ Get binary from releases page.(not every version have binary file, sorry) ## History +### v3.2 + +* Avoid using delay + ### v3.1 * Add vertical display mode(bigger font. ST7789 only) diff --git a/src/main_normal.cpp b/src/main_normal.cpp index d4106d2..b614615 100644 --- a/src/main_normal.cpp +++ b/src/main_normal.cpp @@ -71,21 +71,22 @@ void read_data() { if (config.use_mhz19b) { // - mhz_read_data(); - if (config.opMode == OPMODE_MQTT) { - delay(3050); // MHZデータ取得待ち - mhz_read_data(); // ここは adhoc - } - - // MQTT: if ppm == -1 , MH-Z19 error. - if (sensorValues.co2ppm > 0) { - char buf[24] = ""; - sprintf(buf, "%d", sensorValues.co2ppm); - mqtt_publish("co2ppm", buf); + delay(3050); // MHZデータ取得待ち + mhz_read_data(); // ここは adhoc + + // MQTT: if ppm == -1 , MH-Z19 error. + if (sensorValues.co2ppm > 0) { + char buf[24] = ""; + sprintf(buf, "%d", sensorValues.co2ppm); + mqtt_publish("co2ppm", buf); + } else { + // MH-Z19B read error. do nothing. + } } else { - // MH-Z19B read error. do nothing. - } + mhz_read_data(); + } + } mainlog("Reading sensor data complete."); @@ -192,6 +193,7 @@ void loop_normal() { } read_data(); + delay(1000); // sleep to next. if (config.opMode == OPMODE_MQTT) { diff --git a/src/sensors/mhz19b/mhz19_uart.cpp b/src/sensors/mhz19b/mhz19_uart.cpp index 8771144..44be3c7 100644 --- a/src/sensors/mhz19b/mhz19_uart.cpp +++ b/src/sensors/mhz19b/mhz19_uart.cpp @@ -58,7 +58,6 @@ void mhz_setup_uart() { mhzlog("ESP32 serial begin RX=" + String(config.mhz19b_rxpin.toInt()) + " TX=" + String(config.mhz19b_txpin.toInt())); mhzSerial.begin(MHZ_BAUDRATE, SERIAL_8N1, config.mhz19b_rxpin.toInt(), config.mhz19b_txpin.toInt()); #elif defined(ARDUINO_ARCH_ESP8266) - SoftwareSerial mhzSerial(config.mhz19b_rxpin.toInt(), config.mhz19b_txpin.toInt()); mhzSerial.begin(MHZ_BAUDRATE); #endif From 9b607bc366f074677e399d93ea90da22854e46b8 Mon Sep 17 00:00:00 2001 From: Yakumo Saki Date: Wed, 6 Jan 2021 18:49:55 +0900 Subject: [PATCH 2/7] refactor MQTT --- include/log.h | 3 + include/main_normal.h | 4 +- include/main_normal_mqtt.h | 1 + src/display_ssd1306.cpp | 6 +- src/display_st7789.cpp | 2 +- src/global.cpp | 4 + src/i2c.cpp | 3 + src/log.cpp | 10 ++ src/main.cpp | 13 --- src/main_normal mqtt.cpp | 103 ++++++++++++++++++ src/main_normal.cpp | 175 ++++++++++-------------------- src/main_setup.cpp | 3 +- src/sensors/mhz19b/mhz19_uart.cpp | 20 ++-- 13 files changed, 197 insertions(+), 150 deletions(-) create mode 100644 include/main_normal_mqtt.h create mode 100644 src/main_normal mqtt.cpp diff --git a/include/log.h b/include/log.h index fe4aa45..bc80323 100644 --- a/include/log.h +++ b/include/log.h @@ -12,4 +12,7 @@ void httplog(String msg); void displog(String msg); void mdnslog(String msg); void wifilog(String msg); +void i2clog(String msg); +void stlog(String msg); +void ssdlog(String msg); void sectionlog(String msg); diff --git a/include/main_normal.h b/include/main_normal.h index a4f6d29..525e24f 100644 --- a/include/main_normal.h +++ b/include/main_normal.h @@ -1,2 +1,4 @@ +void init_sensors(); void setup_normal(); -void loop_normal(); \ No newline at end of file +void loop_normal(); +void read_data(); \ No newline at end of file diff --git a/include/main_normal_mqtt.h b/include/main_normal_mqtt.h new file mode 100644 index 0000000..020a8f5 --- /dev/null +++ b/include/main_normal_mqtt.h @@ -0,0 +1 @@ +void setup_normal_mqtt(); diff --git a/src/display_ssd1306.cpp b/src/display_ssd1306.cpp index b0fbb8d..34fb1cc 100644 --- a/src/display_ssd1306.cpp +++ b/src/display_ssd1306.cpp @@ -278,5 +278,9 @@ void disp_ssd1306_set_power(bool poweron) { } void setup_disp_ssd1306() { - displog("SSD1306: Nothing to do."); + if (has_ssd1306()) { + ssdlog("Initialized."); + } else { + ssdlog("SSD1306 NOT FOUND."); + } } \ No newline at end of file diff --git a/src/display_st7789.cpp b/src/display_st7789.cpp index 189d648..9b062b2 100644 --- a/src/display_st7789.cpp +++ b/src/display_st7789.cpp @@ -353,5 +353,5 @@ void setup_disp_st7789() tft.init(); tft.setRotation(3); tft.fillScreen(TFT_BLACK); - displog("ST7789: Nothing to do."); + stlog("ST7789 Initialized."); } \ No newline at end of file diff --git a/src/global.cpp b/src/global.cpp index 95fb21b..7ab3471 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -16,10 +16,14 @@ String product_long = product + " Ver." + ver; // デバイス周りの定数 // -------------------------------------------------------------------- #ifdef ESP32 +// ESP32 SDA extern const int I2C_SDA = 21; +// ESP32 SCL extern const int I2C_SCL = 22; #elif defined(ESP8266) +// ESP8266 SDA extern const int I2C_SDA = 5; +// ESP8266 SCL extern const int I2C_SCL = 4; #endif diff --git a/src/i2c.cpp b/src/i2c.cpp index be8a396..b2fc09e 100644 --- a/src/i2c.cpp +++ b/src/i2c.cpp @@ -1,11 +1,14 @@ #include #include +#include "log.h" bool init_i2c(int sda, int scl) { #ifdef ESP32 + i2clog("Initializing ESP32 I2C SDA=" + String(sda) + " SCL=" + String(scl)); return Wire.begin(sda, scl); #endif #ifdef ESP8266 + i2clog("Initializing ESP8266 I2C SDA=" + String(sda) + " SCL=" + String(scl)); Wire.begin(sda, scl); return true; #endif diff --git a/src/log.cpp b/src/log.cpp index 5c92a24..4655648 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -58,6 +58,16 @@ void wifilog(String msg) { real_log(msg, "WiFi"); } +void i2clog(String msg) { + real_log(msg, "I2C"); +} +void ssdlog(String msg) { + real_log(msg, "SSD1306"); +} +void stlog(String msg) { + real_log(msg, "ST7789"); +} + void sectionlog(String msg) { Serial.println(""); real_log(msg, "========"); diff --git a/src/main.cpp b/src/main.cpp index 9950546..21f0ab1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,12 +6,9 @@ #include "log.h" #include "global.h" #include "config.h" -#include "i2c.h" #include "main_setup.h" #include "main_normal.h" -#include - bool isNormal = false; void setup() @@ -29,16 +26,6 @@ void setup() config_setup(); isNormal = has_valid_config(); - // Init I2C Serial - sectionlog("Initializing I2C SDA=" + String(I2C_SDA) + " SCL=" + String(I2C_SCL)); - - bool ret = init_i2c(I2C_SDA, I2C_SCL); - if (ret) { - mainlog("I2C initialized."); - } else { - mainlog("error initializing I2C"); - } - if (!isNormal) { sectionlog("Entering setup mode."); setup_setupmode(); diff --git a/src/main_normal mqtt.cpp b/src/main_normal mqtt.cpp new file mode 100644 index 0000000..923889d --- /dev/null +++ b/src/main_normal mqtt.cpp @@ -0,0 +1,103 @@ +#include + +#include + +#include "log.h" +#include "global.h" +#include "config.h" +#include "wifi.h" +#include "main_normal.h" + +WiFiClient net; +MQTTClient mqttClient; + +bool NO_DEEP_SLEEP = false; +const int NO_DEEP_SLEEP_DURATION = 3000; +const int NORMAL_DURATION = 1000; + +void begin_mqtt_connection() { + + Serial.println("MQTT Begin"); + mqttClient.begin(config.mqttBroker.c_str(), net); + delay(10); + + Serial.println("MQTT Started successfully."); +} + +void mqtt_publish(String topic, String value) { + + if (config.opMode != OPMODE_MQTT) { + return; + } + + String t = "/" + config.mqttName + "/" + topic; + Serial.println("MQTT Publish topic=>" + t + " value=>" + value); + mqttClient.publish(t, value); +} + +/** + * LOOP + */ +void send_and_sleep() { + + sectionlog("loop start"); + + // WiFiが繋がってなければ意味がないので接続チェック + make_sure_wifi_connected(); + + mainlog("WiFi connected."); + + // MQTT + if (config.opMode == OPMODE_MQTT) { + begin_mqtt_connection(); + + mqttClient.loop(); + delay(10); // <- fixes some issues with WiFi stability + + mainlog("MQTT Connect begin"); + while (!mqttClient.connect(config.mDNS.c_str(), "", "")) { // username and password not support + Serial.print("."); + delay(1000); + } + mainlog("MQTT Connect OK"); + } + + read_data(); + + mqtt_publish("lux", String(sensorValues.lux, 0)); + mqtt_publish("luxIr", String(sensorValues.luxIr, 0)); + mqtt_publish("co2ppm", String(sensorValues.co2ppm,0)); + mqtt_publish("co2ppmAccuracy", sensorValues.co2ppmAccuracy); + mqtt_publish("temperature",String(sensorValues.temperature, 2)); + mqtt_publish("humidity", String(sensorValues.humidity, 2)); + mqtt_publish("pressure", String(sensorValues.pressure, 1)); + + if (NO_DEEP_SLEEP) { + mainlog("!!! NOT deep sleep because of NO_DEEP_SLEEP is set !!!"); + delay(NO_DEEP_SLEEP_DURATION); + mainlog("!!! Going to next loop !!!"); + } else { + delay(500); + mainlog("*** Goto deep sleep ***"); + ESP.deepSleep(NORMAL_DURATION); + delay(10000); + } +} + +/** + * MQTT通常起動モードのSETUP + */ +void setup_normal_mqtt() { + + // read_config(); configは読み込み済 + // I2C は初期化済 + + // start WiFi + sectionlog("Connecting WiFi."); + make_sure_wifi_connected(); + + init_sensors(); + + send_and_sleep(); +} + diff --git a/src/main_normal.cpp b/src/main_normal.cpp index b614615..21d040f 100644 --- a/src/main_normal.cpp +++ b/src/main_normal.cpp @@ -15,41 +15,18 @@ #include "config.h" #include "wifi.h" +#include "i2c.h" +#include "main_normal_mqtt.h" + WiFiClient net; MQTTClient mqttClient; int counter; -void begin_mqtt_connection() { - - Serial.println("MQTT Begin"); - mqttClient.begin(config.mqttBroker.c_str(), net); - delay(10); - - Serial.println("MQTT Started successfully."); -} - -void mqtt_publish(String topic, String value) { - - if (config.opMode != OPMODE_MQTT) { - return; - } - - String t = "/" + config.mqttName + "/" + topic; - Serial.println("MQTT Publish topic=>" + t + " value=>" + value); - mqttClient.publish(t, value); -} - void read_data() { mainlog("Reading sensor data start."); - // 電圧 - // if (true) { - // int s0 = analogRead(0); - // mqtt_publish("battery", String(s0)); - // } - // 精度の怪しいものから順に値を上書きしていく。 bme_read_data(); // temp humi pres am_read_data(); // temp humi @@ -60,10 +37,7 @@ void read_data() { // MQTT char buf[24] = ""; sprintf(buf, "%2f", sensorValues.lux); - mqtt_publish("lux", buf); - - sprintf(buf, "%2f", sensorValues.luxIr); - mqtt_publish("luxIr", buf); + sprintf(buf, "%2f", sensorValues.luxIr); } else { sensorValues.lux = 0; sensorValues.luxIr = 0; @@ -72,42 +46,37 @@ void read_data() { if (config.use_mhz19b) { // if (config.opMode == OPMODE_MQTT) { - delay(3050); // MHZデータ取得待ち - mhz_read_data(); // ここは adhoc - - // MQTT: if ppm == -1 , MH-Z19 error. - if (sensorValues.co2ppm > 0) { - char buf[24] = ""; - sprintf(buf, "%d", sensorValues.co2ppm); - mqtt_publish("co2ppm", buf); - } else { - // MH-Z19B read error. do nothing. - } + delay(3050); // MHZデータ取得待ち + mhz_read_data(); // ここは adhoc + + // MQTT: if ppm == -1 , MH-Z19 error. + if (sensorValues.co2ppm > 0) { + char buf[24] = ""; + sprintf(buf, "%d", sensorValues.co2ppm); + } else { + // MH-Z19B read error. do nothing. + } } else { - mhz_read_data(); - } + mhz_read_data(); + } } - mainlog("Reading sensor data complete."); + mainlog("Reading sensor data complete."); +} - // MQTT - char buf[24] = ""; - if (sensorValues.temperature != NAN) { - sprintf(buf, "%2f", sensorValues.temperature); - mqtt_publish("temp", buf); - } - - if (sensorValues.humidity != NAN) { - sprintf(buf, "%2f", sensorValues.humidity); - mqtt_publish("humi", buf); - } +void init_sensors() { + sectionlog("Initializing sensors start."); + bme_setup(); + adt_setup(); + am_setup(); + lps_setup(); + tsl_setup(); - if (sensorValues.pressure != NAN) { - sprintf(buf, "%2f", sensorValues.pressure); - mqtt_publish("pres", buf); + if (config.use_mhz19b != MHZ_NOUSE) { + mhz_setup(); } - + sectionlog("Initializing sensors done."); } /** @@ -117,24 +86,34 @@ void setup_normal() { read_config(); + // Init I2C Serial + bool ret = init_i2c(I2C_SDA, I2C_SCL); + if (ret) { + mainlog("I2C initialized."); + } else { + mainlog("error initializing I2C"); + } + + if (config.opMode == OPMODE_MQTT) { + setup_normal_mqtt(); + return; // MQTTモードの場合はもう戻ってこない(ディープスリープする) + } + setup_display(); disp_normal_startup_screen(product_long); // setupモードに入りやすくするための処理 - if (config.opMode == OPMODE_DISPLAY) { - sectionlog("Reset to reconfig start."); - remove_configure_flag_file(); - // list_dir(); + sectionlog("Reset to reconfig start."); + remove_configure_flag_file(); + // list_dir(); - disp_wait_for_reconfig(); - - // 設定済みフラグファイル - create_configure_flag_file(); + disp_wait_for_reconfig(); - // list_dir(); - sectionlog("Reconfigure timeout. continue."); + // 設定済みフラグファイル + create_configure_flag_file(); - } + // list_dir(); + sectionlog("Reconfigure timeout. continue."); // start WiFi sectionlog("Connecting WiFi."); @@ -148,18 +127,6 @@ void setup_normal() { sectionlog("Starting HTTP server."); http_setup_normal(); - sectionlog("Initializing sensors start."); - bme_setup(); - adt_setup(); - am_setup(); - lps_setup(); - tsl_setup(); - - if (config.use_mhz19b != MHZ_NOUSE) { - mhz_setup(); - } - sectionlog("Initializing sensors done."); - // 初期化終了時に画面表示をどうにかできるフック disp_all_initialize_complete(get_wifi_ip_addr(), config.mDNS); @@ -176,45 +143,13 @@ void loop_normal() { make_sure_wifi_connected(); mainlog("WiFi connected."); - - // MQTT - if (config.opMode == OPMODE_MQTT) { - begin_mqtt_connection(); - - mqttClient.loop(); - delay(10); // <- fixes some issues with WiFi stability - - Serial.println("MQTT Connect"); - while (!mqttClient.connect(config.mDNS.c_str(), "", "")) { // username and password not support - Serial.print("."); - delay(1000); - } - Serial.println(""); - } read_data(); - delay(1000); - // sleep to next. - if (config.opMode == OPMODE_MQTT) { - disp_sensor_value(get_wifi_ip_addr(), config.mDNS); - delay(1000); - disp_power_off(); - - // if (NO_DEEP_SLEEP) { - // mainlog("!!! NOT deep sleep because of NO_DEEP_SLEEP is set !!!"); - // delay(NO_DEEP_SLEEP_DURATION); - // mainlog("!!! Going to next loop !!!"); - // } else { - // delay(500); - // mainlog("*** Goto deep sleep ***"); - // ESP.deepSleep(NORMAL_DURATION); - // delay(10000); - // } - } else if (config.opMode == OPMODE_DISPLAY) { - disp_sensor_value(get_wifi_ip_addr(), config.mDNS); - http_loop_normal(); - mainlog("Wait for Next tick."); - delay(1000); - } + disp_sensor_value(get_wifi_ip_addr(), config.mDNS); + + http_loop_normal(); + + mainlog("Wait for Next tick."); + delay(1000); } diff --git a/src/main_setup.cpp b/src/main_setup.cpp index 09a6b50..8f909b3 100644 --- a/src/main_setup.cpp +++ b/src/main_setup.cpp @@ -28,5 +28,4 @@ void setup_setupmode() { void loop_setupmode() { loop_http_setup(); -} - +} \ No newline at end of file diff --git a/src/sensors/mhz19b/mhz19_uart.cpp b/src/sensors/mhz19b/mhz19_uart.cpp index 44be3c7..357d6e8 100644 --- a/src/sensors/mhz19b/mhz19_uart.cpp +++ b/src/sensors/mhz19b/mhz19_uart.cpp @@ -97,24 +97,20 @@ void mhz_read_data_uart() { return; } - mhzGetDataTimer = millis(); - - String range = String(mhz19.getRange()); - printErrorCode(); + int co2ppm = mhz19.getCO2(false); + if (mhz19.errorCode == 1) { + mhzGetDataTimer = millis(); + } else { + printErrorCode(); + } - mhz19.verify(); + int temp = mhz19.getTemperature(); printErrorCode(); String acc = String(mhz19.getAccuracy()); printErrorCode(); - int co2ppm = mhz19.getCO2(false); - printErrorCode(); - - int temp = mhz19.getTemperature(); - printErrorCode(); - - mhzlog("CO2 (ppm): " + String(co2ppm) + " Accuracy: " + acc + " Temp: " + String(temp) + " CO2 range: "+ range); + mhzlog("CO2 (ppm): " + String(co2ppm) + " Accuracy: " + acc + " Temp: " + String(temp)); sensorValues.co2ppm = co2ppm; sensorValues.co2ppmAccuracy = acc; } From 07bc712c8d7441591293e4ba15b209f00386e1ae Mon Sep 17 00:00:00 2001 From: Yakumo Saki Date: Thu, 7 Jan 2021 12:00:59 +0900 Subject: [PATCH 3/7] fix: ESP8266 i2c bug --- README.md | 23 +++- include/display_st7789.h | 4 +- include/i2c_scan.h | 1 + platformio.ini | 105 +++++++----------- src/config.cpp | 3 - src/define.cpp | 3 + src/{ => display}/display.cpp | 7 +- src/{ => display}/display_formatter.cpp | 0 src/{ => display}/display_ssd1306.cpp | 0 .../display_st7789_impl.cpp} | 6 +- src/display/display_st7789_mock.cpp | 30 +++++ src/i2c.cpp | 18 ++- src/i2c_scan.cpp | 45 ++++++++ src/main_normal mqtt.cpp | 2 +- src/main_normal.cpp | 16 +-- src/sensors/mhz19b/mhz19_uart.cpp | 2 +- 16 files changed, 175 insertions(+), 90 deletions(-) create mode 100644 include/i2c_scan.h create mode 100644 src/define.cpp rename src/{ => display}/display.cpp (96%) rename src/{ => display}/display_formatter.cpp (100%) rename src/{ => display}/display_ssd1306.cpp (100%) rename src/{display_st7789.cpp => display/display_st7789_impl.cpp} (99%) create mode 100644 src/display/display_st7789_mock.cpp create mode 100644 src/i2c_scan.cpp diff --git a/README.md b/README.md index 8ad6ed7..a9aa872 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,11 @@ if SSD1306 is connected, sensor value are displayed in SSD1306 (v3.0) ST7789 is supported. Activate on config screen. -In setup mode, no output. +In setup mode, no output on ST7789, it's normal. + +(v3.2) +ST7789 support is now ESP32 only. +Maybe I can support ST7789 on ESP8266. but not in TODO. ### http server @@ -101,11 +105,26 @@ esptool.py write_flash 0x1000 filename.bin ``` Get binary from releases page.(not every version have binary file, sorry) -## History +## Boards I tested (at least once) + +### ESP32 + +* LilyGO TTGO T-DISPLAY (ESP32 and ST7789 TFT) +* NodeMCU V3 V2 ESP32 D1MINI + +### ESP8266 + +* D-Duino (ESP8266 and ST1306 OLED board) +* WeMos D1mini +* NodeMCU V3 + +## Version History ### v3.2 * Avoid using delay +* BUGFIX: ESP8266: I2C not working +* DROP: ESP8266: ST7789 is not supported (because of Pin config) ### v3.1 diff --git a/include/display_st7789.h b/include/display_st7789.h index 694ac6d..b0e8534 100644 --- a/include/display_st7789.h +++ b/include/display_st7789.h @@ -1,10 +1,12 @@ #include +// 使える使えないの判断フラグ ST7789_SUPPORTED -> define.cpp +// このフラグで呼び出される実態が空っぽなのと実装されているものに分かれる。 + // ST7789V はセットアップモードをサポートしない // これは接続されていない場合に初期化しようとしてしまうと何が起きるかわからないため // void disp_st7789_setup_startup_screen(String ipAddr); - void disp_st7789_wifi_info(String ip, String mDNS); void disp_st7789_normal_startup_screen(String product_long); void disp_st7789_wait_for_reconfig_init(); diff --git a/include/i2c_scan.h b/include/i2c_scan.h new file mode 100644 index 0000000..720f778 --- /dev/null +++ b/include/i2c_scan.h @@ -0,0 +1 @@ +void i2c_scan(); \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index d4f558e..3ff3e85 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,47 +8,45 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:esp32dev] -platform = espressif32 -board = esp32dev -framework = arduino -board_build.mcu = esp32 -monitor_speed = 115200 -board_build.f_cpu = 80000000L -;board_build.f_cpu = 160000000L -;board_build.f_cpu = 240000000L -lib_deps = - joba-1/Joba_Tsl2561@^2.0.10 - squix78/ESP8266_SSD1306@^4.1.0 - 256dpi/MQTT@^2.4.7 - wifwaf/MH-Z19@^1.5.2 - sodaqmoja/Sodaq_LPS22HB@^1.0.0 - ottowinter/ESPAsyncWebServer-esphome@^1.2.7 - lorol/LittleFS_esp32@^1.0.0 - seeed-studio/Grove - Barometer Sensor BME280@^1.0.2 -build_flags = - -Os - -DCORE_DEBUG_LEVEL=2 - -DUSER_SETUP_LOADED=1 - -DST7789_DRIVER=1 - -DTFT_WIDTH=135 - -DTFT_HEIGHT=240 - -DTFT_MOSI=19 - -DTFT_SCLK=18 - -DTFT_CS=5 - -DTFT_DC=16 - -DTFT_RST=23 - -DTFT_BL=4 - -DSPI_FREQUENCY=40000000 - -DLOAD_GLCD=1 - -DCGRAM_OFFSET=1 - -DLOAD_FONT2=1 - -DLOAD_FONT4=1 - -DLOAD_FONT6=1 - -DLOAD_FONT7=1 - -DLOAD_GFXFF=1 - -DSMOOTH_FONT=1 - +; [env:esp32dev] +; platform = espressif32 +; board = esp32dev +; framework = arduino +; board_build.mcu = esp32 +; monitor_speed = 115200 +; board_build.f_cpu = 80000000L +; lib_deps = +; joba-1/Joba_Tsl2561@^2.0.10 +; squix78/ESP8266_SSD1306@^4.1.0 +; 256dpi/MQTT@^2.4.7 +; wifwaf/MH-Z19@^1.5.2 +; sodaqmoja/Sodaq_LPS22HB@^1.0.0 +; ottowinter/ESPAsyncWebServer-esphome@^1.2.7 +; lorol/LittleFS_esp32@^1.0.0 +; seeed-studio/Grove - Barometer Sensor BME280@^1.0.2 +; bodmer/TFT_eSPI@^2.3.41 +; build_flags = +; -Os +; -DCORE_DEBUG_LEVEL=2 +; -DUSER_SETUP_LOADED=1 +; -DST7789_DRIVER=1 +; -DTFT_WIDTH=135 +; -DTFT_HEIGHT=240 +; -DTFT_MOSI=19 +; -DTFT_SCLK=18 +; -DTFT_CS=5 +; -DTFT_DC=16 +; -DTFT_RST=23 +; -DTFT_BL=4 +; -DSPI_FREQUENCY=40000000 +; -DLOAD_GLCD=1 +; -DCGRAM_OFFSET=1 +; -DLOAD_FONT2=1 +; -DLOAD_FONT4=1 +; -DLOAD_FONT6=1 +; -DLOAD_FONT7=1 +; -DLOAD_GFXFF=1 +; -DSMOOTH_FONT=1 [env:esp12e] platform = espressif8266 @@ -62,27 +60,6 @@ lib_deps = wifwaf/MH-Z19@^1.5.2 sodaqmoja/Sodaq_LPS22HB@^1.0.0 ottowinter/ESPAsyncWebServer-esphome@^1.2.7 - lorol/LittleFS_esp32@^1.0.0 seeed-studio/Grove - Barometer Sensor BME280@^1.0.2 -build_flags = - -Os - -DCORE_DEBUG_LEVEL=2 - -DUSER_SETUP_LOADED=1 - -DST7789_DRIVER=1 - -DTFT_WIDTH=135 - -DTFT_HEIGHT=240 - -DTFT_MOSI=19 - -DTFT_SCLK=18 - -DTFT_CS=5 - -DTFT_DC=16 - -DTFT_RST=23 - -DTFT_BL=4 - -DSPI_FREQUENCY=40000000 - -DLOAD_GLCD=1 - -DCGRAM_OFFSET=1 - -DLOAD_FONT2=1 - -DLOAD_FONT4=1 - -DLOAD_FONT6=1 - -DLOAD_FONT7=1 - -DLOAD_GFXFF=1 - -DSMOOTH_FONT=1 +build_flags = + -DCORE_DEBUG_LEVEL=2 diff --git a/src/config.cpp b/src/config.cpp index 5e92456..0cd70c9 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -78,9 +78,6 @@ void write_config_file(File f) { void read_config_file(File f) { String settingId = f.readStringUntil('\n'); // 使わない - if (settingId != SETTING_ID) { - cfglog("Setting id is not equal. file=" + settingId + " code=" + SETTING_ID); - } config.ssid = f.readStringUntil('\n'); config.password = f.readStringUntil('\n'); config.mDNS = f.readStringUntil('\n'); diff --git a/src/define.cpp b/src/define.cpp new file mode 100644 index 0000000..5ce86b6 --- /dev/null +++ b/src/define.cpp @@ -0,0 +1,3 @@ +#ifdef ESP32 +#define ST7789_SUPPORTED +#endif diff --git a/src/display.cpp b/src/display/display.cpp similarity index 96% rename from src/display.cpp rename to src/display/display.cpp index 1468289..d8ca35c 100644 --- a/src/display.cpp +++ b/src/display/display.cpp @@ -102,9 +102,9 @@ void disp_wait_for_reconfig() { disp_ssd1306_wait_for_reconfig_init(); } + displog("Wait for reconfigure start"); for (int i = 0; i < MAX_BAR; i++) { - displog("Wait for reconfigure " + String(i) + " / " + String(MAX_BAR)); if (use_st7789()) { disp_st7789_wait_for_reconfig_bar(i, MAX_BAR); } @@ -114,6 +114,8 @@ void disp_wait_for_reconfig() { delay(WAIT_PER_BAR); } + displog("Wait for reconfigure end"); + } void disp_all_initialize_complete(String ip, String mdns) { @@ -178,9 +180,10 @@ void disp_set_power(bool poweron) { } void setup_display() { - displog("Setup"); if (use_ssd1306()) { setup_disp_ssd1306(); + } else { + displog("SSD1306 not found."); } if (use_st7789()) { setup_disp_st7789(); diff --git a/src/display_formatter.cpp b/src/display/display_formatter.cpp similarity index 100% rename from src/display_formatter.cpp rename to src/display/display_formatter.cpp diff --git a/src/display_ssd1306.cpp b/src/display/display_ssd1306.cpp similarity index 100% rename from src/display_ssd1306.cpp rename to src/display/display_ssd1306.cpp diff --git a/src/display_st7789.cpp b/src/display/display_st7789_impl.cpp similarity index 99% rename from src/display_st7789.cpp rename to src/display/display_st7789_impl.cpp index 9b062b2..c98ebd4 100644 --- a/src/display_st7789.cpp +++ b/src/display/display_st7789_impl.cpp @@ -1,3 +1,5 @@ +#ifdef DENVBOY_ST7789_SUPPORT + #include #include "global.h" @@ -354,4 +356,6 @@ void setup_disp_st7789() tft.setRotation(3); tft.fillScreen(TFT_BLACK); stlog("ST7789 Initialized."); -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/src/display/display_st7789_mock.cpp b/src/display/display_st7789_mock.cpp new file mode 100644 index 0000000..127164d --- /dev/null +++ b/src/display/display_st7789_mock.cpp @@ -0,0 +1,30 @@ +#ifndef ST7789_SUPPORTED + +// ST7789 非サポートのボード用。呼ばれることはない。コンパイルを通すためだけのもの + +#include +#include "global.h" +#include "structs.h" + +void disp_st7789_wifi_info(String ip, String mDNS) {} +void disp_st7789_normal_startup_screen(String product_long) {} +void disp_st7789_wait_for_reconfig_init() {} +void disp_st7789_wait_for_reconfig_bar(int now, const int max) {} +void disp_st7789_wifi_starting(int wait_print_row) {} +void disp_st7789_all_initialize_complete(String ip, String mdns) {} +void disp_st7789_sensor_value(disp_values_t new_values, disp_values_t last_values) {} +void disp_st7789_power_off() {} + +void disp_st7789_wifi_error() {} + +String disp_st7789_set_brightness(int brightness) {} + +/** + * 液晶のON/OFFを設定する + * @param poweron true = ONにする false = offにする + */ +void disp_st7789_set_power(bool poweron) {}; + +void setup_disp_st7789() {}; + +#endif \ No newline at end of file diff --git a/src/i2c.cpp b/src/i2c.cpp index b2fc09e..978f68c 100644 --- a/src/i2c.cpp +++ b/src/i2c.cpp @@ -1,15 +1,27 @@ #include #include + #include "log.h" +#include "i2c_scan.h" bool init_i2c(int sda, int scl) { + bool ret = true; #ifdef ESP32 i2clog("Initializing ESP32 I2C SDA=" + String(sda) + " SCL=" + String(scl)); - return Wire.begin(sda, scl); + ret = Wire.begin(sda, scl); + if (ret) { + i2clog("I2C initialized."); + } else { + i2clog("error initializing I2C"); + } #endif #ifdef ESP8266 i2clog("Initializing ESP8266 I2C SDA=" + String(sda) + " SCL=" + String(scl)); - Wire.begin(sda, scl); - return true; + Wire.begin(sda, scl); // 8266のbeginは返り値がない + i2clog("I2C initialized."); #endif + + i2c_scan(); + + return ret; } \ No newline at end of file diff --git a/src/i2c_scan.cpp b/src/i2c_scan.cpp new file mode 100644 index 0000000..5e19092 --- /dev/null +++ b/src/i2c_scan.cpp @@ -0,0 +1,45 @@ +#include +#include + +#include "log.h" + +void i2c_scan() +{ + + unsigned long start = millis(); + + byte error, address; + int nDevices = 0; + for(address = 1; address < 127; address++ ) + { + + Wire.beginTransmission(address); + error = Wire.endTransmission(); + + if (error == 0) + { + String msg = "I2C device found at address 0x"; + if (address<16) + msg += "0"; + msg += String(address,HEX); + msg += " " + String(address); + i2clog(msg); + nDevices++; + } + else if (error==4) + { + String msg = "Unknown error at address 0x"; + if (address<16) + msg += "0"; + msg += String(address,HEX); + i2clog(msg); + } + } + + if (nDevices == 0) { + i2clog("No I2C devices found"); + } + + i2clog("i2c scan done. time = " + String(millis() - start) + " ms"); + +} diff --git a/src/main_normal mqtt.cpp b/src/main_normal mqtt.cpp index 923889d..c22d1d2 100644 --- a/src/main_normal mqtt.cpp +++ b/src/main_normal mqtt.cpp @@ -8,7 +8,7 @@ #include "wifi.h" #include "main_normal.h" -WiFiClient net; +extern WiFiClient net; MQTTClient mqttClient; bool NO_DEEP_SLEEP = false; diff --git a/src/main_normal.cpp b/src/main_normal.cpp index 21d040f..7fc70a3 100644 --- a/src/main_normal.cpp +++ b/src/main_normal.cpp @@ -19,9 +19,6 @@ #include "main_normal_mqtt.h" WiFiClient net; -MQTTClient mqttClient; - -int counter; void read_data() { @@ -87,12 +84,7 @@ void setup_normal() { read_config(); // Init I2C Serial - bool ret = init_i2c(I2C_SDA, I2C_SCL); - if (ret) { - mainlog("I2C initialized."); - } else { - mainlog("error initializing I2C"); - } + init_i2c(I2C_SDA, I2C_SCL); if (config.opMode == OPMODE_MQTT) { setup_normal_mqtt(); @@ -105,14 +97,12 @@ void setup_normal() { // setupモードに入りやすくするための処理 sectionlog("Reset to reconfig start."); remove_configure_flag_file(); - // list_dir(); disp_wait_for_reconfig(); // 設定済みフラグファイル create_configure_flag_file(); - // list_dir(); sectionlog("Reconfigure timeout. continue."); // start WiFi @@ -127,6 +117,8 @@ void setup_normal() { sectionlog("Starting HTTP server."); http_setup_normal(); + init_sensors(); + // 初期化終了時に画面表示をどうにかできるフック disp_all_initialize_complete(get_wifi_ip_addr(), config.mDNS); @@ -142,7 +134,7 @@ void loop_normal() { // WiFiが繋がってなければ意味がないので接続チェック make_sure_wifi_connected(); - mainlog("WiFi connected."); + mainlog("WiFi connected. IP=" + get_wifi_ip_addr()); read_data(); diff --git a/src/sensors/mhz19b/mhz19_uart.cpp b/src/sensors/mhz19b/mhz19_uart.cpp index 357d6e8..36432ed 100644 --- a/src/sensors/mhz19b/mhz19_uart.cpp +++ b/src/sensors/mhz19b/mhz19_uart.cpp @@ -97,7 +97,7 @@ void mhz_read_data_uart() { return; } - int co2ppm = mhz19.getCO2(false); + int co2ppm = mhz19.getCO2(); if (mhz19.errorCode == 1) { mhzGetDataTimer = millis(); } else { From 14aa17502817ab5526260b2daaedeb6e876a7b20 Mon Sep 17 00:00:00 2001 From: Yakumo Saki Date: Fri, 8 Jan 2021 13:06:19 +0900 Subject: [PATCH 4/7] new network directory --- .vscode/settings.json | 8 +++++- README.md | 9 ++++++- include/mdns_client.h | 6 +++++ include/wifi.h | 2 -- platformio.ini | 41 +------------------------------ src/main_normal.cpp | 4 +-- src/mqtt.cpp | 0 src/{ => network}/http.cpp | 0 src/{ => network}/http_normal.cpp | 0 src/{ => network}/http_setup.cpp | 0 src/network/mdns_esp32.cpp | 32 ++++++++++++++++++++++++ src/network/mdns_esp8266_mdns.cpp | 31 +++++++++++++++++++++++ src/{ => network}/wifi.cpp | 18 -------------- 13 files changed, 87 insertions(+), 64 deletions(-) create mode 100644 include/mdns_client.h delete mode 100644 src/mqtt.cpp rename src/{ => network}/http.cpp (100%) rename src/{ => network}/http_normal.cpp (100%) rename src/{ => network}/http_setup.cpp (100%) create mode 100644 src/network/mdns_esp32.cpp create mode 100644 src/network/mdns_esp8266_mdns.cpp rename src/{ => network}/wifi.cpp (89%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 77a769a..ce54a65 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,12 @@ "regex": "cpp", "tuple": "cpp", "type_traits": "cpp", - "utility": "cpp" + "utility": "cpp", + "deque": "cpp", + "list": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "initializer_list": "cpp" } } \ No newline at end of file diff --git a/README.md b/README.md index a9aa872..dffa640 100644 --- a/README.md +++ b/README.md @@ -105,12 +105,18 @@ esptool.py write_flash 0x1000 filename.bin ``` Get binary from releases page.(not every version have binary file, sorry) +## Setups I am using + +* T-Display with BME280, MHZ-19B +* NodeMCU V3 V2 ESP32 with SSD1306, BME280, MH-Z19B +* NodeMCU V3 ESP8266 with BME280, MH-Z19B + ## Boards I tested (at least once) ### ESP32 * LilyGO TTGO T-DISPLAY (ESP32 and ST7789 TFT) -* NodeMCU V3 V2 ESP32 D1MINI +* NodeMCU V3 V2 ESP32 ### ESP8266 @@ -123,6 +129,7 @@ Get binary from releases page.(not every version have binary file, sorry) ### v3.2 * Avoid using delay +* ADD: I2C scan on startup. * BUGFIX: ESP8266: I2C not working * DROP: ESP8266: ST7789 is not supported (because of Pin config) diff --git a/include/mdns_client.h b/include/mdns_client.h new file mode 100644 index 0000000..4c45188 --- /dev/null +++ b/include/mdns_client.h @@ -0,0 +1,6 @@ +#include + +// mdns.h ではないのは、 dunk mdnsのヘッダファイルが mdns.h なため + +void mdns_setup(); +void mdns_loop(); \ No newline at end of file diff --git a/include/wifi.h b/include/wifi.h index b609674..a22bb8b 100644 --- a/include/wifi.h +++ b/include/wifi.h @@ -3,5 +3,3 @@ void make_sure_wifi_connected(); void start_wifi_access_point(); String get_wifi_ip_addr(); - -bool start_mdns(String name); \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 3ff3e85..c04e459 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,46 +8,6 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -; [env:esp32dev] -; platform = espressif32 -; board = esp32dev -; framework = arduino -; board_build.mcu = esp32 -; monitor_speed = 115200 -; board_build.f_cpu = 80000000L -; lib_deps = -; joba-1/Joba_Tsl2561@^2.0.10 -; squix78/ESP8266_SSD1306@^4.1.0 -; 256dpi/MQTT@^2.4.7 -; wifwaf/MH-Z19@^1.5.2 -; sodaqmoja/Sodaq_LPS22HB@^1.0.0 -; ottowinter/ESPAsyncWebServer-esphome@^1.2.7 -; lorol/LittleFS_esp32@^1.0.0 -; seeed-studio/Grove - Barometer Sensor BME280@^1.0.2 -; bodmer/TFT_eSPI@^2.3.41 -; build_flags = -; -Os -; -DCORE_DEBUG_LEVEL=2 -; -DUSER_SETUP_LOADED=1 -; -DST7789_DRIVER=1 -; -DTFT_WIDTH=135 -; -DTFT_HEIGHT=240 -; -DTFT_MOSI=19 -; -DTFT_SCLK=18 -; -DTFT_CS=5 -; -DTFT_DC=16 -; -DTFT_RST=23 -; -DTFT_BL=4 -; -DSPI_FREQUENCY=40000000 -; -DLOAD_GLCD=1 -; -DCGRAM_OFFSET=1 -; -DLOAD_FONT2=1 -; -DLOAD_FONT4=1 -; -DLOAD_FONT6=1 -; -DLOAD_FONT7=1 -; -DLOAD_GFXFF=1 -; -DSMOOTH_FONT=1 - [env:esp12e] platform = espressif8266 board = esp12e @@ -61,5 +21,6 @@ lib_deps = sodaqmoja/Sodaq_LPS22HB@^1.0.0 ottowinter/ESPAsyncWebServer-esphome@^1.2.7 seeed-studio/Grove - Barometer Sensor BME280@^1.0.2 + mrhornsby/MDNS@^2.0.0 build_flags = -DCORE_DEBUG_LEVEL=2 diff --git a/src/main_normal.cpp b/src/main_normal.cpp index 7fc70a3..2729f5a 100644 --- a/src/main_normal.cpp +++ b/src/main_normal.cpp @@ -14,6 +14,7 @@ #include "http_normal.h" #include "config.h" #include "wifi.h" +#include "mdns_client.h" #include "i2c.h" #include "main_normal_mqtt.h" @@ -111,8 +112,7 @@ void setup_normal() { make_sure_wifi_connected(); disp_wifi_info(get_wifi_ip_addr(), config.mDNS); - sectionlog("Starting mDNS server."); - start_mdns(config.mDNS); + mdns_setup(); sectionlog("Starting HTTP server."); http_setup_normal(); diff --git a/src/mqtt.cpp b/src/mqtt.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/http.cpp b/src/network/http.cpp similarity index 100% rename from src/http.cpp rename to src/network/http.cpp diff --git a/src/http_normal.cpp b/src/network/http_normal.cpp similarity index 100% rename from src/http_normal.cpp rename to src/network/http_normal.cpp diff --git a/src/http_setup.cpp b/src/network/http_setup.cpp similarity index 100% rename from src/http_setup.cpp rename to src/network/http_setup.cpp diff --git a/src/network/mdns_esp32.cpp b/src/network/mdns_esp32.cpp new file mode 100644 index 0000000..b0b3c23 --- /dev/null +++ b/src/network/mdns_esp32.cpp @@ -0,0 +1,32 @@ +#ifdef ESP32 + +#include + +#include + +#include "global.h" +#include "config.h" +#include "log.h" + +bool start_mdns(String name) { + char n[name.length() + 1]; + name.toCharArray(n, sizeof n); + + mdnslog("mDNS responder starting"); + + if (!MDNS.begin(n)) { + mdnslog("Error setting up MDNS responder!"); + return false; + } + mdnslog("mDNS responder started name=" + name); + return true; +} + +void mdns_setup() { + sectionlog("Starting mDNS server."); + start_mdns(config.mDNS); +} + +void mdns_loop() { +} +#endif \ No newline at end of file diff --git a/src/network/mdns_esp8266_mdns.cpp b/src/network/mdns_esp8266_mdns.cpp new file mode 100644 index 0000000..c213ba5 --- /dev/null +++ b/src/network/mdns_esp8266_mdns.cpp @@ -0,0 +1,31 @@ +#ifdef ESP8266 + +#include +#include + +#include "global.h" +#include "config.h" +#include "log.h" + +bool start_mdns(String name) { + char n[name.length() + 1]; + name.toCharArray(n, sizeof n); + + mdnslog("mDNS responder starting"); + + if (!MDNS.begin(n)) { + mdnslog("Error setting up MDNS responder!"); + return false; + } + mdnslog("mDNS responder started name=" + name); + return true; +} + +void mdns_setup() { + sectionlog("Starting mDNS server."); + start_mdns(config.mDNS); +} + +void mdns_loop() { +} +#endif \ No newline at end of file diff --git a/src/wifi.cpp b/src/network/wifi.cpp similarity index 89% rename from src/wifi.cpp rename to src/network/wifi.cpp index 0a26c83..84a013f 100644 --- a/src/wifi.cpp +++ b/src/network/wifi.cpp @@ -7,13 +7,6 @@ #include #endif -// mDNS -#ifdef ESP32 -#include -#elif defined(ESP8266) -#include -#endif - #include "log.h" #include "global.h" @@ -124,14 +117,3 @@ String get_wifi_ip_addr() { } -bool start_mdns(String name) { - char n[name.length() + 1]; - name.toCharArray(n, sizeof n); - - if (!MDNS.begin(n)) { - mdnslog("Error setting up MDNS responder!"); - return false; - } - mdnslog("mDNS responder started"); - return true; -} \ No newline at end of file From 04cd8f8067f6faed0e495794419689fe3a38b021 Mon Sep 17 00:00:00 2001 From: Yakumo Saki Date: Fri, 8 Jan 2021 13:07:36 +0900 Subject: [PATCH 5/7] fix warning --- src/display/display_st7789_mock.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/display/display_st7789_mock.cpp b/src/display/display_st7789_mock.cpp index 127164d..2fc3d13 100644 --- a/src/display/display_st7789_mock.cpp +++ b/src/display/display_st7789_mock.cpp @@ -11,13 +11,13 @@ void disp_st7789_normal_startup_screen(String product_long) {} void disp_st7789_wait_for_reconfig_init() {} void disp_st7789_wait_for_reconfig_bar(int now, const int max) {} void disp_st7789_wifi_starting(int wait_print_row) {} -void disp_st7789_all_initialize_complete(String ip, String mdns) {} -void disp_st7789_sensor_value(disp_values_t new_values, disp_values_t last_values) {} -void disp_st7789_power_off() {} +void disp_st7789_all_initialize_complete(String ip, String mdns) {}; +void disp_st7789_sensor_value(disp_values_t new_values, disp_values_t last_values) {}; +void disp_st7789_power_off() {}; -void disp_st7789_wifi_error() {} +void disp_st7789_wifi_error() {}; -String disp_st7789_set_brightness(int brightness) {} +String disp_st7789_set_brightness(int brightness) { return ""; } /** * 液晶のON/OFFを設定する From 274b54148b8858ceb758f9194296d5321aeeb8ed Mon Sep 17 00:00:00 2001 From: Yakumo Saki Date: Fri, 8 Jan 2021 13:49:21 +0900 Subject: [PATCH 6/7] mhz-19b verify before sensor read --- src/sensors/mhz19b/mhz19_uart.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sensors/mhz19b/mhz19_uart.cpp b/src/sensors/mhz19b/mhz19_uart.cpp index 36432ed..8125d34 100644 --- a/src/sensors/mhz19b/mhz19_uart.cpp +++ b/src/sensors/mhz19b/mhz19_uart.cpp @@ -6,6 +6,8 @@ #include "sensors/mhz19_main.h" #include "sensors/mhz19_util.h" +const int MHZ_RESULT_OK = 1; + // 400ppmの校正(ABC)を行う。これをするには、20分以上外気に晒し続ける必要がある。 // 終了後は false に戻す。 bool AUTO_BASELINE_CORRECTION = false; @@ -64,7 +66,6 @@ void mhz_setup_uart() { mhzlog("Wait for MHZ UART serial"); while(!mhzSerial); - mhzlog("MHZ-19B begin()"); mhz19.begin(mhzSerial); mhzlog("setRange()"); @@ -97,6 +98,12 @@ void mhz_read_data_uart() { return; } + mhz19.verify(); + if (mhz19.errorCode == 1) { + printErrorCode(); + mhzlog("MH-Z19B connection failed. abort."); + } + int co2ppm = mhz19.getCO2(); if (mhz19.errorCode == 1) { mhzGetDataTimer = millis(); From 345d1a8293c177b31c5e078e9b3b85d7f5c49dc9 Mon Sep 17 00:00:00 2001 From: Yakumo Saki Date: Fri, 8 Jan 2021 14:00:30 +0900 Subject: [PATCH 7/7] move files --- platformio.ini | 45 ++++++++++++++++++- src/{model_depends => }/config_esp32.cpp | 0 src/{model_depends => }/config_esp8266.cpp | 0 .../http_normal_esp32.cpp | 0 .../http_normal_esp8266.cpp | 0 .../http_setup_esp32.cpp | 0 .../http_setup_esp8266.cpp | 0 7 files changed, 44 insertions(+), 1 deletion(-) rename src/{model_depends => }/config_esp32.cpp (100%) rename src/{model_depends => }/config_esp8266.cpp (100%) rename src/{model_depends => network}/http_normal_esp32.cpp (100%) rename src/{model_depends => network}/http_normal_esp8266.cpp (100%) rename src/{model_depends => network}/http_setup_esp32.cpp (100%) rename src/{model_depends => network}/http_setup_esp8266.cpp (100%) diff --git a/platformio.ini b/platformio.ini index c04e459..2e0e3ce 100644 --- a/platformio.ini +++ b/platformio.ini @@ -7,6 +7,49 @@ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html +[platformio] +description="EnvBoyX" + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +board_build.mcu = esp32 +monitor_speed = 115200 +board_build.f_cpu = 80000000L +;board_build.f_cpu = 160000000L +;board_build.f_cpu = 240000000L +lib_deps = + joba-1/Joba_Tsl2561@^2.0.10 + squix78/ESP8266_SSD1306@^4.1.0 + 256dpi/MQTT@^2.4.7 + wifwaf/MH-Z19@^1.5.2 + sodaqmoja/Sodaq_LPS22HB@^1.0.0 + ottowinter/ESPAsyncWebServer-esphome@^1.2.7 + lorol/LittleFS_esp32@^1.0.0 + seeed-studio/Grove - Barometer Sensor BME280@^1.0.2 +build_flags = + -Os + -DCORE_DEBUG_LEVEL=2 + -DUSER_SETUP_LOADED=1 + -DST7789_DRIVER=1 + -DTFT_WIDTH=135 + -DTFT_HEIGHT=240 + -DTFT_MOSI=19 + -DTFT_SCLK=18 + -DTFT_CS=5 + -DTFT_DC=16 + -DTFT_RST=23 + -DTFT_BL=4 + -DSPI_FREQUENCY=40000000 + -DLOAD_GLCD=1 + -DCGRAM_OFFSET=1 + -DLOAD_FONT2=1 + -DLOAD_FONT4=1 + -DLOAD_FONT6=1 + -DLOAD_FONT7=1 + -DLOAD_GFXFF=1 + -DSMOOTH_FONT=1 [env:esp12e] platform = espressif8266 @@ -21,6 +64,6 @@ lib_deps = sodaqmoja/Sodaq_LPS22HB@^1.0.0 ottowinter/ESPAsyncWebServer-esphome@^1.2.7 seeed-studio/Grove - Barometer Sensor BME280@^1.0.2 - mrhornsby/MDNS@^2.0.0 build_flags = + -Os -DCORE_DEBUG_LEVEL=2 diff --git a/src/model_depends/config_esp32.cpp b/src/config_esp32.cpp similarity index 100% rename from src/model_depends/config_esp32.cpp rename to src/config_esp32.cpp diff --git a/src/model_depends/config_esp8266.cpp b/src/config_esp8266.cpp similarity index 100% rename from src/model_depends/config_esp8266.cpp rename to src/config_esp8266.cpp diff --git a/src/model_depends/http_normal_esp32.cpp b/src/network/http_normal_esp32.cpp similarity index 100% rename from src/model_depends/http_normal_esp32.cpp rename to src/network/http_normal_esp32.cpp diff --git a/src/model_depends/http_normal_esp8266.cpp b/src/network/http_normal_esp8266.cpp similarity index 100% rename from src/model_depends/http_normal_esp8266.cpp rename to src/network/http_normal_esp8266.cpp diff --git a/src/model_depends/http_setup_esp32.cpp b/src/network/http_setup_esp32.cpp similarity index 100% rename from src/model_depends/http_setup_esp32.cpp rename to src/network/http_setup_esp32.cpp diff --git a/src/model_depends/http_setup_esp8266.cpp b/src/network/http_setup_esp8266.cpp similarity index 100% rename from src/model_depends/http_setup_esp8266.cpp rename to src/network/http_setup_esp8266.cpp