def __init__(self):
        argparser = argparse.ArgumentParser()
        argparser.add_argument("-v",
                               "--verbose",
                               help="verbose",
                               default=False,
                               action="store_true")
        argparser.add_argument("-u",
                               "--url",
                               help="URL of the thingsboard server",
                               default="http://localhost:8080")
        argparser.add_argument("-t",
                               "--token",
                               help="token to access the thingsboard API",
                               required=True)
        argparser.add_argument(
            "-d",
            "--device",
            help="device ID of the gateway modem to send the command to",
            required=True)
        argparser.add_argument(
            "-a",
            "--active-access-class",
            help="the active access class to be configured on the GW modem",
            type=int,
            required=True)

        self.config = argparser.parse_args()

        api_client_config = Configuration()
        api_client_config.host = self.config.url
        api_client_config.api_key['X-Authorization'] = self.config.token
        api_client_config.api_key_prefix['X-Authorization'] = 'Bearer'
        self.api_client = ApiClient(api_client_config)
Exemple #2
0
def init_api():
    api_client_config = Configuration()
    api_client_config.host = "http://thingsboard.idlab.uantwerpen.be:8080"
    api_client_config.api_key['X-Authorization'] = "<Thingsboard API key>"
    api_client_config.api_key_prefix['X-Authorization'] = 'Bearer'
    api_client = ApiClient(api_client_config)
    return api_client
Exemple #3
0
    def __init__(self):
        argparser = argparse.ArgumentParser()
        argparser.add_argument("-v", "--verbose", help="verbose", default=False, action="store_true")
        argparser.add_argument("-u", "--url", help="URL of the thingsboard server", default="http://localhost:8080")
        argparser.add_argument("-t", "--token", help="token to access the thingsboard API", required=True)
        argparser.add_argument("-d", "--device", help="device ID of the gateway modem to send the command to",
                               required=True)

        self.config = argparser.parse_args()
        self.config.gateway1 = "427ab180-f79e-11e7-8c87-85e6dd10a2e8"
        self.config.gateway2 = "b6b48ad0-b95a-11e7-bebc-85e6dd10a2e8"
        self.config.gateway3 = "f1f7e740-b8b0-11e7-bebc-85e6dd10a2e8"
        self.config.gateway4 = "43e01b20-b967-11e7-bebc-85e6dd10a2e8"

        api_client_config = Configuration()
        api_client_config.host = self.config.url
        api_client_config.api_key['X-Authorization'] = self.config.token
        api_client_config.api_key_prefix['X-Authorization'] = 'Bearer'
        self.api_client = ApiClient(api_client_config)

        ThingsBoard.start_api(self.config)
Exemple #4
0
def start_api(config):
    global device_controller_api
    global device_api_controller_api
    global api_client

    api_client_config = Configuration()
    api_client_config.host = config.url
    api_client_config.api_key['X-Authorization'] = config.token
    api_client_config.api_key_prefix['X-Authorization'] = 'Bearer'
    api_client = ApiClient(api_client_config)

    device_controller_api = swagger_client.DeviceControllerApi(
        api_client=api_client)
    device_api_controller_api = swagger_client.DeviceApiControllerApi(
        api_client=api_client)
Exemple #5
0
  def __init__(self):
    argparser = argparse.ArgumentParser()
    argparser.add_argument("-v", "--verbose", help="verbose", default=False, action="store_true")
    argparser.add_argument("-b", "--broker", help="mqtt broker hostname", default="localhost")
    argparser.add_argument("-u", "--url", help="URL of the thingsboard server", default="http://localhost:8080")
    argparser.add_argument("-t", "--token", help="token to access the thingsboard API", required=True)
    self.mq = None
    self.connected_to_mqtt = False

    self.config = argparser.parse_args()
    self.connect_to_mqtt()

    api_client_config = Configuration()
    api_client_config.host = self.config.url
    api_client_config.api_key['X-Authorization'] = self.config.token
    api_client_config.api_key_prefix['X-Authorization'] = 'Bearer'
    api_client = ApiClient(api_client_config)

    self.device_controller_api = swagger_client.DeviceControllerApi(api_client=api_client)
    self.device_api_controller_api =swagger_client.DeviceApiControllerApi(api_client=api_client)
