1

Trying to register devices using Thingsboard provided REST API Client (Python). (https://thingsboard.io/docs/reference/python-rest-client/)

I have installed Thingsboard in AWS EC2 instance (Linux 20.04). Python 3.8.10. Required TB related package is already installed. Such as 'tb-rest-client'.

While I can register an 'Asset', but failed to register device, which is my aim actually. Asset is optional for me, at least now. Though it should be similar.

Raising issues for the following line:

File "testTB_01.py", line 59, in <module>
   device = Device(name="Thermometer 1", type="thermometer") # this is line 59

Here is the error msg:

raise ValueError("Invalid value for `device_profile_id`, must not be `None`")  # noqa: E501
ValueError: Invalid value for `device_profile_id`, must not be `None`

Though I definitely have a value as I am using the example as it is. So not sure where it is going wrong.

Fakir
  • 139
  • 11

1 Answers1

0

looks like their example is out of date and there is some inconsistency in their code. According to declaration of Device class in tb_rest_client.models.models_pe.device argument device_profile_id is indeed optional, yet if you look closer into it's setter in line 329 you will see that ValueError is raised if value for the argument is not given. Just set anything for device_profile_id and it'll work.
Example:

device = Device(name="Thermometer 1", type="thermometer", device_profile_id="anything")
Norbiox
  • 69
  • 4
  • Thank you for your suggestion. I have modified accordingly and the previous error is gone. But now the 'Error code 500' with ' message: JSON parse error' appears. – Fakir Mar 13 '23 at 08:10
  • Seems this error is due to the next line, where the 'rest_client' is used. "device = rest_client.save_device(device)" . Without this line in the code, error is gone, but not device is created in Thingsboard. Seems the parameters are mismatching. – Fakir Mar 13 '23 at 08:24
  • Maybe the `device_profile_id` argument is expected to have some specific value. Anyway it looks like a case for their support, you should definitely ask them about it. – Norbiox Mar 13 '23 at 09:50
  • I actually post this on TB forum on last Friday. But did not get any reply yet. So thought about posting here, in case anyone knows. Thank you. – Fakir Mar 13 '23 at 10:15
  • @Fakir Were you able to find a solution for the issue? – Santhosh May 02 '23 at 09:50
  • 1
    @Santhosh I couldn't be able to do that in this way. But could register devices in bulk through CSV file to Thingsboard using API. That was my actual intention, so I no longer pursue the above process anymore. If you are interested in CSV-file device register, pl let me know. Btw, there is no bulk-deletion API. you have to do it recursively. – Fakir May 07 '23 at 04:44