diff --git a/Code/ESP32_communication/Two-way/ESP32_master/ESP32_master.ino b/Code/ESP32_communication/Two-way/ESP32_master/ESP32_master.ino index 114b0f7d775a92db878ea734c478e09c15b2699f..9aa93ca7b852270142e66c8e6e1ed7f41e89d82f 100644 --- a/Code/ESP32_communication/Two-way/ESP32_master/ESP32_master.ino +++ b/Code/ESP32_communication/Two-way/ESP32_master/ESP32_master.ino @@ -8,7 +8,9 @@ String success; // Define variables to store BME280 readings to be sent String strdata = ""; String valdata = ""; +String quedata = ""; int count = 0; +double memory=0; // Define variables to store incoming readings String incomingStr = ""; @@ -22,6 +24,7 @@ typedef struct struct_message { String StrD; double ValD; String DebugM; + String QueM; } struct_message; // Create a struct_message to hold incoming sensor readings @@ -90,18 +93,27 @@ void loop() strdata += char(inChar); delay(10); count +=1; - if (count == 3){ + if (count == 3 && !isDigit(inChar)){ sentData.StrD = strdata; Serial.println(sentData.StrD); } if (isDigit(inChar) || inChar == '.' || inChar == '-'){ valdata += char(inChar); } + if (inChar == '?'){ + quedata += char(inChar); + sentData.QueM = quedata; + } if (inChar == '\n'){ //after message is sent - sentData.ValD = valdata.toDouble(); - Serial.println(sentData.ValD); - + if (valdata!=""){ + // memory = valdata.toDouble(); + sentData.ValD = valdata.toDouble(); + valdata = ""; + Serial.println(sentData.ValD); + sentData.QueM = ""; + } + esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &sentData, sizeof(sentData)); // esp_now_send(RxMACaddress, (uint8_t *) &sentData, sizeof(sentData)); //------------------------------------------------------------------------------------- @@ -110,7 +122,8 @@ void loop() //------------------------------------------------------------------------------------- delay(500); strdata = ""; - valdata = ""; + // valdata = ""; + quedata = ""; count = 0; }