I'm having a problem with the Arduino IOT API. I'm trying to use the devicesV2TimeSeries function. I keep getting an error: "Invalid value for last_evaluated_key , must not be None ". This appears to be due to the fact that the function cannot populate the response structure correctly. I'm not sure what to do to debug this.
This appears to be a homework problem. With the information given I can only say sorry I cannot help! Post your code and a schematic, not a frizzy thing showing all interconnections and links to technical information on all hardware devices.
Gladly! No schematics needed. This is purely a software issue. Device/Thing are working perfectly. I just cannot dump the historic data from the Thing for local analysis.
My code is below. I've removed by CLIENT_ID's for security reasons. The last line will fail with an error: "C:\Users\jmdod\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\iot_api_client\models\arduino_devicev2propertyvalues.py", line 103, in last_evaluated_key
raise ValueError("Invalid value for last_evaluated_key, must not be None") # noqa: E501
ValueError: Invalid value for last_evaluated_key, must not be None
import os
import time
import iot_api_client as iot
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
DEVICE_ID = "50ff1f09-c510-4c14-a8a0-463eb7d68aa7"
global THING_ID
THING_ID = "254a0c9e-d995-47d5-a0e0-33c2899857d8"
global THING_PROPS
THING_PROPS=0
global CLIENT_ID
global CLIENT_SECRET
CLIENT_ID = ""
CLIENT_SECRET = ""
def get_client(cc):
try:
resp=iot.ApiClient(cc)
return(resp)
except iot.ApiException as e:
while(e.status==429):
time.sleep(1)
resp=iot.ApiClient(cc)
e=iot.ApiException()
if(e.status!=429):
return(resp)
def get_thing_props(c):
try:
resp=iot.PropertiesV2Api(c)
return(resp)
except iot.ApiException as e:
while(e.status==429):
time.sleep(1)
resp=iot.PropertiesV2Api(c)
e=iot.ApiException()
if(e.status!=429):
return(resp)
def get_proplist(t,tid):
try:
resp=t.properties_v2_list(tid)
return(resp)
except iot.ApiException as e:
while(e.status==429):
time.sleep(1)
resp=t.properties_v2_list(tid)
e=iot.ApiException()
if(e.status!=429):
return(resp)
def get_prop_id(t,tid,prop_name):
plist=get_proplist(t,tid)
for p in plist:
if p.name==prop_name:
return(p.id)
return(None)
def get_auth():
global CLIENT_ID,CLIENT_SECRET
oauth_client = BackendApplicationClient(client_id=CLIENT_ID)
token_url = "https://api2.arduino.cc/iot/v1/clients/token"
oauth = OAuth2Session(client=oauth_client)
token = oauth.fetch_token(token_url=token_url,client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,include_client_id=True,audience="https://api2.arduino.cc/iot")
return token
def get_client(token):
client_config = iot.Configuration(host="https://api2.arduino.cc/iot")
client_config.access_token = token.get("access_token")
client = iot.ApiClient(client_config)
return(client)
if name == "main":
token=get_auth()
print(">>",end="",flush=True)
time.sleep(1)
client=get_client(token)
print(">>",end="",flush=True)
time.sleep(1)
devices = iot.DevicesV2Api(client)
print(">>",end="",flush=True)
time.sleep(1)
things=iot.ThingsV2Api(client)
print(">>",end="\n")
thing_props=get_thing_props(client)
time.sleep(1)
prop_id=get_prop_id(thing_props,THING_ID,"flow0")
date="2021-06-10T00:00:00Z"
resp=devices.devices_v2_timeseries(DEVICE_ID, prop_id,limit=2,start=date)
Sorry. I guess I could have formatted the python code better.
import os
import time
import iot_api_client as iot
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
DEVICE_ID = "50ff1f09-c510-4c14-a8a0-463eb7d68aa7"
global THING_ID
THING_ID = "254a0c9e-d995-47d5-a0e0-33c2899857d8"
global THING_PROPS
THING_PROPS=0
global CLIENT_ID
global CLIENT_SECRET
CLIENT_ID = "Gkk8M2RWjQYiP5GgkT38EQYCz259NV6b" # get a valid one from your Arduino Create account
CLIENT_SECRET = "rZfviB5YOEb5Z5YdQgNabGaZtjhzzOsNGp972jA9GNzkbyQapr1Mg1De5Kc7RRUB"
def get_client(cc):
try:
resp=iot.ApiClient(cc)
return(resp)
except iot.ApiException as e:
while(e.status==429):
time.sleep(1)
resp=iot.ApiClient(cc)
e=iot.ApiException()
if(e.status!=429):
return(resp)
def get_thing_props(c):
try:
resp=iot.PropertiesV2Api(c)
return(resp)
except iot.ApiException as e:
while(e.status==429):
time.sleep(1)
resp=iot.PropertiesV2Api(c)
e=iot.ApiException()
if(e.status!=429):
return(resp)
def get_proplist(t,tid):
try:
resp=t.properties_v2_list(tid)
return(resp)
except iot.ApiException as e:
while(e.status==429):
time.sleep(1)
resp=t.properties_v2_list(tid)
e=iot.ApiException()
if(e.status!=429):
return(resp)
def get_prop_id(t,tid,prop_name):
plist=get_proplist(t,tid)
for p in plist:
if p.name==prop_name:
return(p.id)
return(None)
def get_auth():
global CLIENT_ID,CLIENT_SECRET
oauth_client = BackendApplicationClient(client_id=CLIENT_ID)
token_url = "https://api2.arduino.cc/iot/v1/clients/token"
oauth = OAuth2Session(client=oauth_client)
# This will fire an actual HTTP call to the server to exchange client_id and
# client_secret with a fresh access token
token = oauth.fetch_token(token_url=token_url,client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,include_client_id=True,audience="https://api2.arduino.cc/iot")
return token
def get_client(token):
client_config = iot.Configuration(host="https://api2.arduino.cc/iot")
# client_config.debug = True
client_config.access_token = token.get("access_token")
#print("Got access token")
# Create the iot-api Python client with the given configuration
client = iot.ApiClient(client_config)
#print("Got Client")
return(client)
if __name__ == "__main__":
token=get_auth()
print(">>",end="",flush=True)
time.sleep(1)
client=get_client(token)
print(">>",end="",flush=True)
time.sleep(1)
devices = iot.DevicesV2Api(client)
print(">>",end="",flush=True)
time.sleep(1)
things=iot.ThingsV2Api(client)
print(">>",end="\n")
thing_props=get_thing_props(client)
time.sleep(1)
prop_id=get_prop_id(thing_props,THING_ID,"flow0")
date="2021-06-10T00:00:00Z"
resp=devices.devices_v2_timeseries(DEVICE_ID, prop_id,limit=2,start=date)
Same Problem. Frustration ...
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.