class GatewayCommandExample:
    def __init__(self):
        argparser = argparse.ArgumentParser()
        argparser.add_argument("-v",
                               "--verbose",
                               help="verbose",
                               default=False,
                               action="store_true")
        argparser.add_argument("-u",
                               "--url",
                               help="URL of the thingsboard server",
                               default="http://localhost:8080")
        argparser.add_argument("-t",
                               "--token",
                               help="token to access the thingsboard API",
                               required=True)
        argparser.add_argument(
            "-d",
            "--device",
            help="device ID of the gateway modem to send the command to",
            required=True)
        argparser.add_argument(
            "-a",
            "--active-access-class",
            help="the active access class to be configured on the GW modem",
            type=int,
            required=True)

        self.config = argparser.parse_args()

        api_client_config = Configuration()
        api_client_config.host = self.config.url
        api_client_config.api_key['X-Authorization'] = self.config.token
        api_client_config.api_key_prefix['X-Authorization'] = 'Bearer'
        self.api_client = ApiClient(api_client_config)

    def execute_rpc_command(self, device_id, json_alp_cmd):
        # TODO the device_api_controller_api.post_rpc_request_using_post() proxy does not seem to work unfortunately
        # we will do it by a manual POST to /api/plugins/rpc/oneway/ , which is the route specified
        # in the documentation
        cmd = {
            "method": "execute-alp-async",
            "params": jsonpickle.encode(json_alp_cmd),
            "timeout": 500
        }
        path_params = {'deviceId': device_id}
        query_params = {}
        header_params = {}
        header_params['Accept'] = self.api_client.select_header_accept(['*/*'])
        header_params[
            'Content-Type'] = self.api_client.select_header_content_type(
                ['application/json'])

        # Authentication setting
        auth_settings = ['X-Authorization']
        return self.api_client.call_api(
            '/api/plugins/rpc/oneway/{deviceId}',
            'POST',
            path_params,
            query_params,
            header_params,
            body=cmd,
            post_params=[],
            files={},
            response_type='DeferredResultResponseEntity',
            auth_settings=auth_settings,
            async=False)

    def run(self):
        # in this example we will instruct the modem in the GW to switch to another active class
        cmd = Command.create_with_write_file_action_system_file(
            DllConfigFile(active_access_class=self.config.active_access_class))
        self.execute_rpc_command(self.config.device, cmd)
Exemple #7
0
class gatewayTest:
    def __init__(self):
        argparser = argparse.ArgumentParser()
        argparser.add_argument("-v",
                               "--verbose",
                               help="verbose",
                               default=False,
                               action="store_true")
        argparser.add_argument("-u",
                               "--url",
                               help="URL of the thingsboard server",
                               default="http://localhost:8080")
        argparser.add_argument("-t",
                               "--token",
                               help="token to access the thingsboard API",
                               required=True)
        argparser.add_argument(
            "-d",
            "--device",
            help="device ID of the gateway modem to send the command to",
            required=True)

        self.config = argparser.parse_args()

        api_client_config = Configuration()
        api_client_config.host = self.config.url
        api_client_config.api_key['X-Authorization'] = self.config.token
        api_client_config.api_key_prefix['X-Authorization'] = 'Bearer'
        self.api_client = ApiClient(api_client_config)

    def execute_rpc_command(self, device_id, json_alp_cmd):
        # we will do it by a manual POST to /api/plugins/rpc/oneway/ , which is the route specified
        # in the documentation
        cmd = {
            "method": "execute-alp-async",
            "params": jsonpickle.encode(json_alp_cmd),
            "timeout": 500
        }
        path_params = {'deviceId': device_id}
        query_params = {}
        header_params = {}
        header_params['Accept'] = self.api_client.select_header_accept(['*/*'])
        header_params[
            'Content-Type'] = self.api_client.select_header_content_type(
                ['application/json'])

        # Authentication setting
        auth_settings = ['X-Authorization']
        return self.api_client.call_api(
            '/api/plugins/rpc/oneway/{deviceId}',
            'POST',
            path_params,
            query_params,
            header_params,
            body=cmd,
            post_params=[],
            files={},
            response_type='DeferredResultResponseEntity',
            auth_settings=auth_settings,
            async=False)

    def update_progress(self, progress):
        #print("\r[{0}] {1}%".format('#' * (progress / 10), progress))
        sys.stdout.write('\r')
        sys.stdout.write("[")
        sys.stdout.write("#" * (progress / 10) + "] ")
        sys.stdout.write("%.2f%%" % (progress, ))
        sys.stdout.flush()

    def run(self):
        # cmd = Command.create_with_return_file_data_action(file_id, data, interface_type=InterfaceType.HOST,interface_configuration=None)
        cmd = Command.create_with_return_file_data_action(
            file_id=40,
            data=[0x31, 0x41, 0x45],
            interface_type=InterfaceType.D7ASP,
            interface_configuration=D7config(
                qos=QoS(resp_mod=ResponseMode.RESP_MODE_NO),
                addressee=Addressee(access_class=0x11, id_type=IdType.NOID)))
        # cmd = {0x32, 0xd7, 0x01, 0x00, 0x10, 0x01, 0x20, 0x01, 0x00}
        # cmd = {0x011}
        self.execute_rpc_command(self.config.device, cmd)
        print("Send 1")

        self.update_progress(0)
        sleep(1)
        self.update_progress(20)
        sleep(1)
        self.update_progress(40)
        sleep(1)
        self.update_progress(60)
        sleep(1)
        self.update_progress(80)
        sleep(1)
        self.update_progress(100)

        self.execute_rpc_command(self.config.device, cmd)
        print()
        print("Send 2")
