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 60b27146047d928237c71c6936811d15cf332f40..903cfe3598e2b7f880bbda4285d0b5c803934417 100644 --- a/Code/ESP32_communication/Two-way/ESP32_master/ESP32_master.ino +++ b/Code/ESP32_communication/Two-way/ESP32_master/ESP32_master.ino @@ -3,7 +3,8 @@ #include <Wire.h> // REPLACE WITH THE MAC Address of your receiver (SLAVE) -uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0x4C}; +// uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0x4C}; // #4 +uint8_t broadcastAddress[] = {0xC4, 0xDD, 0x57, 0x9E, 0x91, 0x74}; // #1 String success; // Define variables to store BME280 readings to be sent @@ -11,6 +12,7 @@ String strdata = ""; String valdata = ""; String quedata = ""; int count = 0; +int count_digit = 0; // Define variables to store incoming readings String incomingStr = ""; @@ -100,9 +102,11 @@ void loop() sentData.StrD = strdata; Serial.println(sentData.StrD); } - if (isDigit(inChar) || inChar == '.' || inChar == '-'){ + if ((isDigit(inChar) || inChar == '.' || inChar == '-') && (count_digit <= 9)){ valdata += char(inChar); + count_digit += 1; } + if (inChar == '?'){ quedata += char(inChar); sentData.QueM = quedata; @@ -119,8 +123,8 @@ void loop() sentData.QueM = ""; }else{ // sentData.ValD = 0; - Serial.print("ValD"); - Serial.println(sentData.ValD); + Serial.print("ValD"); + Serial.println(sentData.ValD); Serial.print("QueM:"); Serial.println(sentData.QueM); } @@ -135,6 +139,7 @@ void loop() strdata = ""; quedata = ""; count = 0; + count_digit = 0; } } diff --git a/Code/ESP32_communication/Two-way/ESP32_slave/ESP32_slave.ino b/Code/ESP32_communication/Two-way/ESP32_slave/ESP32_slave.ino index 96cb18326de66c27a75b4282bf32759ec0e290c4..fcd4d3fdf481f82588213737e0ff4606007d0d05 100644 --- a/Code/ESP32_communication/Two-way/ESP32_slave/ESP32_slave.ino +++ b/Code/ESP32_communication/Two-way/ESP32_slave/ESP32_slave.ino @@ -4,7 +4,8 @@ // REPLACE WITH THE MAC Address of your receiver (MASTER) // Slave: 40:F5:20:44:B6:4C -uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x4A, 0xCF, 0x00}; +// uint8_t broadcastAddress[] = {0x3C, 0x61, 0x05, 0x4A, 0xCF, 0x00}; +uint8_t broadcastAddress[] = {0x40, 0xF5, 0x20, 0x44, 0xB6, 0x4C}; // #4 String success; // Define variables to store BME280 readings to be sent @@ -27,9 +28,8 @@ int8_t threshold[6] = {Lmin, Lmax, Amin, Amax, Bmin, Bmax}; int base_speed = 70; int seeking_speed = 70; int lidar_thres = 300; // mm - -int gbx = 0, gby = 0; - +int gbx = 0, gby = 0,gbd = 0; +double gbc = 0; // ===================================================================================== //Structure the sending data @@ -262,8 +262,13 @@ void ChangeVariables(){ lidar_thres = getDoubleVal(strData,"lth",valData,lidar_thres); //------ green ball x, y---- - gbx = getDoubleVal(strData,"gbx",valData,gbx); - gby = getDoubleVal(strData,"gby",valData,gby); + gbc = getDoubleVal(strData,"gbc",valData,gbc); + gbx = gbc /1000000; + gby = fmod(gbc,1000000)/1000;//(gbc.toInt() % 1000000)/1000; + gbd = fmod(gbc,1000); // gbc.toInt() % 1000; + + // gbx = getDoubleVal(strData,"gbx",valData,gbx); + // gby = getDoubleVal(strData,"gby",valData,gby); } @@ -338,12 +343,17 @@ void print_allvariables(){ Serial.print("Kpy:"); Serial.println(Kpy); Serial.print("|"); - + + Serial.print("gbc:"); + Serial.print(gbc); + Serial.print("|"); Serial.print("gbx:"); Serial.print(gbx); Serial.print("|"); Serial.print("gby:"); - Serial.println(gby); + Serial.print(gby); + Serial.print("gbd:"); + Serial.println(gbd); Serial.println("---------------------------\n"); print_count +=1 ;