I use the below code and put a right Master Api key from the setting of personal xively site but the result is "SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)" . don't know why it occurred.
from time import localtime, strftime
import time
import requests
import random
Base URL for the requests
url = 'https://api.xively.com'
Replace with your master API key and feed IDs of your devices
MASTER_API_KEY = '***********'
feed_ID_1 = '******'
feed_ID_2 = '******'
feed_ID_3 = '******'
Function for updating all channels of a device using the requests library
:param feed_id: feed ID of a device
:param temperature: temperature value to be updated to a channel
:param humidity: humidity value to be updated to a channel
:param lux: lux value to be updated to a channel
def update_channels(feed_id, temperature, humidity, light):
url_feed =url + '/v2/feeds/' + str(feed_id) + '.json' headers = {'X-ApiKey': str(MASTER_API_KEY)}
payload = '{ \ "version":"1.0.0", \ "datastreams" : [ { \ "id" : "humidity", \ "current_value" : '+str(humidity)+' \ }, \ { \ "id" : "light", \ "current_value" : '+str(light)+' \ }, \ { \ "id" : "temperature", \ "current_value" : '+str(temperature)+' \ } \ ] \ } '\
try: r = requests.put(url=url_feed, headers=headers, data=payload) print (strftime("%a, %d %b %Y %H:%M:%S", localtime()))
print (payload)
print (r.text)
print (r.status_code)
except Exception as e:
print(e)Loop for updating 3 devices with random values from a given ranges
while True:
update_channels(feed_ID_1,random.uniform(20.0,22.0),random.uniform(50.0,51.0),random.uniform(320.0,325.0)) update_channels(feed_ID_2,random.uniform(22.0,24.0),random.uniform(51.0,52.0),random.uniform(325.0,330.0)) update_channels(feed_ID_3,random.uniform(24.0,26.0),random.uniform(52.0,53.0),random.uniform(330.0,335.0)) time.sleep(1)