The Internet of Things is a large ecosystem of hardware, connectivity, middleware, and software providers; each piece of the puzzle coming together harmoniously to providing a complete IoT solution in the form of an IoT Application. In an ideal world, data for your IoT App would simply flow directly from device to cloud:
However, as with most of life's intricacies, reality is a bit more complex. Depending on your Application’s requirements and hardware constraints, data may require additional stops before being visualized and made available to end-user via your Ubidots powered App. Your App many require the applications of a Machine Learning or Data Cleansing algorithm, or possibly enlist in one of the hardware device management services provided by dozens of OEMs in today’s maturing world of IT solution development.
Using the Data Plugin capabilities enabled by the UbiFunctions engine you can effortlessly aggregate valuable data into your Ubidots-powered IoT app to give your App and its users the best solutions possible.
Table of Contents
- What is a Plugin
- Types of Plugins
- Creating a Plugin
- Code the Plugin Parsing Function
- Testing the Plugin Function
- Extra Support
What is a Plugin?
A plugin is a Parsing Function that excecutes Node.js / Python code in the cloud and can be triggered by either (1) making an HTTP GET or POST request to the Function’s URL automatically created by Ubidots, or (2) based on a predefined repeat interval:
Simply, a plugin is a Parsing Function that when programmed properly can understands particular inputs with a specific data structure and then transform said structure into an Ubidots-readable output.
Types of Plugins
1. Device Management Platforms to Ubidots
- A device management platform offered by your OEM or hardware provider. This is the case when working with Particle.io, Monnit.com, mcThings.com, and more:
2. Connectivity and Telecommunication Platforms to Ubidots
- A platform offered by connectivity or telecommunications provider. This would be the case of LoRaWAN operators such as Comcast’s MachineQ, The Things Network, Sigfox, and more:
3. Data Storage Servers to Ubidots
- An IoT-specific backend, such as AWS, Azure or IBM Bluemix, where you can perform data ingestion and then relay said data to Ubidots for enablement:
4. Spot-data APIs to Ubidots
- Lastly, your data can even come from devices you don’t own or operate (like weather stations that feed data to WeatherUnderground or OpenWeatherMaps) - and even virtual sources! (like the Energy prices of the US Energy Information Administration - EIA.
3. Creating a Plugin
The Device Plugin feature presently is a tool within the larger UbiFunction engine. Accordingly, you can code your plugin's using "Functions" located in the Device Management tab of your Ubidots Admin account navbar.
If you do not yet have the UbiFunctions add-on enabled in your Ubidots account, you can quickly enable it from the billing section of an Admin account, or by clicking here.
Step 1: Click the blue "+" icon to create your first plugin function:
Step 2: Give the parsing function a name that describes the type of device you're plugging into Ubidots. We recommend using the format "Brand-Reference", i.e. "mcthings-mctrack" or "digitalmatter-oyster".
Step 3: Click on "Make it live" to deploy an API endpoint URL containing the name of your function. You should see the updated URL created directly from the UbiFunction tool. This endpoint where be where you point any data coming to Ubidots.
4. Coding the Plugin Parsing Function
By default, every new UbiFunction is populated with a sample code that uses input data (TOKEN, Device, & Temp Value) to make a request to Ubidots API. This sample code demonstrates a simple HTTP GET endpoint that receives an Ubidots token, a device label, and a temperature value as URL parameters, then uses this data to make an HTTP POST request to Ubidots API. See below for some already available integrations or plugins to get your data from other popular IoT Platforms.
- LoRaWAN Devices –> Comcast machineQ Platform –> Ubidots (show me how)
- LoRaWAN Devices –> The Things Network –> Ubidots (show me how)
- Sigfox Devices –> Sigfox Cloud –> Ubidots (show me how)
- Sensoterra Devices –> Sensoterra Cloud –> Ubidots (show me how)
- AmbientWeather devices → AmbientWeather Cloud → Ubidots (See example)
5. Testing the Plugin Function
During the development process, you will want to test your function to see if you are on the right track towards the desired output. To do so, click on "Run Function." This will being up an modal screen requesting some input data to test with. If your function requires an input, you need only enter a JSON dictionary of sample inputs. You may leave this blank if your function does not require an input.
In the case of Ubidots default sample function, enter the JSON payload below containing the parameters you look to pass through the HTTP GET request:
After clicking on "Run with this input" a console window will emerge with both the output and the console of the results:
- Output: This is what your function returns. It must be in a JSON dictionary format. In your code, make sure to use "return" to quit the function and return the dictionary.
- Console: This is used to debug purposes. Use console.log("hello") to leave trails in this console.
6. Extra Support?
Need help coding your Ubifunction? Feel free to ask for help to our support team via the in-app chat channel or via email at firstname.lastname@example.org.
Want to share a helpful function to teach others how to connect the dots? Feel free to post it at community.ubidots.com and help another IoT innovator achieve their goals.
Other users also found helpful: