XBEE

The Xbee class manages the XBEE sockets as if they were serial ports.

Methods

class Xbee(uart_baudrate, identifier, uart_rxbuf=4096)

The class needs to be initialized with the following parameters:

Parameter name

Value

Description

uart_baudrate

9600, 19200, 38400, 57600,

115200, 230400, 460800,

921600

GNSS receiver UART1 baudrate

identifier

XBEE_A or XBEE_B

XBEE socket (A or B) at which

you want to connect

uart_rxbuf

any, default value is 4096

RX buffer size

read(size=None)

Read data from Xbee

Args:

size: number of bytes to receive. Use read() to read all available data.

Return:

Received data

Example to read data:

>>> import sbc
>>> xbee = sbc.Xbee( 115200, "XBEE_A" )
>>> print(xbee.read(12))
b'Hello World!'

Note

The ouput messages from the XBEE socket are being stored in the Xbee uart_rxbuf buffer.
The default buffer size (4096 bytes) should be enough to read continuously, but be aware that if you don’t read the buffer during a long time, the buffer will be completed and the new messages from the XBEE socket will be lost, and by the time you read the buffer you will read “old” messages.
If you want to discard old messages, you can empty the buffer with uart_init() method.

write(data)

Write data to the Xbee

Args:

data: data to send

Return:

Number of bytes written

Example to write data:

>>> import sbc
>>> xbee = sbc.Xbee( 115200, "XBEE_A" )
>>> sent_bytes = xbee.write( "Hello World!" )
>>> print('Bytes sent: ', sent_bytes)
Bytes sent:  12
uart_init()

Initializes XBEE UART port

forward_to(uart_fwd=None)

Fordwards XBEE data to a peripheral with UART

Args:

uart_fwd: peripheral object (Gps, Xbee, RS232)

Example to forward information received on the XBEE A socket to GPS1 UART1:
>>> import sbc
>>> pm = sbc.Power_Module()
>>> pm.xbee_on()
>>> xbee = sbc.Xbee( 115200, "XBEE_A" )
>>> gps1 = sbc.Gps( 1, 115200 )
>>> xbee.forward_to(gps1)
forward_disable()

Disables XBEE forwarding

get_uart_id()

Get XBEE UART port.

Return:

Uart port

Note

Since the get_uart_id() method of the Xbee class returns a microPython UART object, it has all its methods.
To do not duplicate the documentation, we suggest to take a look at the official microPython project documentation to see what methods you can additionaly use.

Example of additional methods:
>>> import sbc
>>> xbeeA = sbc.Xbee( 115200, "XBEE_A" )
>>> print('There are: ',xbeeA.any(),' characters to be read')
There are:  1580  characters to be read
>>> print(xbeeA.get_uart_id().readline())
b'$GNGGA,142222.00,4136.52091,N,00036.70322,E,2,10,1.27,203.6,M,49.8,M,,0000*4D\r\n'