def main(): client = TBDeviceMqttClient(THINGSBOARD_HOST, DEVICE_ACCESS_TOKEN) client.connect() rc = client.claim(secret_key=SECRET_KEY, duration=DURATION).get() if rc == 0: print("Claiming request was sent.") client.stop()
def main(): client = TBDeviceMqttClient("127.0.0.1", "A2_TEST_TOKEN") # we set maximum amount of messages sent to send them at the same time. it may stress memory but increases performance client.max_inflight_messages_set(100) client.connect() results = [] result = True for i in range(0, 100): results.append(client.send_telemetry(telemetry_with_ts)) for tmp_result in results: result &= tmp_result.get() == TBPublishInfo.TB_ERR_SUCCESS print("Result " + str(result)) client.stop()
def main(): client = TBDeviceMqttClient("127.0.0.1", "A2_TEST_TOKEN") client.connect() # Sending data in async way client.send_attributes(attributes) client.send_telemetry(telemetry) client.send_telemetry(telemetry_as_array, quality_of_service=1) client.send_telemetry(telemetry_with_ts) client.send_telemetry(telemetry_with_ts_as_array) # Waiting for data to be delivered result = client.send_attributes(attributes) result.get() print("Attribute update sent: " + str(result.rc() == TBPublishInfo.TB_ERR_SUCCESS)) result = client.send_attributes(attributes) result.get() print("Telemetry update sent: " + str(result.rc() == TBPublishInfo.TB_ERR_SUCCESS)) client.stop()
def main(): """ We can provide the following parameters to provisioning function: host - required - Host of ThingsBoard provision_device_key - required - device provision key from device profile provision_device_secret - required - device provision secret from device profile port=1883 - not required - MQTT port of ThingsBoard instance device_name=None - may be generated on ThingsBoard - You may pass here name for device, if this parameter is not assigned, the name will be generated ### Credentials type = ACCESS_TOKEN access_token=None - may be generated on ThingsBoard - You may pass here some access token and it will be saved as accessToken for device on ThingsBoard. ### Credentials type = MQTT_BASIC client_id=None - not required (if username is not None) - You may pass here client Id for your device and use it later for connecting username=None - not required (if client id is not None) - You may pass here username for your client and use it later for connecting password=None - not required - You may pass here password and use it later for connecting ### Credentials type = X509_CERTIFICATE hash=None - required (If you wanna use this credentials type) - You should pass here public key of the device, generated from mqttserver.jks """ # Call device provisioning, to do this we don't need an instance of the TBDeviceMqttClient to provision device credentials = TBDeviceMqttClient.provision("127.0.0.1", "PROVISION_DEVICE_KEY", "PROVISION_DEVICE_SECRET") if credentials is not None: client = TBDeviceMqttClient("127.0.0.1", credentials) client.connect() # Sending data in async way client.stop()