1
0
mirror of https://github.com/thingsboard/thingsboard-gateway synced 2025-10-26 22:31:42 +08:00

Added license and some improvements

This commit is contained in:
zenx
2019-10-23 16:47:19 +03:00
parent ef19fe1655
commit 549dfc722c
63 changed files with 795 additions and 29 deletions

View File

@@ -0,0 +1,14 @@
# Copyright 2019. ThingsBoard
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

View File

@@ -1,3 +1,17 @@
# Copyright 2019. ThingsBoard
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import time
from thingsboard_gateway.tb_client.tb_gateway_mqtt import TBGatewayMqttClient
@@ -43,16 +57,17 @@ class TBClient:
def connect(self, min_reconnect_delay=10):
keep_alive = self.__config.get("keep_alive", 60)
while not self.client.is_connected():
try:
try:
while not self.client.is_connected():
log.debug("connecting to ThingsBoard")
self.client.connect(tls=self.__tls,
ca_certs=self.__ca_cert,
cert_file=self.__cert,
key_file=self.__private_key,
keepalive=keep_alive,
min_reconnect_delay=min_reconnect_delay)
except Exception as e:
log.error(e)
log.debug("connecting to ThingsBoard")
time.sleep(1)
time.sleep(1)
except Exception as e:
log.exception(e)
time.sleep(10)

View File

@@ -1,3 +1,17 @@
# Copyright 2019. ThingsBoard
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging.config
import logging.handlers
import time
@@ -18,7 +32,9 @@ log = logging.getLogger(__name__)
class TBGatewayService:
def __init__(self, config_file):
def __init__(self, config_file=None):
if config_file is None:
config_file = path.dirname(path.dirname(path.abspath(__file__))) + '/config/tb_gateway.yaml'
with open(config_file) as config:
config = yaml.safe_load(config)
self.__config_dir = path.dirname(path.abspath(config_file))+'/'
@@ -255,5 +271,4 @@ class TBGatewayService:
if __name__ == '__main__':
print(path.join(path.abspath(__file__), '..', '..'))
TBGatewayService(path.dirname(path.dirname(path.abspath(__file__))) + '/config/tb_gateway.yaml')