The second part of this week’s 2-Bullet Tuesday! See the first part here. You can subscribe to the newsletter on the 2-Bullet Tuesday page!
Omega Tip
Connecting your Omega to Losant with a Single Command!
We’re huge fans of Losant’s IoT Cloud Platform, it’s incredibly powerful, flexible, and super customizable. It’s a great fit for making your Omega projects cloud-connected!
In the past, it’s taken quite a few steps to setup your Omega to connect to the Losant platform. To help you do less setting up and more inventing, we’ve made a single command that installs all of the necessary packages and performs all of the configuration required to get your Omega hooked up with Losant.
All you need is to create a device and an access key on Losant and our script will do the rest! At the end of it, you’ll have an MQTT bridge to Losant configured and ready to use!
First, go to Losant.com and register. Then create a Losant Application by clicking the Applications menu and then Create Application:
Now, we’ll need to create a Losant Device. Click the Devices menu, and then Create a Blank Device. Give your device a name and set it to be a Standalone device. Finish the process to create the device and then make note of the Device ID:
One more thing: for your Omega to be able to authenticate with Losant, you’ll need to create an Access Key. Click the Security menu and then the Add Access Key button. You’ll be able to give your Key a description and choose whether it allows access to all of your Losant devices or if it’s restricted to specific devices. Once that’s done, the access key and secret will be generated:
Make sure to record both the key and secret somewhere since this is the only time you will get to see the secret!
Ok! Now you’re all set to connect your Omega to Losant, get to the Omega’s command line, make sure you’re connected to WiFi, and enter the following command:
wget -qP /tmp https://raw.githubusercontent.com/OnionIoT/Losant-Setup- Script/master/losant_setup.sh; sh /tmp/losant_setup.sh; rm /tmp/losant_setup.sh;
Follow the prompts to enter your Device ID, Access Key, and Access Secret:
Your Omega can now connect to Losant!
Run the mosquitto_sub command that was printed when the setup script completed:
mosquitto_sub -t losant/[YOUR-DEVICE-ID]/command
This will subscribe to the MQTT topic Losant uses to send commands to your device. All commands will be printed directly to the terminal.
Navigate back to your Device on Losant to make sure that it’s connected:
Click the Debug tab and let’s send a sample command:
And here it is, being received by the Omega:
Congratulations! Your Omega is ready to communicate with the Losant Cloud Platform. You can send state updates up to the Cloud or receive commands based on workflows. This can be done on your Omega by piping to mosquitto_pub and piping from mosquitto_sub, or using a higher-level programming language and an MQTT module, like Python and Paho-MQTT.
Stay tuned for more Losant and MQTT goodness! In the meantime, you can check out the multi-part Smart Plant in our Project Book that uses Python and the Losant Cloud Platform to create a truly intelligent plant that Tweets and waters itself!
Get the Project Book for Free!
Thanks for reading & have a great week!
Let us know what kind of stuff you would like to see featured on 2-Bullet Tuesday! Send a tweet to @OnionIoT with your suggestions!
P.S. Get free shipping on all Onion Store orders over $75 that include a Dock, Expansion, or a Kit!
P.P.S. The Onion Summer ‘17 Omega-thon Contest is underway on Hackster.io for students of all ages in North America! Check out the Contest Page for more info.