Skip to main content
All CollectionsConnect your Devices
Connect a Revolution Pi Core 3 to Ubidots over HTTP
Connect a Revolution Pi Core 3 to Ubidots over HTTP

Launch your Industrial applications with Revolution Pi and Ubidots – Energy Management, Process Monitoring, Machine Health and more.

Sergio M avatar
Written by Sergio M
Updated over 3 months ago

Revolution Pi is an open, modular, and durable industrial PC based on the established Raspberry Pi whilst meeting the EN61131-2 standard. Equipped with the Raspberry Pi Compute Module, the RevPi Core base can be expanded seamlessly using appropriate I/O modules and fieldbus gateways for energy management, process monitoring, machine health applications and more.

The Rev Pi Core is the foundation to any IoT application powered by Kunbus hardware and depending on your I/O requirements expansion modules such as RevPi DIO, RevPi AIO, RevPi Gates can be attached as digital, analog, or gateway modules. 

The Revolution Pi series begins with the base device, the RevPi Core and RevPi Core 3, the central processing unit of the modular system. Equipped with a quad-core processor with 1.2 GHz and 1 GByte RAM, the multi-core processor by Broadcom has enough power for complex tasks such as image processing or edge computing. Installed in a DIN rail housing and powered by 24 VDC the RevPi Core is built to last and requires standard energy input. 

In the following guide you will learn how to integrate your RevPi Core and RevPi Core 3 with Ubidots IoT Application Development platform. This guide will simulate Pressure, Temperature, and Humidity readings through a python firmware script, and push this data to you Ubidots account giving you the example code required to get your data online to be made valuable. 

This tutorial is designed for only RevPi Core setup, if you already have your core compiled and look to now work with some expansion modules, please reference the below setup article for additional integrations and application development: 

Revolution Pi Core Setup

Requirements

Step-by-Step

  1. Hardware Setup 

  2. Sending (POST) Data to Ubidots

  3. Data visualization

  4. Summary

1. Hardware Setup

To begin the setup of your RevPi Core or RevPi Core 3, reference the Quick Start Guide from Revolution Pi to get your device configured and connected. :) 

Once your RevPi Core is configured with the latest image version (Jessie) and properly connected to your PC, execute the below commands in the RevPi terminal:

NOTE: To be able to run the commands below, you must access the RevPi. If you do not yet know how to access the RevPi's terminal, please refer to this guide.  

sudo apt-get update

then:

sudo apt-get upgrade

NOTE: The commands above will take several minutes to update. The whole system is updating so please be patient.

2. Sending (POST) Data to Ubidots 

We decided to use Python programming language because of its ease-of-use when with the RevPi Core. If you wish to code in another language please reference the Revolution Pi forum for additional details in firmware support.  

If this is your first time working with Python in your RevPi Core, have a peak at this video to become a bit more familiar:

 1. To begin writing your firmware, create a Python script in the RevPi Core terminal. We are going to use the nano editor to get this done. To create the new script, enter and execute the command below:

nano ubidots_revpi.py

As you will see, the nano editor terminal will automatically populate and you can begin writing your code. 

Please copy and paste the sample code below into the nano editor. Once pasted, assign your Ubidots Token where indicated in the script. Reference here for help locating your Ubidots token if you cannot find

In this sample code we have written the delay for data communication with Ubidots to be every 1 second. If you wish extend this delay to save on your Application's data consumption, you can do so simply do so by adjusting the "Delay = 1" line. 

NOTE: To save the script into the nano editor - press Ctrl+O, confirm the file name to write (ubidots_revpi.py) and press enter. To close the nano editor press Ctrl+X.


################################################################################
# This script simulates different sensors values using the random module and make
# a HTTP request to Ubidots Cloud (https://ubidots.com/)
#
# Author: M. Hernandez
################################################################################

import requests
import time
import random
from uuid import getnode as get_mac

# Assign your Ubidots TOKEN
TOKEN = "{Assign_your_Ubidots_token}"
# Set the delay desired to post the data
DELAY = 1

'''
This method build the JSON to be sent to the Ubidots Cloud
'''
def build_json(variable_1, value_1, variable_2, value_2, variable_3, value_3):
    try:
        data = {variable_1: value_1, variable_2: value_2, variable_3: value_3}
        return data
    except:
        return None

'''  
This method make the HTTP Request to the Ubidots Cloud
'''
def post_variable(device, value_1, value_2, value_3):
    try:
        url = "https://industrial.api.ubidots.com/api/v1.6/devices/" + device
        headers = {"X-Auth-Token": TOKEN, "Content-Type": "application/json"}
        data = build_json("temperature", value_1, "humidity", value_2, "pressure", value_3)
        response = requests.post(url=url, headers=headers, json=data)
        return response.json()
    except:
        pass


if __name__ == "__main__":
    while True:
        mac = get_mac() # get the mac address of your device
        device_mac = ':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2))
        temp_value = random.randint(0,15)*2
        hum_value = random.randint(20,50)
        press_value = random.randint(2,50)*2
        print post_variable(device_mac, temp_value, hum_value, press_value)
        time.sleep(DELAY)


2. Now let's test the script. Run the script previously created in the RevPi terminal: 

python ubidots_revpi.py

Once the script begins to run, you will see the successful status code response from the Ubidots Server 201 :

3. Data visualization 

Go to your Ubidots account and verify the data has been received. You will see a new device automatically created in the Device section with the device name being the MAC address of your RevPi Core.

The advantage of assigning the RevPi Core MAC address as device label, is that the same script will serve all your RevPi Cores sending data to Ubidots, but needing only to adjust the MAC address in the code. This maintains that from the first time to the last time you send data to Ubidots, the data always remains stored in its proper digital device you have in Ubidots. 

Don't like the MAC address as your device's name in your Ubidots display? Don't worry! You can change the name to a more friendly one, but the device label will be stay as the MAC address so the Ubidots platform never get confused which hardware is updating which digital device in Ubidots. Check out this help center article to better understand Device Labels and Device Names in Ubidots.
​ 
Click on any device in your Device section to visualize the variables being recorded and sent to Ubidots from our sample firmware. As you can see, the sample code has provided three variables: humidity, pressure, and temperature. These can easily be adjusted in your code to fit the solution you are developing. 


IMPORTANT NOTE: As previously mentioned, the data published from the provided sample code is simulated. To begin sensing real world environments, you will need a expansion module of the Revolution Pi. One such as the RevPi DIO. To begin working with a expansion module like the RevPi DIO, please reference to this integration article to begin working with sensor and actuator data for your IoT Solution:

4. Summary  

In just a few minutes you've integrated the RevPi Core with Ubidots, sent some sample data using a mock Python code, and reported your work to Ubidots for data retention, visualization, and calculation. To deploy your Industrial solutions for monitoring or management, check out the full lineup of RevPi expansion modules that can be connected to Ubidots to enrich data to make decisions and improve processes. 

Now its time to create Ubidots Dashboards to visualize and understand your data to make the best decisions, simply and coherently. 

Did this answer your question?