Close
0%
0%

Connect your RevPi Core to Ubidots

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

Similar projects worth following
144 views
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.
  • Connect your RevPi Core to Ubidots

    Maria Carlina Hernandez01/10/2018 at 16:02 0 comments

    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: 

View project log

  • 1
    Requirements
    • Ethernet Cable
    • 24V Power Supply
  • 2
    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.

  • 3
    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
    

    2. 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)

    3. 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.

View all 5 instructions

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates