コード例 #1
0
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()
コード例 #2
0
#Access token of edge device 1
ACCESS_TOKEN_EDGE_1 = 'CnpDrS1iinb5fZ4dQD90'

#Sample
sensor_data = {'temperature': 1414114, 'humidity': 0}

#Controller device
client = TBDeviceMqttClient(THINGSBOARD_HOST, ACCESS_TOKEN)
client_to_edge = TBDeviceMqttClient(THINGSBOARD_HOST, ACCESS_TOKEN_EDGE_1)
client.connect()
client_to_edge.connect()

# Sending to attribute and checking the delivery status (QoS = 1 by default)
result = client.send_attributes({
    "Edge1_Len": 10,
    "Edge1_Straight": 7,
    "Edge1_Right": 3
})

# send to edge attribute
result2 = client_to_edge.send_attributes({
    "Edge1_Len": 10,
    "Edge1_Straight": 7,
    "Edge1_Right": 3
})

success = result.get() == TBPublishInfo.TB_ERR_SUCCESS

success2 = result2.get() == TBPublishInfo.TB_ERR_SUCCESS

コード例 #3
0
        "temperature": 42.2,
        "humidity": 71
    }
}, {
    "ts": 1451649601000,
    "values": {
        "temperature": 42.3,
        "humidity": 72
    }
}]
attributes = {"sensorModel": "DHT-22", "attribute_2": "value"}

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.disconnect()