Last week we announced the DreamFactory integration of MQTT communication for IoT applications. It's a powerful new addition to the capabilities of our robust REST API platform.
For this demo we're going to use DreamFactory as an MQTT broker for two Raspberry Pi computers acting as publisher and subscriber. We'll go over three scenarios covering key aspects of IoT deployments. Though the tutorials are based on Raspberry Pi, any microcontroller or SOC board can be used for exploring the features. A video walkthrough is also available, recorded from a webinar presentation in October.
cd GrovePi/Software/Python/<br>sudo python grove_led_blink.py
cd /opt/bitnami/apps/dreamfactory
sudo git clone https://github.com/dreamfactorysoftware/df-iot.git
cd /opt/bitnami/apps/dreamfactory/df-iot/config && sudo sh ./configure.sh
cd /opt/bitnami/apps/dreamfactory/df-iot/config && sh ./df-iot-services.sh
cd /opt/bitnami/apps/dreamfactory/df-iot && node index.js --config config.json
cd /opt/bitnami/apps/dreamfactory/df-iot/config && sh ./reg_rpi-pub.sh<br>cd /opt/bitnami/apps/dreamfactory/df-iot/config && sh ./reg_rpi-sub.sh
mqtt sub -u rpi-sub -P rpi-sub -v -t '#'
mqtt pub -u rpi-pub -P rpi-pub -v -t 'test' -m '{ "msg": "Hello DreamFactory IoT" }'
When you move DreamFactory Bitnami appliance from host to another, it is recommended that you reset the configuration. To do that, follow the instructions below:
cd /opt/bitnami/apps/dreamfactory/df-iot/config && sudo sh ./reset-env.sh<br>cd /opt/bitnami/apps/dreamfactory/df-iot/config && sudo sh ./configure.sh<br>cd /opt/bitnami/apps/dreamfactory/df-iot/config && sh ./df-iot-services.sh<br>cd /opt/bitnami/apps/dreamfactory/df-iot/config && sh ./reg_rpi-pub.sh<br>cd /opt/bitnami/apps/dreamfactory/df-iot/config && sh ./reg_rpi-sub.sh<br>cd /opt/bitnami/apps/dreamfactory/df-iot/config && sudo sh ./restart_mosca.sh
DreamFactory IoT enables M2M communication through MQTT and HTTP. This demo shows how DreamFactory enables registered devices to talk to each other.
git clone https://github.com/dreamfactorysoftware/df-iot.git
cd df-iot/Demos/Demo1/rpi-pub
sudo python Button.py <DreamFactory_IP>
git clone https://github.com/dreamfactorysoftware/df-iot.git
cd df-iot/Demos/Demo1/rpi-sub
For example - sudo python Bulb.py <DreamFactory_IP>
When you toggle the Grove Button on rpi-pub, you should see the Grove Red LED connected to rpi-sub turning on and off. This demonstrates that DreamFactory is brokering the MQTT messages between the devices
git clone https://github.com/dreamfactorysoftware/df-iot.git
cd df-iot/Demo2/rpi-pub
sudo python Temperature.py <<i>DreamFactory_IP></i>
git clone https://github.com/dreamfactorysoftware/df-iot.git
cd df-iot/Demos/Demo2/rpi-pub
For example - sudo python Temperature.py <<i>DreamFactory_IP></i>
git clone https://github.com/dreamfactorysoftware/df-iot.git
cd df-iot/Demos/Demo1/rpi-sub
sudo python Bulb.py <<i>DreamFactory_IP></i>
var lodash = require("lodash.min.js");<br>var options = {<br> "CURLOPT_HTTPHEADER": ['Content-type: application/json','X-DF-DEVICEID: rpi-pub','X-DF-DEVICETOKEN: rpi-pub']<br>};<br><br>var result;<br>var led;<br><br>if (event.request.payload.resource) {<br> lodash._.each(event.request.payload.resource, function( record ) {<br> if (record.payload.h < 50)<br> led='{"color":"green"}';<br> else<br> led='{"color":"red"}';<br> result = platform.api.post("https://<DreamFactory_IP>:3000/p/df-iot/temp",led, options);<br> });<br>}
There are many more options available for robust IoT integration in DreamFactory. We've just scratched the surface here. We're looking forward to seeing what you'll build with it.