diff --git a/Code/ESP32_communication/simple_test/ESP32_master/ESP32_master.ino b/Code/ESP32_communication/simple_test/ESP32_master/ESP32_master.ino index d06a0bbcf0b1d8df5fad759264b5c998e864b6f3..de148c205f465cd40814f540d6d75aad4ac1d3d1 100644 --- a/Code/ESP32_communication/simple_test/ESP32_master/ESP32_master.ino +++ b/Code/ESP32_communication/simple_test/ESP32_master/ESP32_master.ino @@ -7,10 +7,13 @@ //------------------------------------------------------------------------------------- uint8_t RxMACaddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0x91, 0x74}; String strdata = ""; +String valdata = ""; +int count = 0; //------------------------------------------------------------------------------------- typedef struct TxStruct { - int potVal; + String StrD; + double ValD; }TxStruct; TxStruct sentData; //------------------------------------------------------------------------------------- @@ -56,17 +59,29 @@ void loop() delay(500); */ strdata += char(inChar); - + delay(10); + count +=1; + if (count == 3){ + sentData.StrD = strdata; + Serial.println(sentData.StrD); + } + if (isDigit(inChar) || inChar == '.'){ + valdata += char(inChar); + } + if (inChar == '\n'){ - sentData.potVal = strdata.toInt(); - Serial.println(sentData.potVal); + sentData.ValD = valdata.toDouble(); + Serial.println(sentData.ValD); esp_err_t result = esp_now_send(RxMACaddress, (uint8_t *) &sentData, sizeof(sentData)); + // esp_now_send(RxMACaddress, (uint8_t *) &sentData, sizeof(sentData)); //------------------------------------------------------------------------------------- if (result == ESP_OK) Serial.println("Sent with success"); else Serial.println("Error sending the data"); //------------------------------------------------------------------------------------- delay(500); strdata = ""; + valdata = ""; + count = 0; } } @@ -74,42 +89,3 @@ void loop() //------------------------------------------------------------------------------------- } - - -/* - * String inString = ""; // string to hold input - -void setup() { - // Open serial communications and wait for port to open: - Serial.begin(9600); - while (!Serial) { - ; // wait for serial port to connect. Needed for native USB port only - } - - // send an intro: - Serial.println("\n\nString toInt():"); - Serial.println(); -} - -void loop() { - // Read serial input: - while (Serial.available() > 0) { - int inChar = Serial.read(); - if (isDigit(inChar)) { - // convert the incoming byte to a char and add it to the string: - inString += (char)inChar; - } - // if you get a newline, print the string, then the string's value: - if (inChar == '\n') { - Serial.print("Value:"); - Serial.println(inString.toInt()); - Serial.print("String: "); - Serial.println(inString); - // clear the string for new input: - inString = ""; - } - } -} - - * / - */