Digi XBee modules are a great solution for wireless communication. Using two or more XBee modules you can create a wide area wireless network. The maximum range depends on the antenna and the configuration. Outdoors, it can reach several kilometers.
The bandwidth is relatively low so the messages should be short.
In this example we will control the Raspberry Pi (B4J) with an Android tablet (B4A). The XBee modules are connected to the Android tablet and RPi board with two XBee USB adapters.
The USB adapter is based on a FTDI USB to serial chip. This means that we will use felUsbDriver library in B4A and jSerial library in B4J.
The messages will be managed by AsyncStreamsText. AsyncStreamsText is useful in cases where we cannot use AsyncStreams in prefix mode. It will correctly build the messages and raise the NewText event whenever a complete message is available.
Note that in the B4A project the AsyncStreamsText module is slightly modified to allow it to work with felUsbSerial DataAvailable event (the change is trivial).
The messages are made of a comma separated string with the target, led or switch number and the state.
The XBee modules are configured in AT (application transparent) mode.
One is configured to be the coordinator and the other is configured as a router.
All the other settings are the default settings. This means that the router sends messages to the coordinator and the coordinator broadcasts messages to all devices (note that there are more efficient configurations for two modules).
The code is very simple. The B4J program is about 40 lines. The B4A program is a bit longer because of the UI.
The bandwidth is relatively low so the messages should be short.
In this example we will control the Raspberry Pi (B4J) with an Android tablet (B4A). The XBee modules are connected to the Android tablet and RPi board with two XBee USB adapters.
The USB adapter is based on a FTDI USB to serial chip. This means that we will use felUsbDriver library in B4A and jSerial library in B4J.
The messages will be managed by AsyncStreamsText. AsyncStreamsText is useful in cases where we cannot use AsyncStreams in prefix mode. It will correctly build the messages and raise the NewText event whenever a complete message is available.
Note that in the B4A project the AsyncStreamsText module is slightly modified to allow it to work with felUsbSerial DataAvailable event (the change is trivial).
The messages are made of a comma separated string with the target, led or switch number and the state.
The XBee modules are configured in AT (application transparent) mode.
One is configured to be the coordinator and the other is configured as a router.
All the other settings are the default settings. This means that the router sends messages to the coordinator and the coordinator broadcasts messages to all devices (note that there are more efficient configurations for two modules).
The code is very simple. The B4J program is about 40 lines. The B4A program is a bit longer because of the UI.