Added decode for battery level and combined temperature/humidity (#265)

This commit is contained in:
f-reiling authored and Florian committed 2018-09-09 21:54:21 +02:00
1 parent e0fe3b721b
commit f7eb0b1921
2 files changed
+36

No files matched your search

+35
View File
@@ -364,6 +364,12 @@ boolean process_data(int offset, char * rest_data, char * mac_adress){
String mactopic(mac_adress); String mactopic(mac_adress);
mactopic = subjectBTtoMQTT + mactopic; mactopic = subjectBTtoMQTT + mactopic;
// second value
char val2[12];
String mactopic2(mac_adress);
mactopic2 = subjectBTtoMQTT + mactopic2;
bool hasTopic2 = false;
// Mi flora provides tem(perature), (earth) moi(sture), fer(tility) and lux (illuminance) // Mi flora provides tem(perature), (earth) moi(sture), fer(tility) and lux (illuminance)
// Mi Jia provides tem(perature) and hum(idity) // Mi Jia provides tem(perature) and hum(idity)
@@ -391,11 +397,40 @@ boolean process_data(int offset, char * rest_data, char * mac_adress){
mactopic = mactopic + subjectBTtoMQTTmoi; mactopic = mactopic + subjectBTtoMQTTmoi;
dtostrf(value,0,0,val); dtostrf(value,0,0,val);
break; break;
case 'a' : // batteryLevel
mactopic = mactopic + subjectBTtoMQTTbatt;
dtostrf(value,0,0,val);
break;
case 'd' : // temp+hum
char tempAr[8];
// humidity
memcpy(tempAr, data, 4);
tempAr[4] = '\0';
value = strtol(tempAr, NULL, 16);
if (value > 65000) value = value - 65535;
dtostrf(value/10,3,1,val); // hum has to be divided by 10
trc(val);
// temperature
memcpy(tempAr, &data[4], 4);
tempAr[4] = '\0';
value = strtol(tempAr, NULL, 16);
if (value > 65000) value = value - 65535;
dtostrf(value/10,3,1,val2); // hum has to be divided by 10
trc(val2);
mactopic = mactopic + subjectBTtoMQTThum;
mactopic2 = mactopic2 + subjectBTtoMQTTtem;
hasTopic2 = true;
break;
default: default:
trc("can't read values"); trc("can't read values");
return false; return false;
} }
client.publish((char *)mactopic.c_str(),val); client.publish((char *)mactopic.c_str(),val);
if (hasTopic2){
client.publish((char *)mactopic2.c_str(),val2);
}
trc(val); trc(val);
return true; return true;
} }
+1
View File
@@ -32,6 +32,7 @@
#define subjectBTtoMQTTmoi "/moi" #define subjectBTtoMQTTmoi "/moi"
#define subjectBTtoMQTTfer "/fer" #define subjectBTtoMQTTfer "/fer"
#define subjectBTtoMQTTlux "/lux" #define subjectBTtoMQTTlux "/lux"
#define subjectBTtoMQTTbatt "/batt"
#define subjectBTtoMQTTservicedata "/servicedata" #define subjectBTtoMQTTservicedata "/servicedata"
#define TimeBtw_Read 55555 //define the time between 2 scans #define TimeBtw_Read 55555 //define the time between 2 scans
#define Scan_duration 10 //define the time for a scan #define Scan_duration 10 //define the time for a scan