diff --git a/WifiControlSensor/MQTT.h b/WifiControlSensor/MQTT.h index 4eca9ad..631cbe2 100644 --- a/WifiControlSensor/MQTT.h +++ b/WifiControlSensor/MQTT.h @@ -7,6 +7,7 @@ int MqttIsConnected(); int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname); int MqttPublish(double temp, double pressure); int MqttDhtPublish(float temp, float humidity); +int MqttDryPublish(int dry); void MqttCheckSubscription(); void MqttChangeGpioValue(int gpio, int value); bool MqttIsConfigured(); diff --git a/WifiControlSensor/MQTT.ino b/WifiControlSensor/MQTT.ino index be1ad66..39405b6 100644 --- a/WifiControlSensor/MQTT.ino +++ b/WifiControlSensor/MQTT.ino @@ -8,6 +8,7 @@ Adafruit_MQTT_Publish *mqtt_temp; Adafruit_MQTT_Publish *mqtt_pressure; Adafruit_MQTT_Publish *mqtt_dht_temp; Adafruit_MQTT_Publish *mqtt_dht_humidity; +Adafruit_MQTT_Publish *mqtt_dry; #define NB_ELEMENTS(x) (sizeof(x)/ sizeof(x[0])) #define FEED_MAX_SIZE 96 @@ -17,6 +18,7 @@ Adafruit_MQTT_Publish *mqtt_dht_humidity; #define PRESSURE_FEED_FORMAT "/feeds/%s/%s/pressure" #define TEMPERATURE_DHT_FEED_FORMAT "/feeds/%s/%s/dht/temperature" #define HUMIDITY_DHT_FEED_FORMAT "/feeds/%s/%s/dht/humidity" +#define DRY_FEED_FORMAT "/feeds/%s/%s/dry" // Should have less that MAXSUBSCRIPTIONS elements // MAXSUBSCRIPTIONS is defined is Adafruit_mqtt.h @@ -46,6 +48,7 @@ int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname) mqtt_dht_humidity = MqttCreatePublisher(HUMIDITY_DHT_FEED_FORMAT, user, mqttId); mqtt_temp = MqttCreatePublisher(TEMPERATURE_FEED_FORMAT, user, mqttId); mqtt_pressure = MqttCreatePublisher(PRESSURE_FEED_FORMAT, user, mqttId); + mqtt_dry = MqttCreatePublisher(DRY_FEED_FORMAT, user, mqttId); for (uint i = 0 ; i < NB_ELEMENTS(gpioWatched) && i < MAXSUBSCRIPTIONS; i++) { snprintf(GPIO_FEED[i], FEED_MAX_SIZE, GPIO_FEED_FORMAT, user, mqttId, gpioWatched[i]); @@ -114,6 +117,14 @@ int MqttPublish(double temp, double pressure) { return 0; } +int MqttDryPublish(int dry) { + if (MqttConnect() == 0) { + SKETCH_DEBUG_PRINTLN("publishing dry!"); + mqtt_dry->publish((dry*100)/1024); + } + return 0; +} + int MqttDhtPublish(float temp, float humidity) { if (MqttConnect() == 0) { SKETCH_DEBUG_PRINTLN("publishing DHT!"); diff --git a/WifiControlSensor/WebServer.ino b/WifiControlSensor/WebServer.ino index 7911513..cb758f3 100644 --- a/WifiControlSensor/WebServer.ino +++ b/WifiControlSensor/WebServer.ino @@ -14,6 +14,9 @@ void WebHandleRoot() { #ifdef CONFIG_ENABLE_DHT "Temperature DHT " + String(dhtTemp, 0) + "C
" "Humidity DHT " + String(dhtHumidity, 0) + "%
" +#endif +#ifdef CONFIG_ENABLE_DRY_SENSOR + "Dryness " + String((dryness*100)/1024) + "%
" #endif "" #ifdef CONFIG_WEB_CONTROLLED_GPIO @@ -147,7 +150,7 @@ void WebHandleOTA() { SKETCH_DEBUG_PRINTLN("Boot mode Set to OTA"); EepromSaveBootMode(BOOTMODE_OTA); server.send(200, "text/html", "

OTA Mode set


" - "You can reboot now" + "You can reboot now
" "Reboot
"); } diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index 902631c..db624ee 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -139,7 +139,7 @@ void OTASetup() { SKETCH_DEBUG_PRINTLN("\nEnd"); }); ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) { - SKETCH_DEBUG_PRINTF("Progress: %u%%\r", (progress / (total / 100))); + SKETCH_DEBUG_PRINTF("Progress: %u%%\n", (progress / (total / 100))); }); ArduinoOTA.onError([](ota_error_t error) { SKETCH_DEBUG_PRINTF("Error[%u]: ", error); @@ -275,6 +275,7 @@ void loop() { SKETCH_DEBUG_PRINT("Current dryness "); SKETCH_DEBUG_PRINT((dryness*100)/1024); SKETCH_DEBUG_PRINTLN("%"); + MqttDryPublish(dryness); } nbCycle = 0; }