sometimes strange partial response are given by serial
Avoid publishing them
This commit is contained in:
1 parent
642c0938f2
commit
37842bd0c4
1 file changed
+10
-7
+10
-7
@@ -28,6 +28,7 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht
|
|||||||
#define STRING_MSG "OK+DISC:"
|
#define STRING_MSG "OK+DISC:"
|
||||||
#define QUESTION_MSG "AT+DISI?"
|
#define QUESTION_MSG "AT+DISI?"
|
||||||
#define RESPONSE_MSG "OK+DISIS"
|
#define RESPONSE_MSG "OK+DISIS"
|
||||||
|
#define RESP_END_MSG "OK+DISCE"
|
||||||
#define SETUP_MSG "OK+RESET"
|
#define SETUP_MSG "OK+RESET"
|
||||||
#define TimeBtw_Read 10000
|
#define TimeBtw_Read 10000
|
||||||
|
|
||||||
@@ -47,16 +48,17 @@ void setupBT() {
|
|||||||
|
|
||||||
boolean BTtoMQTT() {
|
boolean BTtoMQTT() {
|
||||||
while (softserial.available() > 0) {
|
while (softserial.available() > 0) {
|
||||||
|
String discResult = softserial.readString();
|
||||||
|
if (discResult.indexOf(STRING_MSG)>=0){
|
||||||
|
discResult.replace(RESPONSE_MSG,"");
|
||||||
|
discResult.replace(RESP_END_MSG,"");
|
||||||
|
float device_number = discResult.length()/78.0;
|
||||||
|
if (device_number == (int)device_number){ // to avoid publishing partial values we detect if the serial data as been fully read = a multiple of 78
|
||||||
|
trc(F("Sending BT data to MQTT"));
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
yield();
|
yield();
|
||||||
#endif
|
#endif
|
||||||
|
for (int i=0;i<(int)device_number;i++){
|
||||||
String discResult = softserial.readString();
|
|
||||||
if (discResult.indexOf(STRING_MSG)>=0){
|
|
||||||
trc(F("Sending BT data to MQTT"));
|
|
||||||
discResult.replace(RESPONSE_MSG,"");
|
|
||||||
int device_number = discResult.length()/78;
|
|
||||||
for (int i=0;i<device_number;i++){
|
|
||||||
String onedevice = discResult.substring(0,78);
|
String onedevice = discResult.substring(0,78);
|
||||||
onedevice.replace(STRING_MSG,"");
|
onedevice.replace(STRING_MSG,"");
|
||||||
/*String company = onedevice.substring(0,8);
|
/*String company = onedevice.substring(0,8);
|
||||||
@@ -74,6 +76,7 @@ boolean BTtoMQTT() {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (discResult.indexOf(SETUP_MSG)>=0)
|
if (discResult.indexOf(SETUP_MSG)>=0)
|
||||||
{
|
{
|
||||||
trc(F("Connection OK to HM-10"));
|
trc(F("Connection OK to HM-10"));
|
||||||
|
|||||||
Reference in new issue
Block a user