-
1Requirements
-
2Hardware 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.
-
3Firmware 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.
-
4Visualize 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:
-
5Results
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.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.