Duplicate ID issue temporary workaround

Started by KrisK, September 17, 2022, 12:20:45 AM

KrisK

First, thank you forum and forum members for all the knowledge and help you have been to me for the past 2 years!!!   

Secondly (disclaimer), I am posting here as a workaround that works for my code.  I do not claim to be an expert whatsoever.

I thought I could finally post something that might help out.   I figured out a temporary work around for nodes with a duplicate ID.   This is not permanent, but it was a quick fix for my product.  Plus, I currently do not have the bandwidth the really fix the issue.

I have a controller that the users can push a button to send a command to the nodes and the correct node will execute the command (basically a motor runs)   The controller only needs an ACK_BACK from the nodes at startup.  The rest of the time the controller will blast the command and go on.  In other words, I save some battery life by not worrying about an ACK from the nodes on every transmit I do.  Each node has a dip switch to give an ID 0 to 7.     When the controller is activated (turned on)  it brute force initializes an array to verify which node ID is active.   To do this, it sends a command code for ACK initialized in a variable in the data structure.  Brute force it will do this in sequence 0 .. 7.  If the listening NODE X is of that ID it will send an ACK_BACK.  All nodes have spy mode on and are in the same network.  Basically, NODE 1 are you there?  NODE 1 hears the signal and radio.sendACK().  This initialization process last for about 8 to 10 seconds on the controller.   

For the last 20 months the (my MVP) base code was working well.   However, a user decided to take 12 nodes make them all the same ID and put them in a truck bed.  He then turned all the duplicate ID nodes on while sitting on the tailgate.   Next turned on the controller.   POOOF.. the controller did not initialize any nodes.    The cute part was,  when he walked back to his house 30 yards away and turned on the controller, the controller initialized correctly.    This is why the code has worked for 20 months.  Nobody has ever been within 5 feet of 12 duplicate nodes.   

The very temporary workaround fix for that night was to remove the duplicates.  So three nodes had ID#0, three nodes had ID#1.. etc

After a few weeks of thinking how to solve this and an email to Felix to confirm the system does not work well with duplicate IDs on nodes, I though of a solution.    If the duplicate ID on the 12 nodes worked 30 yards away and did not work 3 feet away, maybe I could modulate the ACK_BACK and it actually worked!!! ::).   

The solution that is currently working was to only add 2 lines of code into the existing system.  The two lines of code randomized the radio.sendACK().  The thinking is; if it worked 30 yards away maybe this issue was all about timing and the amount of time it takes the ACK to travel 3 feet vs 30 yards.   

Below is what I did.    The added two lines to my existing code are noted 9-10-22.  This section of code is in the main LOOP.   I hope it helps.   I still plan on reworking the code to make unique IDs internally and keep the functionality the users are used to with ID# 0 to ID# 7.  However, I have other items on my kanban board list-o-plenty.

Thanks again
Kris K

==========================================================================================
//----------------------------------------------------------------
//--   This is the NODE code that has the two lines for ACK 
//----------------------------------------------------------------
void loop() 
{
  if (radio.receiveDone())
  {
    theData           = *(Payload*)radio.DATA;
    if ( (radio.DATALEN == sizeof(Payload)) )  
    {
      if ((theData.COMMANDid == TARGET_ack) && (TARGETid == theData.rcvr_NODEid ) )  
      {
        radio.sendACK();                             // ACK when controller wants it ORIGINAL CODE

        delay( ( random( 3, 8 ) *11) ) ;             // Modulation tweak kk 9-10-22
        radio.sendACK();                             // Modulation tweak kk 9-10-22

        strobeLIGHT(OT_LED1, 2, 25);                // Flash LED to verify ACK
        OLD_PACKETid = theData.PACKETid;            // old packet do notrepeat on execution code
      }
      . . . . 
      . . . .                                                     // other execution code was here
      . . . . 
    }
  }
}

//----------------------------------------------------------------
//--   This is the CONTROLLER code that initializes an array for the active NODES  
//----------------------------------------------------------------

void initialize_TargetID_array()
{

for (tmpID = 1; tmpID <= MAX_TARGETcnt; tmpID++)   // brute force walk through all ID's
  {
     PACKETcounter++;  
     retryCNT                  = 0;
     found_target              = false;
     
     memset(&theData, '\0', sizeof(theData));            //- clear buffer 
     theData.NETid               = NETWORKid;
     theData.sndr_NODEid    = CONTROLLERid;
     theData.COMMANDid     = TARGET_ack;
     theData.rcvr_NODEid     = tmpID;

     while ( (!found_target) && (retryCNT <= 15) )        // try looking for the node for 15 times of retrying.
     {
     if (radio.sendWithRetry(tmpID, (const void*)(&theData), sizeof(theData), 1) )
      {
          found_target =  true;                        // great we found it
          TargetBASE_id[t_ID]  = tmpID;                // add the id value to the array
          TargetID_arrayCNT++;                         // increment the array pointer
          t_ID++;                                      // go to the next ID
          strobeLIGHT(OT_LED1, 2, 50);                 // strobe the outside LED
      }
      else retryCNT++;                                 // else NOGO so brute to next ID
     }  
     if (!found_target) strobeLIGHT(OT_LED1, 1, 25); 
  }
}                                                                    // done we crawled thru each id



KrisK

UPDATE:   I turned on 22 nodes with the same ID all in a 8 x 10 area and stood in the middle of them.  Then I turned on the controller without an issue.  Looks to be working far better than I expected.     I hope to do testing down the road with 50 nodes but there are a few more projects in front of that.  Good luck forum members and thanks again for all of the help in the past and future. 

Felix

That's great to hear your workaround worked so well, thanks for the update!