I want to try IoT using the MQTT protocol (http://mqtt.org/), in order to do this most of Arduino recipe uses Ethernet or WIFI, but I have only bluetooth HC-06, so I utilize my smartphone as hub to access internet through it

attached video contains what I achieved before in other project using this recipe, I will cover here only the connectivity and libraries used.

Step 1: Install Arduino required libraries

IoT your Arduino using bluetooth and andriod smart phone (MQTT tethering)

Two libraries used in this project json library and custom made library to tether mqtt protocol for the Android smart phone, over software Serial.

you can download both libraries from here

https://github.com/ahmadsayed/Mqtt_Bluetooth

https://github.com/bblanchon/ArduinoJson

Hint : as per the attached image you can directly download the library from github using Download Zip button and extract it to Arduino Library folder at the Arduino IDE installation path

Step 2: Hardware Steup , connect arduino to HC-06

IoT your Arduino using bluetooth and andriod smart phone (MQTT tethering)

In this project I use HC-06 similar to what happen in a previous instructable you can find in the below address

http://www.instructables.com/id/Arduino-Internet-W...

but instead connect the RX,TX with 10, 11 digital output pins because our sample code uses Software Serial.

Step 3: Setup you andriod application

IoT your Arduino using bluetooth and andriod smart phone (MQTT tethering)

This android application needs some improvements to detect MAC address, you need to insert the MAC address manually, for simplicity I hard-coded the first 4 bytes they should be the same for all HC-06 from same supplier.

you can find the Android application source code using Android Studio here, and tweak it to fit your module

https://github.com/ahmadsayed/MQTTSerialTethering

Hint: Please insure your phone paired with the HC-06 and your bluetooth turned on before press connect

Step 4: Testing your application

IoT your Arduino using bluetooth and andriod smart phone (MQTT tethering)

This is just a sample to test your connectivity setup, we are going to use IBM provided quickstart service you can use it to it chart your sensor readings, just provide the HC-06 module MAC address and wait for the reading.

Upload attached test.ino to your Arduino, insure updating line 7 with your module info

for example if your mac address is (00:14:03:18:XX:XX), your constructor should be as follow

MqttSerial mqttSerial ("d:quickstart:instructable:00140318XXXX",bluetoothSerial);

the attached code read A0 Analog input pin and publish the data over quick start Mqtt protocol and the data get charted by this magical IBM web page

IoT your Arduino using bluetooth and andriod smart phone (MQTT tethering)
test.ino1 KB

Step 5: What is going to happen

IoT your Arduino using bluetooth and andriod smart phone (MQTT tethering)

Finally, it works the result is from my experiment, this is not an actual sensor data but it is the noise on A0 pin however it gives a very interesting chart too :) :)

 
 

Tag cloud

make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel