15
15
import logging
16
16
from copy import deepcopy
17
17
from inspect import signature
18
+ from re import split
18
19
from time import sleep
19
20
20
21
import paho .mqtt .client as paho
@@ -246,20 +247,20 @@ def get_rate_limits_by_host(host, rate_limit, dp_rate_limit):
246
247
def get_rate_limit_by_host (host , rate_limit ):
247
248
if rate_limit == "DEFAULT_TELEMETRY_RATE_LIMIT" :
248
249
if "thingsboard.cloud" in host :
249
- rate_limit = "5 :1,60:60,"
250
+ rate_limit = "10 :1,60:60,"
250
251
elif "tb" in host and "cloud" in host :
251
- rate_limit = "5 :1,60:60,"
252
+ rate_limit = "10 :1,60:60,"
252
253
elif "demo.thingsboard.io" in host :
253
- rate_limit = "5 :1,60:60,"
254
+ rate_limit = "10 :1,60:60,"
254
255
else :
255
256
rate_limit = "0:0,"
256
257
elif rate_limit == "DEFAULT_MESSAGES_RATE_LIMIT" :
257
258
if "thingsboard.cloud" in host :
258
- rate_limit = "5 :1,60:60,"
259
+ rate_limit = "10 :1,60:60,"
259
260
elif "tb" in host and "cloud" in host :
260
- rate_limit = "5 :1,60:60,"
261
+ rate_limit = "10 :1,60:60,"
261
262
elif "demo.thingsboard.io" in host :
262
- rate_limit = "5 :1,60:60,"
263
+ rate_limit = "10 :1,60:60,"
263
264
else :
264
265
rate_limit = "0:0,"
265
266
else :
@@ -767,13 +768,16 @@ def __send_publish_with_limitations(self, kwargs, timeout, device=None, msg_rate
767
768
data = kwargs .get ("payload" )
768
769
if isinstance (data , str ):
769
770
data = loads (data )
770
- payload = data
771
771
topic = kwargs .get ("topic" , '' )
772
- if topic .endswith ('telemetry' ) or topic .endswith ('attributes' ):
772
+ attributes_format = topic .endswith ('attributes' )
773
+ if topic .endswith ('telemetry' ) or attributes_format :
773
774
if device is None or data .get (device ) is None :
774
775
device_split_messages = self ._split_message (data , dp_rate_limit .get_minimal_limit (),
775
776
self .max_payload_size )
776
- split_messages = [{'message' : split_message ['data' ], 'datapoints' : split_message ['datapoints' ]}
777
+ if attributes_format :
778
+ split_messages = [{'message' : msg_data , 'datapoints' : len (msg_data )} for split_message in device_split_messages for msg_data in split_message ['data' ]]
779
+ else :
780
+ split_messages = [{'message' : split_message ['data' ], 'datapoints' : split_message ['datapoints' ]}
777
781
for split_message in device_split_messages ]
778
782
else :
779
783
device_data = data .get (device )
@@ -784,9 +788,6 @@ def __send_publish_with_limitations(self, kwargs, timeout, device=None, msg_rate
784
788
else :
785
789
split_messages = [{'message' : data , 'datapoints' : 0 }]
786
790
787
- if len (split_messages ) == 0 :
788
- log .debug ("Cannot split message to smaller parts: %r" , payload )
789
-
790
791
results = []
791
792
for part in split_messages :
792
793
if not part :
0 commit comments