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
- 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.
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Setup
- Install the IDE as described by Mediatek:Linkit One IDE
- Upload a simple blink sketch to the LIO just to get warm.
- Get your SIM ready:
- First put the SIM in a phone
- Use phone settings to remove SIM-lock (PIN). The LIO GSM module doesn't support PIN.
- 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
- 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
- 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:
#define MQTT_VERSION MQTT_VERSION_3_1
//#define MQTT_VERSION MQTT_VERSION_3_1_1
Step 3: Using the Bridge
- 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".