Xbee series 2 Zigbee - send delay problem

1,146 views
Skip to first unread message

Michele F

unread,
Jan 30, 2013, 11:24:00 AM1/30/13
to pytho...@googlegroups.com
Hi!

I have a star network setup, with a coordinator connected to the PC, and more arduino connected to more xbees end device.

The coordinator is set as follows:
XB24-ZB - ZIGBEE COORDINATOR API - 21A7
Impostazioni:
All default, except AP:2

The End device is set as follows:
XB24-ZB ZIGBEE END DEVICE API - 29A7
All default, except:
AP:2
DL: address low of coordinator
DH: address hight of coordinator


PC-side I have this python code, to send 5 packets every 1 second:

#! /usr/bin/python

import time
from datetime import datetime
import serial
from xbee import XBee, ZigBee

PORT = '/dev/ttyUSB0'
BAUD_RATE = 9600

# Open serial port and enable flow control
ser = serial.Serial(PORT, BAUD_RATE, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=1, rtscts=1, dsrdtr=1)

# Create API object
xbee = ZigBee(ser,escaped=True)

DEST_ADDR_LONG = "\x00\x13\xA2\x00\x40\x9C\x91\xA5"

#part to discovery shot 16-bit address
xbee.send("tx",data="000\n",dest_addr_long=DEST_ADDR_LONG,dest_addr="\xff\xfe")
response = xbee.wait_read_frame()
shot_addr = response["dest_addr"]

# Continuously read and print packets
while True:
    try:
        print "send data"
    tstart = datetime.now()
        xbee.send("tx",data="321\n",dest_addr_long=DEST_ADDR_LONG,dest_addr=shot_addr)
        xbee.send("tx",data="322\n",dest_addr_long=DEST_ADDR_LONG,dest_addr=shot_addr)
        xbee.send("tx",data="323\n",dest_addr_long=DEST_ADDR_LONG,dest_addr=shot_addr)
        xbee.send("tx",data="324\n",dest_addr_long=DEST_ADDR_LONG,dest_addr=shot_addr)
        xbee.send("tx",data="325\n",dest_addr_long=DEST_ADDR_LONG,dest_addr=shot_addr)
    tend = datetime.now()
    print tend - tstart
    time.sleep(1)
    except KeyboardInterrupt:
        break
       
ser.close()





Arduino-side, I have loaded this simple code to measure the delay of receiving the 5 packets:

#include <XBee.h>

unsigned long initime;

XBee xbee = XBee();
ZBRxResponse zbRx = ZBRxResponse();

void setup() {
  xbee.begin(9600);
  initime = millis();
}

void loop() {

  // 1. This will read any data that is available:
  xbee.readPacket();

  // 2. Now, to check if a packet was received:
  if (xbee.getResponse().isAvailable()) {
    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
      xbee.getResponse().getZBRxResponse(zbRx);

      Serial.println("ms from last packet: ");
      Serial.println(millis() - initime);  //count delay and print it in serial
      Serial.println("\n");
      initime = millis();  //Save time, to count delay of next packet
    }
  }
}



The result is:


ms from last packet:

939


ms from last packet:

31


ms from last packet:

32


ms from last packet:

29


ms from last packet:

30




The delay of packet transmission is about 30 milliseconds. For my application I need to get off at least 10-15ms. Can I do it?

The delay depends of the library?


Thanks in advance!

Reza Febrialdy

unread,
Apr 16, 2014, 5:41:54 AM4/16/14
to pytho...@googlegroups.com
why when i run python code is show error in tstart = datetime.now(), SyntaxError: invalid syntax

Chris Jefferies

unread,
Apr 16, 2014, 11:24:58 AM4/16/14
to pytho...@googlegroups.com
Perhaps you forgot the import statements?

Reza Febrialdy

unread,
Apr 16, 2014, 8:20:37 PM4/16/14
to pytho...@googlegroups.com
oh sorry its work now..but why when i click serial monitor in arduino its result nothing?

Chris Jefferies

unread,
Apr 16, 2014, 10:42:06 PM4/16/14
to pytho...@googlegroups.com
Reza, 

Try to post as much detail as you can about your setup and then we can better understand why data is not appearing in your arduino print statements.

Paul Malmsten

unread,
Apr 17, 2014, 7:35:49 PM4/17/14
to Michelle F, pytho...@googlegroups.com

Hi Michelle,

I am sorry I missed your message a while back. In case you are still having trouble, I would recommend flushing the serial port buffer after sending a message to an XBee. It is possible that the serial port stream is buffering the message briefly before passing it to the local XBee.

This may be done using the following code:

ser.flush()

Place that after each call to XBee.send().

Regards,
~Paul Malmsten

--
You received this message because you are subscribed to the Google Groups "Python XBee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-xbee...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reza Febrialdy

unread,
Apr 23, 2014, 5:43:40 AM4/23/14
to pytho...@googlegroups.com
hi Chris Jefferies ,
i follow everything that Michele Franceschini  post, but in arduino its result nothing..do you know why? 

Reply all
Reply to author
Forward
0 new messages