diff --git a/README.md b/README.md index eb8992f..78291c6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## flora -This arduino sketch implements an ESP32 BLE client for XIaomi Mi Flora Plant sensors, pushing the meaasurements to an MQTT server. +This arduino sketch implements an ESP32 BLE client for Xiaomi Mi Flora Plant sensors, pushing the measurements to an MQTT server. ## Technical requirements diff --git a/flora/flora.ino b/flora/flora.ino index 1cda8a5..21d399e 100644 --- a/flora/flora.ino +++ b/flora/flora.ino @@ -206,7 +206,7 @@ bool readFloraDataCharacteristic(BLERemoteService* floraService, String baseTopi Serial.print("-- Conductivity: "); Serial.println(conductivity); - if (temperature > 200) { + if (temperature > 100 || temperature < -100) { Serial.println("-- Unreasonable values received, skip publish"); return false; } @@ -215,12 +215,27 @@ bool readFloraDataCharacteristic(BLERemoteService* floraService, String baseTopi snprintf(buffer, 64, "%f", temperature); client.publish((baseTopic + "temperature").c_str(), buffer); + char state[] = "{temperature:"; + strcat(state,buffer); + delay(100); snprintf(buffer, 64, "%d", moisture); client.publish((baseTopic + "moisture").c_str(), buffer); + strcat(state,",moisture:"); + strcat(state,buffer); + delay(100); snprintf(buffer, 64, "%d", light); client.publish((baseTopic + "light").c_str(), buffer); + strcat(state,",light:"); + strcat(state,buffer); + delay(100); snprintf(buffer, 64, "%d", conductivity); client.publish((baseTopic + "conductivity").c_str(), buffer); + strcat(state,",conductivity:"); + strcat(state,buffer); + strcat(state,"}"); + delay(100); + client.publish((baseTopic + "state").c_str(), state); + delay(100); return true; }