Пример #1
0
def main(argv):
    """Main entry point for starting the agent client"""
    global pidfile
    configfile = None
    logfile = None
    i = 1
    setInfo()
    while i < len(argv):
        if argv[i] in ["-c", "-C", "--config-file"]:
            configfile = argv[i + 1]
            i += 1
        elif argv[i] in ["-l", "-L", "--log-file"]:
            logfile = argv[i + 1]
            i += 1
        elif argv[i] in ["-h", "-H", "--help"]:
            displayHelp()
        elif argv[i] in ["-d", "--debug"]:
            setDebug()
        elif argv[i] in ["-P", "--pidfile"]:
            pidfile = argv[i + 1]
            i += 1
        i += 1
    if configfile == None:
        configfile = './etc/Network.ini'
    writePidToFile(pidfile)
    logToFile(logfile)
    config = Config(configfile)
    HOST = config.get('CONFIG', 'ServerAddress', 'mqtt.mydevices.com')
    PORT = config.getInt('CONFIG', 'ServerPort', 8883)
    CayenneApiHost = config.get('CONFIG', 'CayenneApi',
                                'https://api.mydevices.com')
    global client
    client = CloudServerClient(HOST, PORT, CayenneApiHost)
    client.Start()
Пример #2
0

# 消息处理函数
def on_message_come(lient, userdata, msg):
    print(msg.topic + " " + ":" + str(msg.payload))


    # subscribe 消息
def on_subscribe():
    print("on_publish")
    mqttClient.subscribe("/server", 1)
    mqttClient.on_message = on_message_come  # 消息到来处理函数


if __name__ == "__main__":
    # on_publish("v1/demo/things/demo_wd/data/json", "Hello Python!", 1)
    setDebug()
    client = CloudServerClient("192.168.8.102", 1883, "192.168.8.102")
    client.Start()
    for i in range(10):
        print(i)
        client.SendSystemInfo()
        sleep(1)

    # # client.Start()

    # on_mqtt_connect()
    # for i in range(10):
    #     on_publish("v1/demo/things/demo_wd/data/json", "Hello Python!", 1)
    #     sleep(1)