Introduction: Two Way MQTT-SMS Bridge (Linkit One)

Picture of Two Way MQTT-SMS Bridge (Linkit One)

This project is for the Linkit One. This prototype board is programed like an Arduino but has a lot more features. This project demonstrates the GSM (SMS) and built in WiFi units.

The features of this project:

  • Connect to WiFi
  • SMS
  • Creates two-way SMS to MQTT bridge
    • Send outgoing SMS to any destination with any message body from the Linkit One board from any MQTT client in the network.
    • Relay incoming SMS messages to the MQTT bus. The first word (up to first space) is the topic. Anything following is payload. I.e. you can control your personal IoT by SMS. A word of caution though. If you have anything sensitive (alarm system?) you should definitely add code to qualify incoming numbers before passing messages to the MQTT bus.

Step 1: Setup

Picture of Setup
  1. Install the IDE as described by Mediatek:Linkit One IDE
  2. Upload a simple blink sketch to the LIO just to get warm.
  3. Get your SIM ready:
    1. First put the SIM in a phone
    2. Use phone settings to remove SIM-lock (PIN). The LIO GSM module doesn't support PIN.
    3. Slide the SIM into the holder on the back with the connector facing the board and the cut corner sticking out (see picture)

Step 2: The Code

Picture of The Code

  • Download the sketch
  • Download the PubSub MQTT client library for Arduino: https://github.com/knolleary/pubsubclient
  • If you don't already have a MQTT server on your network, install one, e. g. Mosquitto server.
  • Install a MQTT GUI client for testing. I like MQTT-spy.
  • Open up the sketch and enter enter network settings and MQTT-server settings
  • Upload
  • Open up the serial monitor and watch the action.
  • If the WiFi connections succeeds but the MQTT connection fails (I had that problem), change protocol version to 3.1. Edit the PubSubClient.h like so:

PubSubClient.h:
#define MQTT_VERSION MQTT_VERSION_3_1
//#define MQTT_VERSION MQTT_VERSION_3_1_1

Step 3: Using the Bridge

Picture of Using the Bridge

    Get started

    • Open MQTT-spy
    • Subscribe to everything: /# and #

    MQTT to SMS

    • Using MQTT-spy, publish to topic: /lio_1/smsto/your_phone_number. Whatever you put in the payload will be the message body of the SMS

    SMS to MQTT

    • Send a SMS to the Linkit One board. Anything before the first space is published to MQTT as a topic. Anything after is the payload. You can even do a loopback test by sending a SMS containing "/lio_1/smsto/your_phone_number hello".

    Comments

    siddhc (author)2016-08-20

    Hi,
    Great post.
    This is a request for guidance.
    My
    ESP8266 module connects to “test.mosquitto.org” and subscribes to a
    topic say “b1”. What ever is published to “b1”, it can read it
    immediately.
    Problem happens when my second ESP8266 module subscribes to “test.mosquitto.org” to “b1”. It continuously returns :

    WiFi connected
    IP address:
    192.168.0.9
    Attempting MQTT connection…connected
    Message arrived [b1] 0
    Attempting MQTT connection…connected
    Message arrived [b1] 0
    Attempting MQTT connection…connected
    Message arrived [b1] 0
    Attempting MQTT connection…connected

    Could you kindly suggest what might be going wrong. I look forward to your advice.

    ehsmaes (author)siddhc2016-08-21

    I'm glad you like it! Just a wild guess. Do your two subscribers have unique client-id's?

    About This Instructable

    2,011views

    12favorites

    License:

    Bio: IT-professional by day, DIY hobbyist (among other things) on my free time. I always have one or more projects going on. Usually something to do ... More »
    More by ehsmaes:Motorized WiFi IKEA Roller BlindCheap 3D Delta Printer ImprovementsMotorize IoT with ESP8266
    Add instructable to: