mirror of
https://github.com/thingsboard/thingsboard-gateway
synced 2025-10-26 22:31:42 +08:00
Init OCPP Connector
This commit is contained in:
4
setup.py
4
setup.py
@@ -40,13 +40,13 @@ setup(
|
||||
'thingsboard_gateway.storage.file', 'thingsboard_gateway.storage.sqlite', 'thingsboard_gateway.tb_client',
|
||||
'thingsboard_gateway.connectors', 'thingsboard_gateway.connectors.ble', 'thingsboard_gateway.connectors.socket',
|
||||
'thingsboard_gateway.connectors.mqtt', 'thingsboard_gateway.connectors.opcua_asyncio', 'thingsboard_gateway.connectors.xmpp',
|
||||
'thingsboard_gateway.connectors.opcua', 'thingsboard_gateway.connectors.request',
|
||||
'thingsboard_gateway.connectors.opcua', 'thingsboard_gateway.connectors.request', 'thingsboard_gateway.connectors.ocpp',
|
||||
'thingsboard_gateway.connectors.modbus', 'thingsboard_gateway.connectors.can', 'thingsboard_gateway.connectors.bacnet',
|
||||
'thingsboard_gateway.connectors.bacnet.bacnet_utilities', 'thingsboard_gateway.connectors.odbc',
|
||||
'thingsboard_gateway.connectors.rest', 'thingsboard_gateway.connectors.snmp', 'thingsboard_gateway.connectors.ftp',
|
||||
'thingsboard_gateway.tb_utility', 'thingsboard_gateway.extensions',
|
||||
'thingsboard_gateway.extensions.mqtt', 'thingsboard_gateway.extensions.modbus', 'thingsboard_gateway.extensions.opcua',
|
||||
'thingsboard_gateway.extensions.opcua_asyncio',
|
||||
'thingsboard_gateway.extensions.opcua_asyncio', 'thingsboard_gateway.extensions.ocpp',
|
||||
'thingsboard_gateway.extensions.ble', 'thingsboard_gateway.extensions.serial', 'thingsboard_gateway.extensions.request',
|
||||
'thingsboard_gateway.extensions.can', 'thingsboard_gateway.extensions.bacnet', 'thingsboard_gateway.extensions.odbc',
|
||||
'thingsboard_gateway.extensions.rest', 'thingsboard_gateway.extensions.snmp', 'thingsboard_gateway.extensions.ftp',
|
||||
|
||||
3
thingsboard_gateway/config/ocpp.json
Normal file
3
thingsboard_gateway/config/ocpp.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
@@ -115,6 +115,11 @@ connectors:
|
||||
# type: xmpp
|
||||
# configuration: xmpp.json
|
||||
#
|
||||
# -
|
||||
# name: OCPP Connector
|
||||
# type: ocpp
|
||||
# configuration: ocpp.json
|
||||
#
|
||||
# ========= Customization ==========
|
||||
#
|
||||
#
|
||||
|
||||
13
thingsboard_gateway/connectors/ocpp/__init__.py
Normal file
13
thingsboard_gateway/connectors/ocpp/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2022. 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.
|
||||
61
thingsboard_gateway/connectors/ocpp/ocpp_connector.py
Normal file
61
thingsboard_gateway/connectors/ocpp/ocpp_connector.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# Copyright 2022. 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.
|
||||
|
||||
from threading import Thread
|
||||
from random import choice
|
||||
from string import ascii_lowercase
|
||||
|
||||
from thingsboard_gateway.connectors.connector import Connector, log
|
||||
from thingsboard_gateway.tb_utility.tb_utility import TBUtility
|
||||
|
||||
|
||||
try:
|
||||
import ocpp
|
||||
except ImportError:
|
||||
print('OCPP library not found - installing...')
|
||||
TBUtility.install_package("ocpp")
|
||||
import ocpp
|
||||
|
||||
|
||||
class OcppConnector(Connector, Thread):
|
||||
def __init__(self, gateway, config, connector_type):
|
||||
super().__init__()
|
||||
self._log = log
|
||||
self._config = config
|
||||
self._connector_type = connector_type
|
||||
self.statistics = {'MessagesReceived': 0,
|
||||
'MessagesSent': 0}
|
||||
self._gateway = gateway
|
||||
self.setName(config.get("name", 'OCPP Connector ' + ''.join(choice(ascii_lowercase) for _ in range(5))))
|
||||
self._connected = False
|
||||
self.__stopped = False
|
||||
self.daemon = True
|
||||
|
||||
def open(self):
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
def is_connected(self):
|
||||
pass
|
||||
|
||||
def on_attributes_update(self, content):
|
||||
pass
|
||||
|
||||
def server_side_rpc_handler(self, content):
|
||||
pass
|
||||
21
thingsboard_gateway/connectors/ocpp/ocpp_converter.py
Normal file
21
thingsboard_gateway/connectors/ocpp/ocpp_converter.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Copyright 2022. 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.
|
||||
|
||||
from thingsboard_gateway.connectors.converter import Converter, abstractmethod, log
|
||||
|
||||
|
||||
class OcppConverter(Converter):
|
||||
@abstractmethod
|
||||
def convert(self, config, val, data=None):
|
||||
pass
|
||||
13
thingsboard_gateway/extensions/ocpp/__init__.py
Normal file
13
thingsboard_gateway/extensions/ocpp/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright 2022. 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.
|
||||
@@ -72,6 +72,7 @@ DEFAULT_CONNECTORS = {
|
||||
"ftp": "FTPConnector",
|
||||
"socket": "SocketConnector",
|
||||
"xmpp": "XMPPConnector",
|
||||
"ocpp": "OcppConnector",
|
||||
}
|
||||
|
||||
DEFAULT_STATISTIC = {
|
||||
|
||||
Reference in New Issue
Block a user