一、构造函数的入参:
- config
tb_gateway.yaml关于thingsboard配置:
thingsboard:host: 127.0.0.1port: 1883remoteShell: trueremoteConfiguration: falsestatsSendPeriodInSeconds: 3600minPackSendDelayMS: 0checkConnectorsConfigurationInSeconds: 60handleDeviceRenaming: truecheckingDeviceActivity:checkDeviceInactivity: falseinactivityTimeoutSeconds: 120inactivityCheckPeriodSeconds: 10security:accessToken: o55jUl0quC1QX2XRPhl5qos: 1
- config_folder_path
配置文件目录:
D:\xx\code\python\thingsboard-gateway\thingsboard_gateway\config\
二、构造函数主要工作
从构造函数传递过来的配置初始化成员变量,核心成员变量是:
self.client = TBGatewayMqttClient(self.__host, self.__port, self.__token, self, quality_of_service=self.__default_quality_of_service)
启动线程
self.start()
线程run函数:
def run(self):keep_alive = self.__config.get("keep_alive", 120)try:while not self.client.is_connected() and not self.__stopped:if not self.__paused:if self.__stopped:breaklog.info("connecting to ThingsBoard")try:self.client.connect(keepalive=keep_alive,min_reconnect_delay=self.__min_reconnect_delay)except ConnectionRefusedError:passexcept Exception as e:log.exception(e)sleep(1)except Exception as e:log.exception(e)sleep(10)while not self.__stopped:try:if not self.__stopped:sleep(.2)else:breakexcept KeyboardInterrupt:log.info('KeyboardInterrupt')self.__stopped = Trueexcept Exception as e:log.exception(e)
tip:
只是启动线程,还没有去连接thingsborad,只有gatewayservice调用connect函数才去连接thingsboard
