I am trying to get last device event using python but I get this error:
wiotp.sdk.application.client.ApplicationClient INFO Connected successfully:
a:orgid:5d633cbe-14c0-4d05-b4d6-86bf97a068d9
Traceback (most recent call last):
File "fetch_event_data_fromWatson_iot.py", line 23, in <module>
print("Event from device: %s:%s" % (event.typeId, event.deviceId))
AttributeError: 'str' object has no attribute 'typeId'.
My code is follows:
import wiotp.sdk.application
from wiotp.sdk.messages import Message, MessageCodec, JsonCodec, RawCodec, Utf8Codec
import json
import base64
myConfig = {
"auth":
{ "key": "-----",
"token": "-----"
}
}
client = wiotp.sdk.application.ApplicationClient(config=myConfig)
client.connect()
device = {"typeId": "ESP8266", "deviceId": "ecg", "eventId": "status"}
lastEvents = client.lec.get(device,"status")
for event in lastEvents:
print("Event from device: %s:%s" % (event.typeI`enter code here`d, event.deviceId))
print("- Event ID: %s " % (event.eventId))
print("- Format: %s" % (event.format))
print("- Cached at: %s" % (event.timestamp.isoformat()))
# The payload is always returned base64 encoded by the API
print("- Payload (base64 encoded): %s" % (event.payload))
# Depending on the content of the message this may not be a good idea (e.g. if it was originally binary data)
print("- Payload (decoded): %s" % (base64.b64decode(event.payload).decode('utf-8')))
#
client.disconnect()
question from:
https://stackoverflow.com/questions/65940129/unable-to-get-last-cached-device-event-from-watson-iot-while-using-application-i 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…