From 5c246a9fd75c2f0bf070be38f249b43f7a7896c2 Mon Sep 17 00:00:00 2001 From: Torben Egmose Date: Mon, 5 Apr 2021 01:01:04 +0200 Subject: split --- platformio.ini | 40 ++++++++++++++++++++++++++++------------ src/main.cpp | 34 +++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/platformio.ini b/platformio.ini index c4f0d94..e9ab053 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,23 +8,39 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:esp01_1m] +[env:sensor] +build_flags = + !echo "'-D PROJECT=\"$(basename "$(pwd)")\"'" platform = espressif8266 board = esp01_1m framework = arduino board_build.flash_mode = dout - lib_deps = - LiquidCrystal_I2C - WifWaf/MH-Z19 - adafruit/Adafruit Unified Sensor - adafruit/Adafruit AHTX0 - tzapu/WiFiManager - PubSubClient - -;upload_port = /dev/ttyUSB0 + LiquidCrystal_I2C + WifWaf/MH-Z19 + adafruit/Adafruit Unified Sensor + adafruit/Adafruit AHTX0 + PubSubClient upload_protocol = espota -upload_port = 172.19.1.209 -upload_flags= -P 36286 +upload_port = 172.19.5.106 +upload_flags = -P 36286 +[env:display] +build_flags = + !echo "'-D PROJECT=\"$(basename "$(pwd)")\"'" + -D mydisplay=1 +platform = espressif8266 +board = esp01_1m +framework = arduino +board_build.flash_mode = dout +lib_deps = + LiquidCrystal_I2C + WifWaf/MH-Z19 + adafruit/Adafruit Unified Sensor + adafruit/Adafruit AHTX0 + PubSubClient + +upload_protocol = espota +upload_port = 172.19.5.205 +upload_flags = -P 36286 diff --git a/src/main.cpp b/src/main.cpp index 04b765b..aee48ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -12,7 +11,7 @@ WiFiManager wm; #include const char* debug = "debug"; -const char* server = "172.19.1.10"; +const char* server = "mqtt.iot"; const char* s_will = "died"; const char* s_ready = "ready"; const char* s_sens = "zero MHZ"; @@ -29,6 +28,9 @@ bool pubsub = false; MHZ19 myMHZ19; Adafruit_AHTX0 aht; // x38 + +#if defined mydisplay +#include LiquidCrystal_I2C lcd(0x27, 20, 4); #define DEGREE_SYMBOL 0xDF //degree symbol from LCD ROM @@ -185,12 +187,17 @@ void numprint(int num) { } } +#endif + + void callback(char* topic, byte* payload, unsigned int length) { if(topic[14] == 's') { if((char)payload[0] == 'r' && (char)payload[1] == 'e' && (char)payload[2] == 's' && (char)payload[3] == 'e' && (char)payload[4] == 't') { +#if defined mydisplay lcd.setCursor(0,1); lcd.print(F("reset")); +#endif WiFi.forceSleepBegin(); ESP.wdtFeed(); ESP.restart(); @@ -233,34 +240,36 @@ void setup() { if(wm.autoConnect("CO2sensor")){ pubsub = true; client.connect(MAC_char, sta, 0, false, s_will); - client.publish(debug,MAC_char); client.subscribe(sta,1); - - client.publish(sta,__FILE__); - IPAddress ip = WiFi.localIP(); - sprintf(buffer,"%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); - client.publish(sta,buffer); + client.publish(debug,MAC_char); + IPAddress ip = WiFi.localIP(); sprintf(buffer,"%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); client.publish(sta,buffer); + client.publish(sta, server); + client.publish(sta, PROJECT); client.publish(sta,s_ready); } Wire.begin(0,2); // 00-sda,02-sdl +#if defined mydisplay lcd.init(); lcd.noBacklight(); lcd.clear(); lcd.backlight(); - lcd.print(F("CO2 monitor starting")); +#endif myMHZ19.begin(Serial); myMHZ19.setRange(2000); myMHZ19.autoCalibration(false); +#if defined mydisplay lcd.setCursor(0,1); lcd.print(F("CO2 sensor started")); +#endif sensor = aht.begin(); +#if defined mydisplay lcd.setCursor(0,2); lcd.print(F("aht sensor started")); @@ -274,6 +283,7 @@ void setup() { lcd.setCursor(0,3); lcd.print(F("lcd font loaded")); +#endif ESP.wdtEnable(WDTO_8S); tick = millis(); @@ -316,12 +326,16 @@ void loop() { if(sec == 5) { if(clear) { +#if defined mydisplay lcd.clear(); +#endif clear = false; } value = myMHZ19.getCO2(); +#if defined mydisplay numprint(value); +#endif if(pubsub) { sprintf(buffer,"%d", (int) value); client.publish(co,buffer); @@ -338,6 +352,7 @@ void loop() { client.publish(hum,buffer); } +#if defined mydisplay lcd.setCursor(0,2); lcd.print(temp.temperature); lcd.print(F(" ")); @@ -351,6 +366,7 @@ void loop() { lcd.print(F(" ")); lcd.write(6); lcd.print(F("2% ")); +#endif } } } -- cgit v1.2.3