From 33a7f7915cb42ffa1b67627db20d442f16f88105 Mon Sep 17 00:00:00 2001
From: Zhaoliang <zhz03@g.ucla.edu>
Date: Fri, 15 Oct 2021 17:31:24 -0700
Subject: [PATCH] try to query the variables but failed

---
 .../Two-way/ESP32_master/ESP32_master.ino     | 23 +++++++++++++++----
 1 file changed, 18 insertions(+), 5 deletions(-)

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 114b0f7..9aa93ca 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;
   }
   
-- 
GitLab