Digimesh testing

From emboxit
Jump to: navigation, search

DIGI Wiki

...At this point, you should see the sleeping devices sleeping for 2 seconds, then being awake for 2 seconds. 
You host/PC can talk to the sleeping nodes only when they are awake - which is why we wanted the SO=0x04, 
so that your code receives a message when the mesh wakes

AT command SO 0x04 
           or set BIT_2 --> Enable API sleep status messages
  • Sleep Options.
  • Set/read the sleep options of the module. This command is a bitmask.
  • For synchronous sleep modules, the following sleep options are defined:
  • bit 0 = Preferred sleep coordinator
  • bit 1 = Non-sleep coordinator
  • bit 2 = Enable API sleep status messages
  • bit 3 = Disable early wake-up
  • bit 4 = Enable node type equality
  • bit 5 = Disable lone coordinator sync repeat
  • For ansynchronous sleep modules, the following sleep options are defined:
  • bit 8 = Always wake for ST time

DIGI





  • Includes a small Python program for PC, to communicate with the Digimesh from a serial channel.


mbed


PC to XBEE using Python

  • Using
  • The code proposed here
  • Python Xbee Package from here
  • Python PySerial Package from here

a small test program created as below:


File:Xbee-python-2.jpg
Run in DOS-PROMPT window


















My serial number high is 130200. I need two more bytes to have 32-bits, so that’s 00130200. 
My serial number low is 4054F82F. No 0s needed. So, final address is:
"001302004054F82F"
This is in hexadecimal format. We need to tell python about this. So we add “\x” in front of each byte:
"\x00\x13\x02\x00\x40\x54\xF8\x2F"


<python> from xbee import XBee from serial import Serial

PORT = '/dev/ttyUSB0' BAUD = 9600

ser = Serial(PORT, BAUD)

xbee = XBee(ser)

  1. Send the string 'Hello World' to the module with MY set to 1

xbee.tx(dest_addr='\x00\x01', data='Hello World')

  1. Wait for and get the response

print(xbee.wait_read_frame())

ser.close() </python> You can send AT commands by doing: <python> xbee.at(frame_id='A', command='MY') reply = xbee.wait_read_frame() print(reply)

  1. Getting the integer value out of reply

import struct print(struct.unpack('>h', reply['parameter'])[0]) </python> You can set the frame_id to any string, and it is used to identify the correct reply.

Remote Led

remote_led.py <python>

  1. !/usr/bin/python
  1. This is a simple demo to remotely turn a LED on and off
  2. 2011-02-11 Harald Kubota

import serial from xbee import ZigBee import time

PORT='/dev/ttyUSB0' BAUD_RATE=9600 ser = serial.Serial(PORT, BAUD_RATE)

  1. ZB XBee here. If you have Series 1 XBee, try XBee(ser) instead

xbee=ZigBee(ser)

  1. MAC, number written on the back of the XBee module
  2. CO3 = my coordinator
  3. EP1 = my endpoint with the LED on pin 11

device={

       "CO3":'\x00\x13\xa2\x00\x40\x52\x8d\x8a',
       "EP1":'\x00\x13\xa2\x00\x40\x4a\x61\x84'

}

  1. 64 bit address

led=False

  1. change remote device function

xbee.remote_at(dest_addr_long=device["EP1"],command='D2',parameter='\x02') xbee.remote_at(dest_addr_long=device["EP1"],command='D1',parameter='\x03') xbee.remote_at(dest_addr_long=device["EP1"],command='IR',parameter='\x04\x00') xbee.remote_at(dest_addr_long=device["EP1"],command='IC',parameter='\x02')

while 1:

       #set led status
       led=not led
       if led:
               xbee.remote_at(dest_addr_long=device["EP1"],command='D4',parameter='\x04')
       else:
               xbee.remote_at(dest_addr_long=device["EP1"],command='D4',parameter='\x05')
       # wait 1 second
       time.sleep(1)
      

ser.close()


</python>


Embedded CPU to Xbee using C