forked from jblance/mpp-solar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting the development docker commands to work in the make file. Add…
…ing USBPort so I can test with my hardware (jblance#334)
- Loading branch information
1 parent
28cada4
commit 812c647
Showing
10 changed files
with
202 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
services: | ||
mosquitto: | ||
image: eclipse-mosquitto | ||
network_mode: host | ||
volumes: | ||
- ./docker/mosquitto/config:/mosquitto/config | ||
- ./docker/mosquitto/data:/mosquitto/data | ||
- ./docker/mosquitto/log:/mosquitto/log | ||
|
||
mppsolar: | ||
network_mode: host | ||
devices: | ||
- /dev/hidraw0:/dev/hidraw0 | ||
volumes: | ||
#Bind over the configuration | ||
- type: bind | ||
source: ./docker/dev/config/ | ||
target: /config | ||
#Bind the code | ||
# - type: bind | ||
# source: ../.. | ||
# target: /mpp-solar | ||
build: | ||
context: ./ | ||
dockerfile: docker/dev/Dockerfile | ||
entrypoint: | ||
- powermon | ||
- -C | ||
- /config/powermon.yaml #Available due to volume binding above | ||
- --debug | ||
# - sleep | ||
# - infinity | ||
depends_on: | ||
- mosquitto | ||
|
||
# mppsolar-api: | ||
# network_mode: host | ||
# build: | ||
# context: api | ||
# dockerfile: Dockerfile.development | ||
# entrypoint: | ||
# - node | ||
# - index.js | ||
# depends_on: | ||
# - mppsolar | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0
docker/mpp-solar/mpp-solar.conf → docker/dev/config/mpp-solar.conf
100644 → 100755
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
device: | ||
name: Test_Inverter | ||
id: 123456789 | ||
model: 8048MAX | ||
manufacturer: MPP-Solar | ||
port: | ||
baud: 2400 | ||
path: /dev/hidraw0 | ||
type: USB | ||
protocol: PI30 | ||
commands: | ||
- command: QPGS0 | ||
outputs: | ||
- name: screen | ||
format: hass | ||
entity_id_prefix: inverter42 | ||
discovery_prefix: homeassistant | ||
filter: ^serial|^work|^charger|^fault | ||
loop: 60 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# yaml config for powermon | ||
device: | ||
name: Test_Inverter | ||
id: 123456789 | ||
model: 1012LV-MK | ||
manufacturer: MPP-Solar | ||
port: | ||
baud: 2400 | ||
path: /dev/hidraw0 | ||
type: USB | ||
protocol: PI30 | ||
|
||
#Separate the schedule from the device definition | ||
scheduling: | ||
loop: 10 | ||
adhoc_command_topic: mpp-solar/api-client | ||
schedules: | ||
- name: QPIGS_5_minutes | ||
type: loop | ||
loopCount: 6 #will run every 1 minute | ||
commands: | ||
- command: QPIGS | ||
type: basic #default command type is basic | ||
outputs: | ||
- type: mqtt | ||
topic: Test_Inverter | ||
tag: QPIGS | ||
mqttbroker: | ||
name: localhost | ||
port: 1883 | ||
user: null | ||
pass: null | ||
|
||
daemon: | ||
type: systemd | ||
keepalive: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import configparser | ||
#import configparser | ||
|
||
version = configparser.ConfigParser() | ||
version.read("pyproject.toml") | ||
__version__ = version["tool.poetry"]["version"].replace('"', "") | ||
#version = configparser.ConfigParser() | ||
#version.read("pyproject.toml") | ||
#__version__ = version["tool.poetry"]["version"].replace('"', "") | ||
|
||
__version__ = "0.15.30" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import logging | ||
import os | ||
import time | ||
|
||
from mppsolar.helpers import get_kwargs | ||
|
||
from .port import Port | ||
|
||
log = logging.getLogger("USBPort") | ||
|
||
|
||
class usbport(Port): | ||
def __init__(self, *args, **kwargs) -> None: | ||
config = get_kwargs(kwargs, "config") | ||
self.path = config["path"] | ||
self.protocol = config["protocol"] | ||
log.debug(f"Initializing usb port. path:{self.path}, protocol: {self.protocol}") | ||
|
||
def protocol(self): | ||
return self.protocol | ||
|
||
def connect(self) -> None: | ||
log.debug(f"USBPort connecting. path:{self.path}, protocol: {self.protocol}") | ||
try: | ||
self.port = os.open(self.path, os.O_RDWR | os.O_NONBLOCK) | ||
log.debug(f"USBPort port number ${self.port}") | ||
except Exception as e: | ||
log.warning(f"Error openning usb port: {e}") | ||
self.error = e | ||
return | ||
|
||
def disconnect(self) -> None: | ||
log.debug(f"USBPort disconnecting {self.port}") | ||
|
||
def send_and_receive(self, *args, **kwargs) -> dict: | ||
full_command = get_kwargs(kwargs, "full_command") | ||
response_line = bytes() | ||
self.connect() | ||
|
||
# Send the command to the open usb connection | ||
to_send = full_command | ||
try: | ||
log.debug(f"length of to_send: {len(to_send)}") | ||
except: # noqa: E722 | ||
import pdb | ||
|
||
pdb.set_trace() | ||
if len(to_send) <= 8: | ||
# Send all at once | ||
log.debug("1 chunk send") | ||
time.sleep(0.35) | ||
try: | ||
os.write(self.port, to_send) | ||
except Exception as e: | ||
log.debug("USB read error: {}".format(e)) | ||
|
||
elif len(to_send) > 8 and len(to_send) < 11: | ||
log.debug("2 chunk send") | ||
time.sleep(0.35) | ||
os.write(self.port, to_send[:5]) | ||
time.sleep(0.35) | ||
os.write(self.port, to_send[5:]) | ||
else: | ||
while len(to_send) > 0: | ||
log.debug("multiple chunk send") | ||
# Split the byte command into smaller chucks | ||
send, to_send = to_send[:8], to_send[8:] | ||
log.debug("send: {}, to_send: {}".format(send, to_send)) | ||
time.sleep(0.35) | ||
os.write(self.port, send) | ||
time.sleep(0.25) | ||
# Read from the usb connection | ||
# try to a max of 100 times | ||
for x in range(100): | ||
# attempt to deal with resource busy and other failures to read | ||
try: | ||
time.sleep(0.15) | ||
r = os.read(self.port, 256) | ||
response_line += r | ||
except Exception as e: | ||
log.debug("USB read error: {}".format(e)) | ||
# Finished is \r is in byte_response | ||
if bytes([13]) in response_line: | ||
# remove anything after the \r | ||
response_line = response_line[: response_line.find(bytes([13])) + 1] | ||
break | ||
log.debug("usb response was: %s", response_line) | ||
os.close(self.port) | ||
return response_line |