Digimesh testing
Contents
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.
- Libelium DigiMesh Networking Guide
- This is an example about how to send API frame using the XBee Digimesh device
- Creating a Simple Zigbee Communication Network using XBe, presentation
mbed
PC to XBEE using Python
- Using
a small test program created as below:
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)
- Send the string 'Hello World' to the module with MY set to 1
xbee.tx(dest_addr='\x00\x01', data='Hello World')
- 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)
- 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>
- !/usr/bin/python
- This is a simple demo to remotely turn a LED on and off
- 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)
- ZB XBee here. If you have Series 1 XBee, try XBee(ser) instead
xbee=ZigBee(ser)
- MAC, number written on the back of the XBee module
- CO3 = my coordinator
- 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'
}
- 64 bit address
led=False
- 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