[chronojump] Wifi. Fixed discoverTerminals



commit 4f5ef106984eb2fb8d8c64302ee9ce90bec059c7
Author: xpadulles <x padulles gmail com>
Date:   Mon Mar 28 16:17:11 2022 +0200

    Wifi. Fixed discoverTerminals

 .../WiFi/terminal/Current/terminal/terminal.ino    |  9 ++++----
 arduino/WiFi/terminal/V3/terminal/terminal.ino     | 27 +++++++++++++++-------
 arduino/WiFi/terminal/V4/terminal/terminal.ino     | 14 +++++------
 3 files changed, 31 insertions(+), 19 deletions(-)
---
diff --git a/arduino/WiFi/terminal/Current/terminal/terminal.ino 
b/arduino/WiFi/terminal/Current/terminal/terminal.ino
index 28b2d9aa5..98f58c337 100644
--- a/arduino/WiFi/terminal/Current/terminal/terminal.ino
+++ b/arduino/WiFi/terminal/Current/terminal/terminal.ino
@@ -233,12 +233,13 @@ void loop(void)
 //    Serial.print("Command received: ");
 //    Serial.println(instruction.command);
 //    radio.flush_rx();
-//    radio.startListening();
 
     if (instruction.termNum == sample.termNum)
     {
       executeCommand(instruction.command);
     }
+    
+    radio.startListening();
   }
 }
 
@@ -384,9 +385,9 @@ void executeCommand(uint16_t command)
 
     if ((command & ping) == ping) {
       sample.state = digitalRead(2);
-      radio.setRetries(15, 15);
+      //radio.setRetries(15, 15);
       sendPong();
-      radio.setRetries(5, 15);
+      //radio.setRetries(5, 15);
     }
   }
 }
@@ -462,5 +463,5 @@ void sendPong(void) {
   flagint = LOW;
   if (! unlimitedMode) waitingSensor = false;
   radio.setChannel(terminal0Channel - sample.termNum);
-  radio.startListening();
+  //radio.startListening();
 }
diff --git a/arduino/WiFi/terminal/V3/terminal/terminal.ino b/arduino/WiFi/terminal/V3/terminal/terminal.ino
index 595795962..194440920 100644
--- a/arduino/WiFi/terminal/V3/terminal/terminal.ino
+++ b/arduino/WiFi/terminal/V3/terminal/terminal.ino
@@ -214,6 +214,10 @@ void setup(void)
   Serial.print(lastPinState);
   Serial.print("\t");
   Serial.println(sample.state);
+  
+  //radio.printPrettyDetails();
+  Serial.print("Power: ");
+  Serial.println(radio.getPALevel());
 }
 
 
@@ -231,14 +235,16 @@ void loop(void)
     radio.stopListening();
 //    delay(100);
 //    Serial.print("Command received: ");
-//    Serial.println(instruction.command);
+    Serial.print("termNum received: ");
+    Serial.println(instruction.termNum);
 //    radio.flush_rx();
-//    radio.startListening();
 
+    //Some times the terminal receives instructions of other terminals
     if (instruction.termNum == sample.termNum)
     {
       executeCommand(instruction.command);
     }
+    radio.startListening();
   }
 }
 
@@ -315,6 +321,7 @@ void debounce() {
 
 void executeCommand(uint16_t command)
 {
+  Serial.println(instruction.command);
   if (command == deactivate) {
     //    Serial.println("deactivating leds and sensor");
     deactivateAll();
@@ -384,9 +391,9 @@ void executeCommand(uint16_t command)
 
     if ((command & ping) == ping) {
       sample.state = digitalRead(2);
-      radio.setRetries(15, 15);
+      //radio.setRetries(15, 15);
       sendPong();
-      radio.setRetries(5, 15);
+      //radio.setRetries(5, 15);
     }
   }
 }
@@ -449,18 +456,22 @@ void beepStop(void)
 }
 
 void sendPong(void) {
-  Serial.println("Pong");
   sample.data = deviceType * 1000000 + deviceVersion;
 //  Serial.println(sample.data);
-  Serial.print("Wifi-Sensor-");
-  Serial.println(deviceVersion);
+//  Serial.print("Wifi-Sensor-");
+//  Serial.println(deviceVersion);
   flagint = LOW;
   MsTimer2::stop();
   radio.stopListening();
+  delay(10);
   radio.setChannel(control0Channel - controlSwitch);
+  //delay(10);
   bool en = radio.write( &sample, sample_size);
   flagint = LOW;
   if (! unlimitedMode) waitingSensor = false;
+  //delay(10);
   radio.setChannel(terminal0Channel - sample.termNum);
-  radio.startListening();
+  //delay(10);
+  //radio.startListening();
+  //delay(10);
 }
diff --git a/arduino/WiFi/terminal/V4/terminal/terminal.ino b/arduino/WiFi/terminal/V4/terminal/terminal.ino
index e2458c450..6b6e18598 100644
--- a/arduino/WiFi/terminal/V4/terminal/terminal.ino
+++ b/arduino/WiFi/terminal/V4/terminal/terminal.ino
@@ -233,12 +233,12 @@ void loop(void)
 //    Serial.print("Command received: ");
 //    Serial.println(instruction.command);
 //    radio.flush_rx();
-//    radio.startListening();
 
     if (instruction.termNum == sample.termNum)
     {
       executeCommand(instruction.command);
     }
+    radio.startListening();
   }
 }
 
@@ -384,9 +384,9 @@ void executeCommand(uint16_t command)
 
     if ((command & ping) == ping) {
       sample.state = digitalRead(2);
-      radio.setRetries(15, 15);
+      //radio.setRetries(15, 15);
       sendPong();
-      radio.setRetries(5, 15);
+      //radio.setRetries(5, 15);
     }
   }
 }
@@ -449,11 +449,11 @@ void beepStop(void)
 }
 
 void sendPong(void) {
-  Serial.println("Pong");
+//  Serial.println("Pong");
   sample.data = deviceType * 1000000 + deviceVersion;
 //  Serial.println(sample.data);
-  Serial.print("Wifi-Sensor-");
-  Serial.println(deviceVersion);
+//  Serial.print("Wifi-Sensor-");
+//  Serial.println(deviceVersion);
   flagint = LOW;
   MsTimer2::stop();
   radio.stopListening();
@@ -462,5 +462,5 @@ void sendPong(void) {
   flagint = LOW;
   if (! unlimitedMode) waitingSensor = false;
   radio.setChannel(terminal0Channel - sample.termNum);
-  radio.startListening();
+//  radio.startListening();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]