thegooglecodearchive / python-xbee

Automatically exported from code.google.com/p/python-xbee
MIT License
0 stars 0 forks source link

Processing Waspmote data frames. #54

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi, I've made some code lines to process data frame package and make a 
dictionary. Something like this:

{'sequence': '178', 'waspmote_id': 'WASPMOTE_XBEE', 'frame_type': 128, 
'num_fields': 2, 'sensors_data': [('STR', 'XBee frame'), ('BAT', '48')], 
'serial_id': '356907616', 'source_addr_long': '00-13-a2-00-40-ba-aa-f0'}

Do you think this is useful for your prooject? Would you like I commit it or 
would you like I put it here?

Original issue reported on code.google.com by a...@orencio.org on 31 Jul 2014 at 5:48

GoogleCodeExporter commented 9 years ago
Sorry, I refer to Libelium Waspmote data frame. I don't know if it is useful 
for you.

Original comment by a...@orencio.org on 31 Jul 2014 at 5:58

GoogleCodeExporter commented 9 years ago
My apologies for the delay getting back to you.

To make sure I understand - you have extended the python-xbee library to work 
with Waspmote devices?

I'm always interested in accepting contributions to the library. In order to 
accept a contribution, I will need to see:
 - Well-formed code
 - Unit tests demonstrating that the new code works
 - Documentation suitable for users

I'm happy to work with you to make it happen.

Original comment by pmalms...@gmail.com on 15 Aug 2014 at 12:42

GoogleCodeExporter commented 9 years ago
Hi!
We are using Digimesh from waspmote. Could you help me with receiving frames 
with waspmote format? It would be sweet, best regards!

Original comment by rov...@gmail.com on 6 Mar 2015 at 9:31

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hello, in my code I use this (for python3).

I create a zb object:

```python3
import serial
from xbee import ZigBee
import binascii
import re
from queue import Queue, Empty

self._zb = ZigBee(self._serial_port, escaped=True, 
callback=self._message_received)
_q_msg_rcv = Queue()
_df_re = 
re.compile(r"^b'<=>(?P<frame_type>\\x\d{2})(?P<num_fields>\\x\d{2})#(?P<serial_i
d>[^#]+)#(?P<waspmote_id>[^#]*)#(?P<sequence>[^#]*)#(?P<sensors_data>.*)'$")

It call _message_received function when data are received and puts the message into a Queue object (_q_msg_rcv). To parse data frame I use regexp (_df_re):

   def _message_received(self, data):
        """Process XBee messages by XBee API callback.

        :param data: Data received from ZB.
        :type data: dict
        :return: None
        """
        try:
            # If there are data and they are data frame type, we process.
            if data.get('rf_data') and self._df_re.match('{0}'.format(data['rf_data'])):
                df = self._df_re.match('{0}'.format(data['rf_data'])).groupdict()
                df['sensor_data'] = [tuple(e.split(':')) for e in re.findall(r"([^#]*)#", df['sensors_data'])]
                if df['sensors_data']:
                    del df['sensors_data']
                df['frame_type'] = int(df['frame_type'].replace('\\x', ''), 16)
                df['num_fields'] = int(df['num_fields'].replace('\\x', ''), 16)
                df['source_addr_long'] = re.sub(r'(\w\w)', r'\1-', str(binascii.b2a_hex(data['source_addr_long']))[2:-1])[:-1].lower()
                self._q_msg_rcv.put_nowait(df)
        except Exception as e:
            (my exception)

After I read the queue when I need and drop its elements.


Original comment by `a...@orencio.org` on 7 Mar 2015 at 8:37