jblance / mpp-solar

Python package to communicate to MPP Solar PIP-4048MS inverters (and similar)
MIT License
364 stars 151 forks source link

getting a json.decoder.JSONDecodeError #178

Closed shanrahul closed 2 years ago

shanrahul commented 3 years ago

I'm preparing a python script using the mpp-solar to catch several data from the inverter and write them down to influxdb. So here is my code. When i run the code for a day, sometimes i receive an error like this,

Traceback (most recent call last): File "/home/pi/getdata.py", line 145, in <module> write_influx() File "/home/pi/getdata.py", line 31, in write_influx data_dict_energy_generated = json.loads(payload_energy_generated) File "/usr/lib/python3.7/json/__init__.py", line 348, in loads return _default_decoder.decode(s) File "/usr/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

How can i overcome this issue?

jblance commented 3 years ago

no idea. i dont know what your script is doing or what data you are processing suggest you add exception handling to your script and dump the json when a JSONDecodeError is caught

VictorBucha commented 2 years ago

starting from version 0.7.82 (or maybe earlier) a totally unnecessary line appeared in JSON output root@raspberrypi:/opt/Temp/inverter# mpp-solar -p /dev/hidraw0 -P PI30MAX -c QPGS0 -o json MqttBroker(name='localhost', port=1883, username=None, password=None, results_topic='mpp-solar') {"_command": "QPGS0", "_command_description": "Parallel Information inquiry", "parallel_instance_number": "Not valid", "serial_number": "92932012101959", "work_mode": "Line Mode", "fault_code": "No fault", "grid_voltage": 228.6, "grid_frequency": 49.92, "ac_output_voltage": 228.6, "ac_output_frequency": 49.92, "ac_output_apparent_power": 525, "ac_output_active_power": 439, "load_percentage": 6, "battery_voltage": 56.7, "battery_charging_current": 0, "battery_capacity": 100, "pv1_input_voltage": 0.0, "total_charging_current": 0, "total_ac_output_apparent_power": 525, "total_output_active_power": 439, "total_ac_output_percentage": 5, "is_scc_ok": 1, "is_ac_charging": 1, "is_scc_charging": 1, "is_battery_over_voltage": 0, "is_battery_under_voltage": 0, "is_line_lost": 0, "is_load_on": 1, "is_configuration_changed": 0, "output_mode": "single machine", "charger_source_priority": "Solar first", "max_charger_current": 90, "max_charger_range": 120, "max_ac_charger_current": 60, "pv1_input_current": 0, "battery_discharge_current": 0, "pv2_input_voltage": 290.9, "pv2_input_current": 1}

Especially when I was parsing it and sending directly to Influx, not with instruments of mpp-solar package. I am not using mqtt at all. how can I get rid of this first line in -json responce?

jblance commented 2 years ago

That was a bug, is it still there in the latest version?

On Wed, 10 Nov 2021, 9:28 pm Viktor, @.***> wrote:

starting from version 0.7.82 (or maybe earlier) a totally unnecessary line appeared in JSON output @.***:/opt/Temp/inverter# mpp-solar -p /dev/hidraw0 -P PI30MAX -c QPGS0 -o json MqttBroker(name='localhost', port=1883, username=None, password=None, results_topic='mpp-solar') {"_command": "QPGS0", "_command_description": "Parallel Information inquiry", "parallel_instance_number": "Not valid", "serial_number": "92932012101959", "work_mode": "Line Mode", "fault_code": "No fault", "grid_voltage": 228.6, "grid_frequency": 49.92, "ac_output_voltage": 228.6, "ac_output_frequency": 49.92, "ac_output_apparent_power": 525, "ac_output_active_power": 439, "load_percentage": 6, "battery_voltage": 56.7, "battery_charging_current": 0, "battery_capacity": 100, "pv1_input_voltage": 0.0, "total_charging_current": 0, "total_ac_output_apparent_power": 525, "total_output_active_power": 439, "total_ac_output_percentage": 5, "is_scc_ok": 1, "is_ac_charging": 1, "is_scc_charging": 1, "is_battery_over_voltage": 0, "is_battery_under_voltage": 0, "is_line_lost": 0, "is_load_on": 1, "is_configuration_changed": 0, "output_mode": "single machine", "charger_source_priority": "Solar first", "max_charger_current": 90, "max_charger_range": 120, "max_ac_charger_current": 60, "pv1_input_current": 0, "battery_discharge_current": 0, "pv2_input_voltage": 290.9, "pv2_input_current": 1}

Especially when I was parsing it and sending directly to Influx, not with instruments of mpp-solar package. I am not using mqtt at all. how can I get rid of this first line in -json responce?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jblance/mpp-solar/issues/178#issuecomment-964890945, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJVKNXQ7NDVVEY3TAFBTZLULIUKLANCNFSM5HFHUFMQ .

VictorBucha commented 2 years ago

had my MAX2 inverter offline - revealed only yesterday. will upgrade and revert

jblance commented 2 years ago

Cool.

I have been refactoring (while my own system has been in the midst of change) to allow the fixing of some issues that are design related, so it is possible (or likely) that bugs have been introduced

Good luck 🙃

On Wed, 10 Nov 2021, 9:31 pm Viktor, @.***> wrote:

had my MAX2 inverter offline - revealed only yesterday. will upgrade and revert

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jblance/mpp-solar/issues/178#issuecomment-964895012, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJVKNXE2ZFQZ2S2RXLIT53ULIUWJANCNFSM5HFHUFMQ .

VictorBucha commented 2 years ago

If newest release fail, can I have the latest pre refactoring version?

jblance commented 2 years ago

The fix was in the middle of refactoring. Try first and see if it works

On Wed, 10 Nov 2021, 9:45 pm Viktor, @.***> wrote:

If newest release fail, can I have the latest pre refactoring version?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jblance/mpp-solar/issues/178#issuecomment-964904316, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJVKNWWH54GL7YYR6SZHQDULIWJHANCNFSM5HFHUFMQ .

VictorBucha commented 2 years ago

0.7.91 - has no first line

VictorBucha commented 2 years ago

And it works like a charm