Ejemplo n.º 1
0
                        help="MQTT use unsecured connection")

    args = parser.parse_args()

    logging.basicConfig(format='%(levelname)s %(asctime)s %(message)s',
                        level=logging.INFO)

    wni = WirepasNetworkInterface(args.host,
                                  args.port,
                                  args.username,
                                  args.password,
                                  insecure=args.insecure)

    def on_data_received(data):
        print("RX from %s:%s => %s" %
              (data.gw_id, data.sink_id, data.data_payload))

    # Register for any data
    wni.register_data_cb(on_data_received)

    while True:
        message = input("Write a message to send to all sinks\n")
        for gw, sink, config in wni.get_sinks():
            try:
                res = wni.send_message(gw, sink, config["node_address"], 1, 1,
                                       message.encode())
                if res != wmm.GatewayResultCode.GW_RES_OK:
                    print("Cannot send data to %s:%s res=%s" % (gw, sink, res))
            except TimeoutError:
                print("Cannot send data to %s:%s", gw, sink)
Ejemplo n.º 2
0
                                  insecure=args.insecure)

    if args.network is None:
        print("No network address provided")
        exit()

    if args.delay_s is None:
        print("No delay given to listen the network")
        exit()

    nodes = set()

    def on_data_rx(data):
        nodes.add(data.source_address)

    wni.register_data_cb(on_data_rx, network=args.network)

    print("Waiting for %d s to discover nodes" % args.delay_s)
    sleep(args.delay_s)

    print("In %d s, %d nodes were found in network 0x%x" %
          (args.delay_s, nodes.__len__(), args.network))

    if args.output_folder is not None:
        file = os.path.join(args.output_folder,
                            "list_nodes_" + strftime("%Y%m%d-%H%M%S"))
        with open(file, "w") as f:
            for node in nodes:
                f.write("%d\n" % node)
        print("Result written to %s" % file)
    else: