SoftwareAG / cumulocity-devicemanagement-agent

Cumulocity Reference Agent written in Python to demonstrate most of the Device Management Capabilities of Cumulocity IoT
Apache License 2.0
26 stars 20 forks source link

Agent fails with 'NoneType' object is not subscriptable on RPI #59

Closed sagIoTPower closed 2 years ago

sagIoTPower commented 2 years ago

When running the dm agent outside of docker

c8ydm.start

on RPi IV using the settings:

tls = true
cert_auth = true

I get the following exception:

Starting...
2022-07-17 19:10:34,411 MainThread INFO root Serial: 3332221
2022-07-17 19:10:34,412 MainThread INFO c8ydm.client.mqtt_agent Starting agent
2022-07-17 19:10:34,706 Thread-1 INFO c8ydm.client.mqtt_agent Agent connected with result code: 0
2022-07-17 19:10:35,662 MainThread INFO c8ydm.client.mqtt_agent Starting refresh token thread 
2022-07-17 19:10:35,664 TokenThread-1 INFO c8ydm.client.mqtt_agent Refreshing Token
SenseHat not available
2022-07-17 19:10:35,991 InitializerThread-AgentInitializer INFO c8ydm.agentmodules.agent_initializer Agent Initializer called...
2022-07-17 19:10:35,994 InitializerThread-DockerSensor INFO c8ydm.agentmodules.docker_watcher Docker Initializer called...
2022-07-17 19:10:36,001 InitializerThread-EventInitializer INFO c8ydm.agentmodules.event_initializer Event Initializer called...
2022-07-17 19:10:36,008 InitializerThread-Network INFO c8ydm.agentmodules.network Network Initializer called...
2022-07-17 19:10:36,032 InitializerThread-SmartRestInitializer INFO c8ydm.agentmodules.smartRest_inizializer SmartRest Template Initializer called...
2022-07-17 19:10:36,035 InitializerThread-SmartRestInitializer ERROR c8ydm.client.rest_client The following error occured while trying to check for existing SmartRest templates: 'NoneType' object is not subscriptable
2022-07-17 19:10:36,036 InitializerThread-SmartRestInitializer INFO c8ydm.agentmodules.smartRest_inizializer SmartRest Template does not exist, creating....
2022-07-17 19:10:36,036 InitializerThread-SmartRestInitializer ERROR c8ydm.client.rest_client The following error occured while trying to create SmartRest template: 'NoneType' object is not subscriptable
2022-07-17 19:10:36,071 MainThread INFO c8ydm.client.mqtt_agent Supported operations:
2022-07-17 19:10:36,240 MainThread INFO c8ydm.client.mqtt_agent {'c8y_DeviceProfile', 'c8y_MeasurementRequestOperation', 'c8y_RemoteAccessConnect', 'c8y_DownloadConfigFile', 'c8y_SoftwareList', 'c8y_Restart', 'c8y_UploadConfigFile', 'c8y_Firmware', 'c8y_Message', 'c8y_Command', 'c8y_SoftwareUpdate', 'c8y_Configuration', 'c8y_LogfileRequest', 'c8y_Docker'}
2022-07-17 19:10:36,807 MainThread INFO c8ydm.client.mqtt_agent Required interval: 10
2022-07-17 19:10:36,813 MainThread INFO c8ydm.client.mqtt_agent Model:
2022-07-17 19:10:36,814 MainThread INFO c8ydm.client.mqtt_agent ['3332221', 'raspberry', '1.0']
2022-07-17 19:10:36,950 MainThread INFO c8ydm.client.mqtt_agent Subscribing to XID: c8y-dm-agent-v1.0
2022-07-17 19:10:37,480 InitializerThread-DockerSensor ERROR c8ydm.client.rest_client The following error occured: 'NoneType' object is not subscriptable
2022-07-17 19:10:37,481 MainThread ERROR c8ydm.client.rest_client The following error occured: 'NoneType' object is not subscriptable
2022-07-17 19:10:37,548 InitializerThread-DockerSensor ERROR c8ydm.client.rest_client The following error occured: 'NoneType' object is not subscriptable
2022-07-17 19:10:37,582 MainThread ERROR c8ydm.client.rest_client The following error occured: 'NoneType' object is not subscriptable
--- Logging error ---
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.7/site-packages/c8ydm/client/mqtt_agent.py", line 100, in run
    self.__init_agent()
  File "/home/pi/.local/lib/python3.7/site-packages/c8ydm/client/mqtt_agent.py", line 283, in __init_agent
    self.rest_client.set_operations_to_failed(ops)
  File "/home/pi/.local/lib/python3.7/site-packages/c8ydm/client/rest_client.py", line 320, in set_operations_to_failed
    if len(operations) > 0:
TypeError: object of type 'NoneType' has no len()

The registration in the cloud works, but it seems that no measurements are send to the could tenant. What could be the issue?

switschel commented 2 years ago

The same error has been fixed with https://github.com/SoftwareAG/cumulocity-devicemanagement-agent/commit/5b2465af25fc4e63b44ea3ccc6846f3ab3f97d43

Are you sure you're running the latest version? The Initializer will not run if the token is not there with the newest version.

The lines posted in the trace are not matching to the latest versions: File "/home/pi/.local/lib/python3.7/site-packages/c8ydm/client/mqtt_agent.py", line 283, in __init_agent self.rest_client.set_operations_to_failed(ops)

For me this is line 292