Skip to content

Commit

Permalink
Release 2.0.5 (#56)
Browse files Browse the repository at this point in the history
* Removed orderDict

* Added MySQL support and code cleanup

* Cleaned up --v1 support

* Release 2.0.5
  • Loading branch information
CharlesGodwin authored Nov 13, 2023
1 parent db27073 commit 7ab252c
Show file tree
Hide file tree
Showing 25 changed files with 672 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ pymagnum.code-workspace
*.bak
credentials.txt
source/_build
docs/_build
testdata/**
testing/**
.pymodhis
!testdata/allpackets.txt
!testdata/allpackets.json
!testdata/allpackets.sql
examples/mqttlogger_2.py
14 changes: 11 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
=======================
pyMagnum Release Notes
=======================
========================
Version 2.0.5 2023/11
------------------------
- Enhancement added ``allinone`` method to Magnum class. This creates a single record instead of one per device.
- ``magdump`` has been enhanced to support ``--allinone`` option
- A new example program ``magsql.py`` is available to log data to MariaDB/MySQL. Read the program comments for more information.
- A new tool ``mag2sql`` is available to convert JSON from ``magdump`` output to a MySQL schema definition.

Version 2.0.4 2023/11/05
------------------------
- Fixed bug in emitted JSON when using multiple devices
- Cleaned up code when using dummy data files instead of RS485 serial device
- Provided a complete dummy test file testdata/allpackets.txt
- Provided a JSON file testdata/allpackets.JSON
- Enhancement added --pretty option to magdump for formatted JSON output
- Fixed All revision values are defined as string. It used to be mixed
- Enhancement --pretty option to magdump for formatted JSON output


Version 2.0.3 2023/10/20
------------------------
- Fixed problem with installing tzlocal on some system
- Fixed problem with installing tzlocal on some systems
- Changed minimum Python version to 3.7
- Added warning about use of ``--break-system-packages`` with Python 3.11 and higher.
- Improved how to build information.
Expand Down
141 changes: 141 additions & 0 deletions allpackets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"datetime":"2023-11-04T09:51:53-04:00",
"device":"MAGNUM",
"comm_device":"!testdata/allpackets.txt",
"data":[
{
"device":"INVERTER",
"data":{
"revision":"6.1",
"mode":64,
"mode_text":"INVERT",
"fault":0,
"fault_text":"None",
"vdc":24.6,
"adc":22.0,
"VACout":119.0,
"VACin":0.0,
"invled":1,
"invled_text":"On",
"chgled":0,
"chgled_text":"Off",
"bat":17.0,
"tfmr":51.0,
"fet":36.0,
"model":107,
"model_text":"MS4024PAE",
"stackmode":1,
"stackmode_text":"Parallel stack - master",
"AACin":0.0,
"AACout":5.0,
"Hz":60.0
}
},
{
"device":"REMOTE",
"data":{
"revision":4.0,
"searchwatts":0,
"batterysize":400,
"battype":8,
"absorb":0,
"chargeramps":100,
"ainput":10,
"parallel":0,
"lbco":20.0,
"vaccutout":155.0,
"vsfloat":26.4,
"vEQ":1.2,
"absorbtime":2.0,
"runtime":3.6,
"starttemp":-17.8,
"startvdc":23.0,
"quiettime":0,
"begintime":2400,
"stoptime":0,
"vdcstop":28.8,
"voltstartdelay":120,
"voltstopdelay":120,
"maxrun":12.0,
"socstart":70,
"socstop":85,
"ampstart":0.0,
"ampsstartdelay":120,
"ampstop":20,
"ampsstopdelay":120,
"quietbegintime":2330,
"quietendtime":2345,
"exercisedays":0,
"exercisestart":0,
"exerciseruntime":0,
"topoff":2,
"warmup":30,
"cool":30,
"batteryefficiency":0
}
},
{
"device":"BMK",
"data":{
"revision":"1.0",
"soc":76,
"vdc":25.45,
"adc":11.6,
"vmin":20.16,
"vmax":30.8,
"amph":-104,
"amphtrip":2046.4,
"amphout":2000,
"Fault":1,
"Fault_Text":"Normal"
}
},
{
"device":"AGS",
"data":{
"revision":"5.2",
"status":2,
"status_text":"Ready",
"running":false,
"temp":14.4,
"runtime":0.0,
"gen_last_run":0,
"last_full_soc":0,
"gen_total_run":0,
"vdc":25.4
}
},
{
"device":"RTR",
"data":{
"revision":"3"
}
},
{
"device":"PT100",
"data":{
"revision":"1.x",
"address":0,
"mode":3,
"mode_text":"Absorb",
"mode_hex":"0X13",
"regulation":1,
"regulation_text":"Voltage",
"fault":0,
"fault_text":"No Fault",
"battery":58.9,
"battery_amps":13.3,
"pv_voltage":146.8,
"charge_time":1.7,
"target_battery_voltage":29.6,
"relay_state":0,
"alarm_state":0,
"fan_on":0,
"day":1,
"battery_temperature":27.0,
"inductor_temperature":49.0,
"fet_temperature":62.0
}
}
]
}
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# The full version, including alpha/beta/rc tags
release = '2.0'
version = '2.0.4'
version = '2.0.5'

# -- General configuration ---------------------------------------------------

Expand Down
5 changes: 1 addition & 4 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ Example programs are available in `this repository <https://github.com/CharlesGo

These programs are provided as examples only. Although we will try to help with bugs or other support, consider these programs unsupported.

..
Example programs are available in `this repository <https://github.com/CharlesGodwin/pymagnum/tree/Pre-release-2.0/examples>`_.
These programs support use of the `configuration file <tools.html#configuration-options-file>`_.

These programs support defining multiple RS485 devices.
These programs support defining multiple RS485 devices, except for `magsql.py`.
9 changes: 9 additions & 0 deletions docs/tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ You can define more than one device. Just provide multiple ``--device /dev/ttyUS
**NOTE:** If the device name is prefixed with a `!` the rest of the name is treated as a filename and is read for data. The format of the text
must be the same as the output generated by the ``magtest`` program. this is useful for debugging.

mag2sql
=======

This tool converts the JSON output from magdump into a draft MySQL definition. Users are urged to edit the output to match their needs.
the example prigram ``examples/magsql.py`` will load MySQL data once the database is defined.

``mag2sql --help``

``magdump | mag2sql > myschema.sql``

Configuration (options) File
============================
Expand Down
7 changes: 4 additions & 3 deletions examples/magsample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#
#!/usr/bin/env python3
#
# Copyright (c) 2018-2022 Charles Godwin <magnum@godwin.ca>
#
# SPDX-License-Identifier: BSD-3-Clause
Expand Down Expand Up @@ -47,7 +48,7 @@ def sigint_handler(signal, frame):
print(f"Magnum Sample Version:{magnum.__version__}")
print(f"Options:{str(args)[10:-1]}")

magnumReaders = dict()
magnumReaders = {}
for device in args.device:
try:
magnumReader = Magnum(device=device, packets=args.packets, trace=args.trace,
Expand All @@ -65,7 +66,7 @@ def sigint_handler(signal, frame):
try:
devices = magnumReader.getDevices()
if len(magnumReaders) > 1:
data = dict()
data = {}
data['comm_device'] = comm_device
data["data"] = devices
print(json.dumps(data, indent=2))
Expand Down
8 changes: 4 additions & 4 deletions examples/magserver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
#
# Copyright (c) 2018-2022 Charles Godwin <magnum@godwin.ca>
#
Expand All @@ -9,7 +10,6 @@
import signal
import sys

from collections import OrderedDict
from datetime import datetime, timezone
from http import HTTPStatus
from http.server import BaseHTTPRequestHandler, HTTPServer
Expand All @@ -27,7 +27,7 @@ def sigint_handler(signal, frame):

signal.signal(signal.SIGINT, sigint_handler)

magnumReaders = dict()
magnumReaders = {}


class magServer(BaseHTTPRequestHandler):
Expand Down Expand Up @@ -59,10 +59,10 @@ def do_GET(self):
devices = magnumReader.getDevices()
if len(devices) != 0:
self._set_headers(contenttype="application/json")
data = OrderedDict()
data = {}
data["datetime"] = timestamp
data["devices"] = devices
device = dict()
device = {}
device['comm_device'] = comm_device
device['data'] = data
response.append(device)
Expand Down
Loading

0 comments on commit 7ab252c

Please sign in to comment.