Return dryness to http and mqtt

This commit is contained in:
Mathieu Maret 2016-06-04 18:45:11 +02:00
parent 4c09dcbb24
commit 5db953072d
4 changed files with 18 additions and 2 deletions

View File

@ -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();

View File

@ -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!");

View File

@ -14,6 +14,9 @@ void WebHandleRoot() {
#ifdef CONFIG_ENABLE_DHT
"Temperature DHT " + String(dhtTemp, 0) + "C<br/>"
"Humidity DHT " + String(dhtHumidity, 0) + "%<br/>"
#endif
#ifdef CONFIG_ENABLE_DRY_SENSOR
"Dryness " + String((dryness*100)/1024) + "%<br/>"
#endif
"</fieldset>"
#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", "<h1>OTA Mode set</h1><br/>"
"You can reboot now"
"You can reboot now<br/>"
"<a href=\"/reboot\">Reboot</a><br/>");
}

View File

@ -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;
}