Exemple #8
0
class backendToGateway:
    def __init__(self):
        argparser = argparse.ArgumentParser()
        argparser.add_argument("-v", "--verbose", help="verbose", default=False, action="store_true")
        argparser.add_argument("-u", "--url", help="URL of the thingsboard server", default="http://localhost:8080")
        argparser.add_argument("-t", "--token", help="token to access the thingsboard API", required=True)
        argparser.add_argument("-d", "--device", help="device ID of the gateway modem to send the command to",
                               required=True)

        self.config = argparser.parse_args()
        self.config.gateway1 = "427ab180-f79e-11e7-8c87-85e6dd10a2e8"
        self.config.gateway2 = "b6b48ad0-b95a-11e7-bebc-85e6dd10a2e8"
        self.config.gateway3 = "f1f7e740-b8b0-11e7-bebc-85e6dd10a2e8"
        self.config.gateway4 = "43e01b20-b967-11e7-bebc-85e6dd10a2e8"

        api_client_config = Configuration()
        api_client_config.host = self.config.url
        api_client_config.api_key['X-Authorization'] = self.config.token
        api_client_config.api_key_prefix['X-Authorization'] = 'Bearer'
        self.api_client = ApiClient(api_client_config)

        ThingsBoard.start_api(self.config)

    def execute_rpc_command(self, device, json_alp_cmd):

        # we will do it by a manual POST to /api/plugins/rpc/oneway/ , which is the route specified
        # in the documentation
        cmd = {"method": "execute-alp-async", "params": jsonpickle.encode(json_alp_cmd), "timeout": 500}
        print(cmd)
        path_params = {'deviceId': device}
        query_params = {}
        header_params = {}
        header_params['Accept'] = self.api_client.select_header_accept(['*/*'])
        header_params['Content-Type'] = self.api_client.select_header_content_type(['application/json'])

        # Authentication setting
        auth_settings = ['X-Authorization']
        return self.api_client.call_api('/api/plugins/rpc/oneway/{deviceId}', 'POST',
                                        path_params,
                                        query_params,
                                        header_params,
                                        body=cmd,
                                        post_params=[],
                                        files={},
                                        response_type='DeferredResultResponseEntity',
                                        auth_settings=auth_settings,
                                        async=False)


    def update_progress(self, progress):
        #print("\r[{0}] {1}%".format('#' * (progress / 10), progress))
        sys.stdout.write('\r')
        sys.stdout.write("[")
        sys.stdout.write("#" * (progress / 10) + "] ")
        sys.stdout.write("%.2f%%" % (progress,))
        sys.stdout.flush()

    def run(self):
        # cmd = Command.create_with_return_file_data_action(file_id, data, interface_type=InterfaceType.HOST,interface_configuration=None)
        cmd = Command.create_with_return_file_data_action(file_id=40, data=[0x03],
                                                          interface_type=InterfaceType.D7ASP,
                                                          interface_configuration=D7config(
                                                              qos=QoS(resp_mod=ResponseMode.RESP_MODE_NO),
                                                              addressee=Addressee(access_class=0x11,
                                                                                  id_type=IdType.NOID)))
        #cmd = {0x32, 0xd7, 0x01, 0x00, 0x10, 0x01, 0x20, 0x01, 0x00}
        # cmd = {0x011}

        for x in range(5):
            print("Alert {} to node".format(x))
            try:
                ThingsBoard.execute_rpc_command(self.config.gateway1,
                                                [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31])
            except:
                print("Gateway {} not reached.".format(self.config.gateway1))
            sleep(0.5)
            try:
                ThingsBoard.execute_rpc_command(self.config.gateway2,
                                                [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31])
            except:
                print("Gateway {} not reached.".format(self.config.gateway2))
            sleep(0.5)
            try:
                ThingsBoard.execute_rpc_command(self.config.gateway3,
                                                [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31])
            except:
                print("Gateway {} not reached.".format(self.config.gateway3))
            sleep(0.5)
            try:
                ThingsBoard.execute_rpc_command(self.config.gateway4,
                                                [0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31, 0x31])
            except:
                print("Gateway {} not reached.".format(self.config.gateway4))
            sleep(1)