Compare commits
No commits in common. "140acba1f5fc4c9fd759a1ddc5bac674fae8cc6a" and "82ee08a1d7d73adc2079e6295e2f9509e0335141" have entirely different histories.
140acba1f5
...
82ee08a1d7
11 changed files with 13 additions and 125 deletions
|
@ -2,7 +2,7 @@
|
|||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
rev: v4.0.1
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
|
@ -23,7 +23,7 @@ repos:
|
|||
- id: detect-private-key
|
||||
|
||||
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
|
||||
rev: 2.7.1
|
||||
rev: 2.3.54
|
||||
hooks:
|
||||
- id: editorconfig-checker
|
||||
args:
|
||||
|
@ -35,19 +35,16 @@ repos:
|
|||
- id: flake8
|
||||
|
||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: v1.2.0
|
||||
rev: v0.910-1
|
||||
hooks:
|
||||
- id: mypy
|
||||
args:
|
||||
- "--install-types"
|
||||
- "--non-interactive"
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.3.0
|
||||
rev: 21.10b0
|
||||
hooks:
|
||||
- id: black
|
||||
|
||||
- repo: https://github.com/PyCQA/isort
|
||||
rev: 5.12.0
|
||||
rev: 5.9.3
|
||||
hooks:
|
||||
- id: isort
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
# Connector
|
||||
|
||||
The connector is a RJ12 (6P6C, phone connector with all 6 positions populated).
|
||||
The interface uses RS-232 levels (±5V), make sure your adaptor can handle this! (Some adaptors require higher voltages).
|
||||
TODO: Triple check RS-232 voltages.
|
||||
The connector is a RJ12 (6P6C, phone connector with all 6 positions populated)
|
||||
The interface uses RS-232 levels (±15V)
|
||||
|
||||
## Pinout
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
consumers:
|
||||
stdio.StdoutConsumer: {}
|
||||
interface:
|
||||
name: serial.SerialInterface
|
||||
params:
|
||||
port: /dev/ttyUSB0
|
||||
baudrate: 9600
|
||||
timeout: 2
|
||||
# name: feasycom.FeasycomInterface
|
||||
# params:
|
||||
# mac: DC:0D:30:9C:61:BA
|
||||
# timeout: 5
|
|
@ -1,29 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
from serial import Serial
|
||||
|
||||
print(sys.path)
|
||||
sys.path.insert(1, os.path.dirname(os.path.dirname(sys.argv[0])))
|
||||
# from srnemqtt.constants import MAC
|
||||
# from srnemqtt.lib.feasycom_ble import BTLEUart
|
||||
from srnemqtt.protocol import construct_request, write # noqa: E402
|
||||
|
||||
for rate in [1200, 2400, 4800, 9600, 115200]:
|
||||
print(rate)
|
||||
with Serial("/dev/ttyUSB0", baudrate=rate, timeout=2) as x:
|
||||
sleep(2)
|
||||
|
||||
print(x)
|
||||
|
||||
write(x, construct_request(0x0E, words=3))
|
||||
print(x.read(3))
|
||||
print(x.read(6))
|
||||
print(x.read(2))
|
||||
|
||||
# x.timeout = 2
|
||||
|
||||
# print(x.read())
|
||||
# print(x.read(1))
|
|
@ -1,7 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from serial import Serial
|
||||
|
||||
with Serial("/dev/ttyUSB0", baudrate=9600, timeout=2) as x:
|
||||
x.write(b"Hello, World!")
|
||||
print(x.read(13))
|
||||
print(x.read(13))
|
|
@ -3,6 +3,3 @@ rrdtool
|
|||
bluepy
|
||||
libscrc
|
||||
paho-mqtt
|
||||
pyserial
|
||||
|
||||
types-PyYAML
|
||||
|
|
|
@ -5,34 +5,28 @@ import time
|
|||
from decimal import Decimal
|
||||
from typing import cast
|
||||
|
||||
from bluepy.btle import BTLEDisconnectError
|
||||
from serial import SerialException
|
||||
from bluepy import btle
|
||||
|
||||
from .config import get_config, get_consumers, get_interface
|
||||
from .config import get_config, get_consumers
|
||||
from .constants import MAC
|
||||
from .lib.feasycom_ble import BTLEUart
|
||||
from .protocol import parse_battery_state, parse_historical_entry, try_read_parse
|
||||
from .solar_types import DataName
|
||||
from .util import Periodical, log
|
||||
|
||||
|
||||
class CommunicationError(BTLEDisconnectError, SerialException, IOError):
|
||||
pass
|
||||
|
||||
|
||||
def main():
|
||||
conf = get_config()
|
||||
consumers = get_consumers(conf)
|
||||
|
||||
per_voltages = Periodical(interval=15)
|
||||
per_current_hist = Periodical(interval=60)
|
||||
# import serial
|
||||
|
||||
# ser = serial.Serial()
|
||||
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
log("Connecting...")
|
||||
with get_interface() as dev:
|
||||
with BTLEUart(MAC, timeout=5) as dev:
|
||||
log("Connected.")
|
||||
|
||||
# write(dev, construct_request(0, 32))
|
||||
|
@ -102,7 +96,7 @@ def main():
|
|||
# else:
|
||||
# write(wd, CMD_ENABLE_LOAD)
|
||||
|
||||
except CommunicationError:
|
||||
except btle.BTLEDisconnectError:
|
||||
log("ERROR: Disconnected")
|
||||
time.sleep(1)
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@ from typing import Any, Dict, List, Optional, Type
|
|||
|
||||
import yaml
|
||||
|
||||
from srnemqtt.interfaces import BaseInterface
|
||||
|
||||
from .consumers import BaseConsumer
|
||||
|
||||
|
||||
|
@ -54,30 +52,6 @@ def get_consumers(conf: Optional[Dict[str, Any]] = None) -> List[BaseConsumer]:
|
|||
return consumers
|
||||
|
||||
|
||||
def _get_interface(name: str) -> Type[BaseInterface]:
|
||||
mod_name, cls_name = name.rsplit(".", 1)
|
||||
|
||||
mod = importlib.import_module(f".interfaces.{mod_name}", package=__package__)
|
||||
|
||||
res = getattr(mod, cls_name)
|
||||
assert issubclass(res, BaseInterface)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def get_interface(conf: Optional[Dict[str, Any]] = None) -> BaseInterface:
|
||||
if conf is None:
|
||||
conf = get_config()
|
||||
|
||||
name = conf["interface"]["name"]
|
||||
params = conf["interface"].get("params", {})
|
||||
|
||||
mod = _get_interface(name)
|
||||
assert mod
|
||||
|
||||
return mod(**params)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
conf = get_config()
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from abc import ABCMeta
|
||||
from io import RawIOBase
|
||||
|
||||
|
||||
class BaseInterface(RawIOBase, metaclass=ABCMeta):
|
||||
pass
|
|
@ -1,10 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from ..lib.feasycom_ble import BTLEUart
|
||||
from . import BaseInterface
|
||||
|
||||
|
||||
class FeasycomInterface(BTLEUart, BaseInterface):
|
||||
pass
|
||||
|
||||
|
||||
# BTLEUart(mac=MAC, timeout=5)
|
|
@ -1,8 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import serial
|
||||
|
||||
from . import BaseInterface
|
||||
|
||||
|
||||
class SerialInterface(serial.Serial, BaseInterface):
|
||||
pass
|
Loading…
Reference in a new issue