Shop OBEX P1 Docs P2 Docs Learn Events
Identification of nodes via Arduino sketch — Parallax Forums

Identification of nodes via Arduino sketch

mashorifmashorif Posts: 6
edited 2013-09-20 21:18 in Accessories
Hi,

I am trying to implement key distribution scheme in 3 Xbee+Arduino based nodes. If I assume one node as Node 1 (A) and another 2 as Node 2 (B) and Node 3 (C), I want to distribute the authentication to these nodes.

My main concern now is Identification of the nodes. I don’t know how Node 1 will refer to Node 2 and 3. I will be using other related sketch in arduino and that’s why I need to know arduino sketch by which I can identify a particular node and when needed refer to that node only. As an example if B wants to communicate with A only and then again wants to send some data to C only instead of A, how will it know the ID of the nodes and accomplish it’s job?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2013-09-20 19:04
    This would be better addressed in the Arduino forums at http://arduino.cc or perhaps the Digi forums.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-09-20 21:18
    There are several ways to do this. One is to set the destination serial number so the XBee will only send messages to the single XBee another way is to just broadcast the data to all XBees but include a header in the message indicating to which node the message is intended. I think it's probably easier to set the destination serial number and let the XBees handle the decision making by themselves.

    Here's some code I wrote several years ago to change the destination serial number. Hopefully it offers you some clues.
    PUB SetDestination(xbeeToChange, NewDestination)
    
      Debug.str(string("Press any key each time you see XBee respond.", 13))
      okFlag := 0
      count := 0
      XBee.str(string("+++"))
      repeat while okFlag == 0 and count < _TimeoutCount 
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string("XBee #"))
      Debug.dec(xbeeToChange)
      Debug.str(string(" SH = "))
      okFlag := 0
      count := 0
      XBee.str(string("ATSH"))
      XBee.tx(13)  
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string(13, "SL = "))
      okFlag := 0
      count := 0
      XBee.str(string("ATSL"))
      XBee.tx(13) 
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string(13, "DH = "))
      okFlag := 0
      count := 0
      XBee.str(string("ATDH"))
      XBee.tx(13) 
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string(13, "DL = "))
      okFlag := 0
      count := 0
      XBee.str(string("ATDL"))
      XBee.tx(13) 
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string(13, "Set DH = "))
      Debug.str(@shCoordinator + (NewDestination * 9))
      okFlag := 0
      count := 0
      XBee.str(string("ATDH "))
      XBee.str(@shCoordinator + (NewDestination * 9))
      XBee.tx(13) 
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string(13, "Set DL = "))
      Debug.str(@slCoordinator + (NewDestination * 9))
      Debug.tx(13)
      okFlag := 0
      count := 0
      XBee.str(string("ATDL "))
      XBee.str(@slCoordinator + (NewDestination * 9))
      XBee.tx(13) 
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string(13, "Check DH = "))
      okFlag := 0
      count := 0
      XBee.str(string("ATDH"))
      XBee.tx(13) 
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string(13, "Check DL = "))
      okFlag := 0
      count := 0
      XBee.str(string("ATDL"))
      XBee.tx(13) 
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
      Debug.str(string(13, "End Command Mode"))
      okFlag := 0
      count := 0
      XBee.str(string("ATCN"))
      XBee.tx(13) 
      repeat while okFlag == 0 and count < _TimeoutCount
        waitcnt(clkfreq / 100 + cnt)
    
    
    DAT
    
    
      shCoordinator         byte "0013A200", 0
      shBarcode             byte "0013A200", 0
      shBackup              byte "0013A200", 0 
      shSam                 byte "0013A200", 0 
      shFred                byte "0013A200", 0 
      shBroadcast           byte "00000000", 0
      slCoordinator         byte "403BCDDD", 0
      slBarcode             byte "400A2CCC", 0
      slBackup              byte "403BCEEE", 0
      slSam                 byte "403DDAAA", 0
      slFred                byte "403DDBBB", 0
      slBroadcast           byte "0000FFFF", 0
    

    The lines:
    XBee.str(string("ATDH "))  XBee.str(@shCoordinator + (NewDestination * 9))
      XBee.tx(13) 
    

    and
    XBee.str(string("ATDL "))  XBee.str(@slCoordinator + (NewDestination * 9))
      XBee.tx(13) 
    

    would send the appropriate serial numbers listed at the bottom of the top block of code.

    The code:
    repeat while okFlag == 0 and count < _TimeoutCount     waitcnt(clkfreq / 100 + cnt)
    

    Would wait for either a timeout period to occur or for the characters "OK" to be received. The variable "count" and "okFlag" were changed in a different cog than the one running the above method.

    I was using Series 2 XBee but I think the destination serial number can also be set Series 1 XBees (though I'm not sure).
Sign In or Register to comment.