Skip to content

Commit

Permalink
Added gateway provisioning and fix for datapoints key in message spli…
Browse files Browse the repository at this point in the history
…tting
  • Loading branch information
imbeacon committed Aug 21, 2024
1 parent 725cf0b commit e6904c4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tb_device_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,13 +681,13 @@ def __send_publish_with_limitations(self, kwargs, timeout, device=None, msg_rate
else:
device_data = data.get(device)
device_split_messages = self._split_message(device_data, dp_rate_limit.get_minimal_limit())
split_messages = [{'message': {device: [split_message['data']]}, 'dp': split_message['datapoints']}
split_messages = [{'message': {device: [split_message['data']]}, 'datapoints': split_message['datapoints']}
for split_message in device_split_messages]
if len(split_messages) == 0:
log.error("Cannot split message to smaller parts!")
results = []
for part in split_messages:
dp_rate_limit.increase_rate_limit_counter(part['dp'])
dp_rate_limit.increase_rate_limit_counter(part['datapoints'])
self._wait_for_rate_limit_released(timeout,
message_rate_limit=msg_rate_limit,
dp_rate_limit=dp_rate_limit,
Expand Down Expand Up @@ -888,7 +888,8 @@ def provision(host,
client_id=None,
username=None,
password=None,
hash=None):
hash=None,
gateway=None):
"""Provision the device in ThingsBoard. Returns the credentials for the device."""
provision_request = {
"provisionDeviceKey": provision_device_key,
Expand All @@ -910,6 +911,9 @@ def provision(host,
if device_name is not None:
provision_request["deviceName"] = device_name

if gateway is not None:
provision_request["gateway"] = gateway

provisioning_client = ProvisionClient(host=host, port=port, provision_request=provision_request)
provisioning_client.provision()
return provisioning_client.get_credentials()
Expand Down

0 comments on commit e6904c4

Please sign in to comment.