Ejemplo n.º 1
0
def main():
    """
        Main service for provisioning server
    """

    parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
    parser.add_argument(
        '--host',
        default=get_default_value_from_env('WM_SERVICES_MQTT_HOSTNAME'),
        help="MQTT broker address")
    parser.add_argument('--port',
                        default=get_default_value_from_env(
                            'WM_SERVICES_MQTT_PORT', 8883),
                        type=int,
                        help='MQTT broker port')
    parser.add_argument('--username',
                        default=get_default_value_from_env(
                            'WM_SERVICES_MQTT_USERNAME', 'mqttmasteruser'),
                        help='MQTT broker username')
    parser.add_argument(
        '--password',
        default=get_default_value_from_env('WM_SERVICES_MQTT_PASSWORD'),
        help='MQTT broker password')
    parser.add_argument(
        '--config',
        default=get_default_value_from_env(
            'WM_PROV_CONFIG',
            '/home/wirepas/wm-provisioning/vars/settings.yml'),
        type=str,
        help=
        'The path to your .yml config file: \"examples/provisioning_config.yml\"'
    )
    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)

    srv = ProvisioningServer(interface=wni, settings=args.config)
    srv.loop()
Ejemplo n.º 2
0
def main():
    # Get "Wirepas Network Interface" parameters from command line interface.
    nw_iface_params = network_interface_get_parameters()

    # Connect to MQTT broker.
    print("connecting to {}:{} ...".format(nw_iface_params.host,
                                           nw_iface_params.port))

    # Create "Wirepas Network Interface" and enable its logger
    logging.basicConfig(format='%(levelname)s %(asctime)s %(message)s',
                        level=logging.INFO)
    wni = WirepasNetworkInterface(nw_iface_params.host,
                                  nw_iface_params.port,
                                  nw_iface_params.username,
                                  nw_iface_params.password,
                                  insecure=nw_iface_params.force_unsecure)

    # Launch shell used to send or receive evaluation application messages
    # to/from the Wirepas Massive network.
    BackendShell(wni).cmdloop()  # Main process.
Ejemplo n.º 3
0
    parser.add_argument('--username',
                        help="MQTT broker username")
    parser.add_argument('--password',
                        help="MQTT broker password")
    parser.add_argument('--insecure',
                        dest='insecure',
                        action='store_true',
                        help="MQTT use unsecured connection")

    args = parser.parse_args()

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

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

    def on_config_changed():
        line = ""
        for gw, sink, _ in wni.get_sinks():
            line += "[%s:%s] " % (gw, sink)

        print(datetime.datetime.now())
        print(line)

    wni.set_config_changed_cb(on_config_changed)

    input()
    parser.add_argument('--sink', required=True, help="the sink to configure")

    parser.add_argument(
        '--sink_address',
        type=int,
        help="the sink address. Other sink settings are hardcoded inside script"
    )
    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)

    found = False
    for gw, sink, config in wni.get_sinks():
        if gw != args.gateway:
            continue

        if sink != args.sink:
            continue

        # Sink is founded
        found = True
        print("Sink %s:%s is found" % (args.gateway, args.sink))
                        action='store_true',
                        help="MQTT use unsecured connection")

    parser.add_argument('--network',
                        type=int,
                        help="Network address concerned by update",
                        required=True)

    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)

    app_config_helper = WirepasTLVAppConfigHelper(wni, network=args.network)

    # Display current app config
    print(app_config_helper)

    # The following example will add two new entries in TLV format in all app config from
    # network args.network and remove one if it exists.
    # It will generate an error and not update the app config if one of the gateway doesn't
    # have enough room for it
    res = app_config_helper.add_raw_entry(0x6666, b'\x00\x00\x12\x34')\
                           .add_raw_entry(0x32, b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A')\
                           .remove_raw_entry(0x5555)\
Ejemplo n.º 6
0
                        default='mqttmasteruser',
                        help="MQTT broker username")
    parser.add_argument('--password', help="MQTT broker password")
    parser.add_argument('--insecure',
                        dest='insecure',
                        action='store_true',
                        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,
Ejemplo n.º 7
0
                        help="MQTT broker password")
    parser.add_argument('--insecure',
                        dest='insecure', action='store_true',
                        help="MQTT use unsecured connection")

    parser.add_argument('--network',
                        type=int,
                        help="Network address concerned by update")

    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)

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

    for gw, sink, config in wni.get_sinks(network_address=args.network):
        print("Set new config to %s:%s" % (gw, sink))
        try:
            res = wni.set_sink_config(gw, sink, {"network_channel": 10})
            if res != wmm.GatewayResultCode.GW_RES_OK:
                print("Cannot set new config to %s:%s res=%s" % (gw, sink, res))
        except TimeoutError:
            print("Cannot set new config to %s:%s" % (gw, sink))
Ejemplo n.º 8
0
        help="Delay in seconds to listen for network traffic and discover nodes"
    )

    parser.add_argument(
        '--output_folder',
        help="Folder to store file containing list of nodes at the end, "
        "otherwise list is printed on standard output")

    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)

    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)