[SOLVED] Python ubidots code review

Hi,

I have scraped together some of the code which runs on RPi.

I noticed ubidots python library dos not support tags or name so only IDs can be send.

Does anyone knows a better approach?

I struggled some time before adding timeout logic. My code was simply stuck in ubidots library from time to time.

If anyone knows a better solution to replace timeout logic?

Best regards

Github sample code

Fortunately, both Python and Ubidots have made it soo easy to use HTTP requests, that is simpler to just hit Ubidots’ API directly than using a custom library (just 2 lines of code!):

1- Install requests (http://docs.python-requests.org/)

sudo pip install requests

2- Use it in the code:

import time
import requests
import math

c = 0

while(1):
    c = c + 1
    payload = {'variable1': round(20*math.cos(c),2), 'variable2': round(20*math.sin(c),2)}
    r = requests.post('http://things.ubidots.com/api/v1.6/devices/motor/?token=H8y1xxxxxxxx0Q1msMSLxxxxxx', data=payload)
    time.sleep(0.5)

These are the results of this code:

Please note that “motor” is the API label of the device:

Many thanks.

It is always nice to see what others are using.

Best regards

1 Like