def main():
    client = TBDeviceMqttClient("127.0.0.1", "A2_TEST_TOKEN")
    client.connect()
    sub_id_1 = client.subscribe_to_attribute("uploadFrequency", callback)
    sub_id_2 = client.subscribe_to_all_attributes(callback)
    client.unsubscribe_from_attribute(sub_id_1)
    client.unsubscribe_from_attribute(sub_id_2)
import logging
import time

from tb_device_mqtt import TBDeviceMqttClient
logging.basicConfig(level=logging.DEBUG)


def callback(result):
    print(result)


client = TBDeviceMqttClient("127.0.0.1", "A2_TEST_TOKEN")
client.connect()
sub_id_1 = client.subscribe_to_attribute("uploadFrequency", callback)
sub_id_2 = client.subscribe_to_all_attributes(callback)
client.unsubscribe_from_attribute(sub_id_1)
client.unsubscribe_from_attribute(sub_id_2)
while True:
    time.sleep(1)
예제 #3
0
    if request_body["method"] == "getCPULoad":
        client.send_rpc_reply(request_id,
                              {"CPU percent": psutil.cpu_percent()})
    elif request_body["method"] == "getMemoryUsage":
        client.send_rpc_reply(request_id,
                              {"Memory": psutil.virtual_memory().percent})


client = TBDeviceMqttClient("127.0.0.1", "A2_TEST_TOKEN")
client.set_server_side_rpc_request_handler(on_server_side_rpc_request)
client.connect()
# to fetch the latest setting for upload frequency configured on the server
client.request_attributes(shared_keys=["uploadFrequency"],
                          callback=on_upload_frequency_change)
# to subscribe to future changes of upload frequency
client.subscribe_to_attribute(key="uploadFrequency",
                              callback=on_upload_frequency_change)


def main():
    while True:
        client.send_telemetry({
            "cpu": psutil.cpu_percent(),
            "memory": psutil.virtual_memory().percent
        })
        print("Sleeping for " + str(uploadFrequency))
        time.sleep(uploadFrequency)


if __name__ == '__main__':
    main()