Beebotte to Ubidots - Kevin Power #10
Introduction
In this blog, I am going to discuss my work on attempting to connect Beebotte to Ubidots, to get a dashboard showing all the data directly from Beebotte. I have had some previous experience working with Beebotte in this lab which I detail below, but to connect it to Ubidots there are various methods I attempted which I will detail later in this blog.
Previous Beebotte work
Beebotte is a really useful technology and something that other members of the team had been looking at for a few weeks by now. Personally, I had only run into it when working with a team member on the Microbits and Xinabox to see if we could get a connection from Xinabox to Beebotte.
This made me familiar with Beebotte but my experience level started on a lower level initially with the technology.
Research
As with everything, my first step in tackling the Beebotte to Ubidots connection was seeing if anybody had previously done it before, or done anything similar before. I took to Google but sadly, I didn't have any luck and could not find any areas where these two technologies have been combined. This spiked my interest in getting a working model further as it meant I'd be the first to do so.
This led me then to research more into Ubidots and the connection options it has, Ubidots has a number of widgets for displaying data that gets sent to it but only one widget for sending data from Ubidots to something else. All the working connections to Ubidots we have at the moment focus on sending values to Ubidots via either a python script or a Makecode Microbit javascript script. For videos or audio, we have had to route through external websites.
The research I completed on Beebotte allowed me to find how open the software is to connect anywhere, Beebotte has an MQTT connection and its own custom API tool. These allow you to send and receive data almost anywhere on the web. Currently, we have a connection from Beebotte to the Microbits and can use a number of extensions in Makecode to allow this to be done.
Beebotte's API seemed like the best place to start for connecting the two platforms together, as Ubidots has an HTML widget to which I could attach any script I wanted to. I spent some time reading and testing how the API worked. I'll attach some useful links to learning about it here:
API Research and Docs: https://beebotte.com/overview
Testing: https://beebotte.com/api/play
The other option for connecting the two platforms together which I researched was using the MQTT option that both platforms seemed to have. I did a lot of research on this side of things and ran into a few walls around the connection types and needed a middle ground to get the two platforms to connect. However, if I had more time it is something I'd potentially look more into in the future.
Beebotte MQTT : https://beebotte.com/docs/mqtt
Ubidots MQTT : https://help.ubidots.com/en/articles/570008-ubidots-mqtt-broker
In conclusion, after all my research, I decided to pursue the API option to connect the platforms in more detail.
Beebotte API
For anyone who hasn't worked with API's before, an API is an Application Programming Interface, they act as a sort of intermediary that allows two applications to talk to each other via API Calls. They are used all over the web and I worked with them a lot in my final year project. A simple example would be when you open a weather app on your phone. Your phone is sending a "Get Request" to the Weather API and the Weather API then comes back and tells the weather app the response and shows it to you on the screen.
Different API's require different authentication and security for them to work, in this case, Beebotte requires you to use your, API keys to generate security checks. The Get requests don't contain any major security checks and I was able to get a working connection between Beebotte and Ubidots using the API after a few hours of work. However, the Post or sending data from Ubidots to Beebotte was a much bigger challenge, Beebotte requires specific encryption using your API keys and a HMAC-SHA1 encryption algorithm to generate a signature that's used to make sure you are allowed to send the data. This is to ensure that the data being sent onto Beebotte's system is safe and secure. On Microbit for Beebotte this algorithm is programmed into the Makecode blocks so that it will work in both directions.
Unfortunately, this part I was not able to get working, as I couldn't embed this encryption into the script I was using on Ubidots for the website.
Ubidots and API's
On Ubidots, they have a tool called Ubidots Functions, which are specifically designed for tackling the issues we are dealing with, allowing Ubidots to connect to external API's and sites really easily. However, it's only for industry users and would require us to pay to gain access.
As a cheaper workaround to that option, I decided to embed the API request in an HTML Widget. Embedding a API call in Javascript or HTML can be done in a number of different ways, I'll leave a research link here: https://levelup.gitconnected.com/all-possible-ways-of-making-an-api-call-in-plain-javascript-c0dee3c11b8b In Ubidots I decided to use XML as a tool to do this.
Initially, when this was done, it would not work, as Ubidots blocks the use of API's via a CORS (cross-origin resource sharing) error. I believe this was in place to stop people from bypassing buying the more expensive industry version of Ubidots.
User Experience
For the user, I wanted their experience to be as easy as possible to use the Ubidots dashboard, and not have to worry about any of the challenges or problems I faced when trying to connect the two devices.
For this, the panel above is what is used to demonstrate the working model, to get the data from Beebotte, all the user would need to do is click the Get Data button and it would work as expected.
Comments
Post a Comment