Skip to content

Example MQTTSN network (Raspberry Pi and Arduino)

Rob Purser edited this page Aug 29, 2015 · 2 revisions

Example MQTT-SN network (Raspberry Pi + 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)

XBee configuration tutorial


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

  1. Edit /boot/cmdline.txt

    sudo cp /boot/cmdline.txt /boot/cmdline.txt.bak // Backup sudo nano /boot/cmdline.txt

  2. 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

  3. Edit /etc/inittab

    sudo cp /etc/inittab /etc/inittab.bak // Backup sudo nano /etc/inittab

  4. Comment out 2:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 and any other references to ttyAMA0

  5. 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

  1. Get MQTT-SN gateway code from https://github.com/lukaszdmitrowski/MQTT-SN.git

    git clone https://github.com/lukaszdmitrowski/MQTT-SN.git

  2. Go inside gateway code

    cd MQTT-SN/Gateway

  3. Install

    make
    make install
    make clean
    cd ../../

  4. To run type

    ./TomyGateway -i 1 -d /dev/ttyAMA0 -b 57600 -h test.mqtt.shiguredo.jp -p 1883


Uploading Arduino client application

  1. Go to example MQTT - SN client application in Wiselib library

    cd your_wiselib_dir/apps/generic_apps/mqttsn_test

  2. 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

  3. 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

  1. Run MQTT-SN gateway application on Raspberry Pi.
  2. Run Arduino MQTT-SN client application.
  3. You can add more Arduino clients
  4. You can write your own version of MQTT-SN client - MQTT-SN client implementation guide

Project photos


Łukasz Dmitrowski