Revolution Pi is an open, modular, and durable industrial PC based on the established Raspberry Pi while 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 and more.

The Rev Pi Core is the foundation to any application 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 Cloud, simulate Pressure, Temperature, and Humidity readings through a python firmware script, and visualize this data in your own Ubidots application with ease. 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

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 last image version (Jessie) and properly connected device's terminal, execute the below commands:

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. 

Firmware setup 

We decided to use Python programming language, because of its easy of use with the RevPi Core. If you wish to code an 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, take 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 nano editor, in order to create the new script. To do this run the command  below:

nano ubidots_revpi.py

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

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.

In this sample code we have written delay for data communication with Ubidots to be every 1 second. If you wish extend this delay, 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://things.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:

Visualize your data

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, 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 device 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 to never get confused which device is which. 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, our sample code has provided three variables: humidity, pressure, and temperature:

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, please reference to the article below to build this integration for sensor and actuator readings:

  • add tittle and link

Results

In just a few minutes you 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. 

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?