diff --git a/Software/co2ampel/co2ampel.h b/Software/co2ampel/co2ampel.h index 6675b1a..c258700 100644 --- a/Software/co2ampel/co2ampel.h +++ b/Software/co2ampel/co2ampel.h @@ -9,6 +9,8 @@ #ifndef CO2AMPEL_H #define CO2AMPEL_H +#include + void scd30ForceRecalibration(uint16_t concentration); void setThresholdGreen(uint16_t th); void setConfig(String& jsonString); diff --git a/Software/co2ampel/co2ampel.ino b/Software/co2ampel/co2ampel.ino index 71085ba..f3c3395 100644 --- a/Software/co2ampel/co2ampel.ino +++ b/Software/co2ampel/co2ampel.ino @@ -141,13 +141,14 @@ void startCalibration() { } } + /**************************** setup() *************************************************/ void setup() { Serial.begin(115200); setupLED(); - + // init IOs #ifdef GPIO_SWITCH pinMode(GPIO_SWITCH, INPUT); @@ -161,6 +162,7 @@ void setup() Serial.println("Start CO2-Ampel"); configStatus=configManager.readConfig("/config.json"); + ledSetBrightnes(configManager.getUintValue("led_brightness", LED_BRIGHTNES)/100.0); // check if mqtt credentials are set if(configStatus==0) { diff --git a/Software/co2ampel/config.h b/Software/co2ampel/config.h index e289113..61cd086 100644 --- a/Software/co2ampel/config.h +++ b/Software/co2ampel/config.h @@ -73,7 +73,7 @@ enum Color {GREEN, YELLOW, RED, BLUE, DARK, WHITE, GREEN2, YELLOW2, RED2}; #define NUMPIXELS 14 #define GPIO_GREEN 12 #define GPIO_RED 0 -#define LED_BRIGHTNES 0.5; +#define LED_BRIGHTNES 59 // % (0=dark, 100=full) overriden by led_brightness from config.json //SCD30 #define GPIO_SCD30_RDY 13 #define SCD30_TEMP_OFFSET 7.0 diff --git a/Software/co2ampel/data/config.json b/Software/co2ampel/data/config.json index 127447a..b08cf5a 100644 --- a/Software/co2ampel/data/config.json +++ b/Software/co2ampel/data/config.json @@ -17,5 +17,6 @@ "th_yellow_high": 1500, "th_red": 2000, "selftest_buzzer": 0, + "led_brightness": 50, "version": "1" } diff --git a/Software/co2ampel/led.cpp b/Software/co2ampel/led.cpp index 901c94c..3ed8207 100644 --- a/Software/co2ampel/led.cpp +++ b/Software/co2ampel/led.cpp @@ -1,8 +1,10 @@ #include "led.h" +double ledBrightnes; + #ifdef PCBV2 -Adafruit_NeoPixel led1 = Adafruit_NeoPixel(NUMPIXELS, GPIO_GREEN, NEO_GRB + NEO_KHZ800); -Adafruit_NeoPixel led2 = Adafruit_NeoPixel(NUMPIXELS, GPIO_RED, NEO_GRB + NEO_KHZ800); +Adafruit_NeoPixel led1 = Adafruit_NeoPixel(NUMPIXELS, GPIO_GREEN, NEO_GRB + NEO_KHZ400); +Adafruit_NeoPixel led2 = Adafruit_NeoPixel(NUMPIXELS, GPIO_RED, NEO_GRB + NEO_KHZ400); #endif /* CO2 Ampel - PCB v2.0 + v1.0 @@ -12,8 +14,10 @@ Adafruit_NeoPixel led2 = Adafruit_NeoPixel(NUMPIXELS, GPIO_RED, NEO_GRB + NEO_KH License: MIT */ + + #ifdef PCBV1 -void setupLED() { +void setupLED(ConfigManager &configManager) { pinMode(GPIO_GREEN, OUTPUT); pinMode(GPIO_YELLOW, OUTPUT); pinMode(GPIO_RED, OUTPUT); @@ -47,7 +51,8 @@ void setupLED() { } void ledSetColor(Color color) { - double brightnes=LED_BRIGHTNES; + + double brightnes=ledBrightnes; int switchState = digitalRead(GPIO_SWITCH); if(!switchState) brightnes=0; @@ -91,3 +96,7 @@ void ledBlink(Color c1, Color c2, uint32_t time) } ledSetColor(DARK); } + +void ledSetBrightnes(double brightness) { + ledBrightnes = brightness; +} diff --git a/Software/co2ampel/led.h b/Software/co2ampel/led.h index fd09aba..f6f34f6 100644 --- a/Software/co2ampel/led.h +++ b/Software/co2ampel/led.h @@ -16,5 +16,6 @@ void setupLED(); void ledSetColor(Color color); void ledBlink(Color c1, Color c2, uint32_t time); +void ledSetBrightnes(double brightness); #endif diff --git a/Software/co2ampel/mqtt.cpp b/Software/co2ampel/mqtt.cpp index 082269c..ccb53c3 100644 --- a/Software/co2ampel/mqtt.cpp +++ b/Software/co2ampel/mqtt.cpp @@ -128,5 +128,25 @@ void mqttCallback(char* topic, byte* payload, unsigned int length) { WiFi.disconnect(true); // disconnect and delete credentials in flash while (1); // freeze and reboot due to watchdog } + } else if (String(topic) == "config/"+mqttUsername+"/ota") { + updateFirmware(messageTemp.c_str()); } } + +void updateFirmware(const char* url) { + Serial.println("Start Firmware Update"); + t_httpUpdate_return ret = ESPhttpUpdate.update( wifiClient, url ); + switch(ret) { + case HTTP_UPDATE_FAILED: + Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); + break; + + case HTTP_UPDATE_NO_UPDATES: + Serial.println("HTTP_UPDATE_NO_UPDATES"); + break; + + case HTTP_UPDATE_OK: + Serial.println("HTTP_UPDATE_OK"); + break; + } +} diff --git a/Software/co2ampel/mqtt.h b/Software/co2ampel/mqtt.h index b227772..97383ed 100644 --- a/Software/co2ampel/mqtt.h +++ b/Software/co2ampel/mqtt.h @@ -23,5 +23,6 @@ void loopMQTT(ConfigManager &configManager); void setupMQTT(ConfigManager &configManager); void publishValues(ConfigManager &configManager, uint16_t co2, double hum ,double temp, double pressure, double temp2, Color color, float RssI, uint32_t runtime); void mqttCallback(char* topic, byte* payload, unsigned int length); +void updateFirmware(const char* url); #endif