correct impossibility to read value with HM10

#281 and make the code more flexible (deduct an offset from a key value instead of fixed offset)
This commit is contained in:
Florian committed 2018-10-13 21:44:23 +02:00
1 parent 4b9ae94d05
commit 69e0428084
2 files changed
+30 -12

No files matched your search

+8
View File
@@ -881,6 +881,14 @@ void revert_hex_data(char * in, char * out, int l){
out[l-1] = '\0';
}
int strpos(char *haystack, char *needle) //from @miere https://stackoverflow.com/users/548685/miere
{
char *p = strstr(haystack, needle);
if (p)
return p - haystack;
return -1;
}
bool to_bool(String const& s) { // thanks Chris Jester-Young from stackoverflow
return s != "0";
}
+22 -12
View File
@@ -112,13 +112,18 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht
if (strstr(serviceDataUUID.toString().c_str(),"fe95") != NULL){
trc("Processing BLE device data");
int pos = -1;
pos = strpos(service_data,"209800");
if (strstr(service_data,"209800") != NULL) {
trc("mi flora data reading");
boolean result = process_data(-22,service_data,mac);
boolean result = process_data(pos - 24,service_data,mac);
}
pos = -1;
pos = strpos(service_data,"20aa01");
if (strstr(service_data,"20aa01") != NULL){
trc("mi jia data reading");
boolean result = process_data(-24,service_data,mac);
boolean result = process_data(pos - 26,service_data,mac);
}
}
}
@@ -257,16 +262,21 @@ boolean BTtoMQTT() {
trc(Service_data);
mactopic = subjectBTtoMQTT + String(d[0].extract) + subjectBTtoMQTTservicedata;
client.publish((char *)mactopic.c_str(),(char *)(Service_data).c_str());
if (strcmp(d[4].extract, "fe95") == 0)
if (strstr(d[5].extract,"209800") != NULL) {
trc("mi flora data reading");
boolean result = process_data(0,d[5].extract,d[0].extract);
}
if (strstr(d[5].extract,"20aa01") != NULL){
trc("mi jia data reading");
boolean result = process_data(-2,d[5].extract,d[0].extract);
}
return true;
if (strcmp(d[4].extract, "fe95") == 0) {
int pos = -1;
pos = strpos(d[5].extract,"209800");
if (pos != -1) {
trc("mi flora data reading");
boolean result = process_data(pos - 38,(char *)Service_data.c_str(),d[0].extract);
}
pos = -1;
pos = strpos(d[5].extract,"20aa01");
if (pos != -1){
trc("mi jia data reading");
boolean result = process_data(pos - 40,(char *)Service_data.c_str(),d[0].extract);
}
return true;
}
}
}
}