-
Notifications
You must be signed in to change notification settings - Fork 57
Example MQTTSN network (Raspberry Pi and Arduino)
This project was made during Google Summer of Code 2014 - 'MQTT-SN implementation for Wiselib'
Prerequisities
- Arduino board(minimum 128kB of flash, 256kB recommended)
- Raspberry Pi board
- Minimum 2 XBee S1 devices(API: 81)
XBee configuration
XBee 1 (Gateway):
- MY: 1234
- AP: 2
- CH: 0C
- ID: 1111
- BD: 6 (56700 baud rate)
- CE: 1 (Coordinator)
XBee 2 (Client) :
- MY: 1235
- AP: 2
- CH: 0C
- ID: 1111
- BD: 6 (56700 baud rate)
- CE: 0 (End device)
Connections
-
Arduino to XBee
Arduino 3V3 - XBee Pin 1 (VCC)
Arduino Ground - XBee Pin 10 (Ground)
Arduino Tx - XBee Pin 3 (DIN)
Arduino Rx - XBee Pin 2 (DOUT)
-
Raspberry Pi to XBee
RPi Pin 1 (3V3) - XBee Pin 1 (VCC)
RPi Pin 6 (Ground) - Xbee Pin 10 (Ground)
RPi Pin 8 (GPIO 14 Tx) - Xbee Pin 3 (DIN)
RPi Pin 10 (GPIO 15 Rx) - Xbee Pin 2 (DOUT)
If you are using your Raspberry Pi UART for the first time
-
Edit /boot/cmdline.txt
sudo cp /boot/cmdline.txt /boot/cmdline.txt.bak // Backup
sudo nano /boot/cmdline.txt
-
Remove all references to ttyAMA0
/boot/cmdline.txt should look similiar to:
dwc_otg.lpm_enable=0 rpitestmode=1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
-
Edit /etc/inittab
sudo cp /etc/inittab /etc/inittab.bak // Backup
sudo nano /etc/inittab
-
Comment out
2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
and any other references tottyAMA0
-
Reboot Raspberry Pi
Note: If Raspberry UART seems not to work, install wiringPi. With this utility by using gpio <BCM-pin> mode <mode>
command change mode of Rx and Tx pin to IN
or OUT
and then back to ALT0
Installing Gateway on Raspberry Pi
-
Get MQTT-SN gateway code from https://github.com/lukaszdmitrowski/MQTT-SN.git
git clone https://github.com/lukaszdmitrowski/MQTT-SN.git
-
Go inside gateway code
cd MQTT-SN/Gateway
-
Install
make
make install
make clean
cd ../../
-
To run type
./TomyGateway -i 1 -d /dev/ttyAMA0 -b 57600 -h test.mqtt.shiguredo.jp -p 1883
Uploading Arduino client application
-
Go to example MQTT - SN client application in Wiselib library
cd your_wiselib_dir/apps/generic_apps/mqttsn_test
-
As this is generic application compile it for Arduino platform (please remember about editing apps/generic_apps/Makefile.arduino and check/change: ARDUINO_PATH, ARDUINO_BOARD)
make arduino
-
For uploading use avrdude(below example works with Arduino Mega2560, if you are not familiar with avrdude please check
man avrdude
)avrdude -V -p m2560 -c stk500v2 -b 115200 -Uflash:w:out/arduino/mqttsn_example_app.hex -P /dev/ttyACM0
Start MQTT-SN network
- Run MQTT-SN gateway application on Raspberry Pi.
- Run Arduino MQTT-SN client application.
- You can add more Arduino clients
- You can write your own version of MQTT-SN client - MQTT-SN client implementation guide
Project photos
Łukasz Dmitrowski