Hi Jblance,
I did the work to expand and test the PI18 Protocol
All queries and set functions work so far except for the Yearly/Montly/Daly PV Generated Energy Inquiry. It means that the commands don't exceed even though they are there.
With the SETTER_COMMANDS you expected a ACK or NACK. Although this is chicked up as b"^0" or b"^1", this is not processed. So I adjusted the commands/results so that the program does not break off.
Then I had to make an adjustment at the CRC Check in PI18. Since there is no "^D" back in the SETTER Commands.
But only b "^0" or b "^1"
Here are the results of the QUERY_COMMANDS
--------------------------------------------------------------------
Command: PIRI - Current Settings inquiry
--------------------------------------------------------------------
Parameter Value Unit
ac_input_voltage 230.0 V
ac_input_current 21.7 A
ac_output_voltage 230.0 V
ac_output_frequency 50.0 Hz
ac_output_current 21.7 A
ac_output_apparent_power 5000 VA
ac_output_active_power 5000 W
battery_voltage 48.0 V
battery_re-charge_voltage 51.0 V
battery_re-discharge_voltage 53.0 V
battery_under_voltage 44.0 V
battery_bulk_charge_voltage 56.0 V
battery_float_charge_voltage 56.0 V
battery_type User
max_ac_charging_current 2 A
max_charging_current 80 A
input_voltage_range UPS
output_source_priority Solar - Battery - Utility
charger_source_priority Solar + Utility
max_parallel_units 9
machine_type Off Grid
topology transformerless
output_mode single machine output
solar_power_priority Battery-Load-Utiliy + AC Charger
mppt_strings 1
unknown_flags? 00
----------------------------------
Command: PI - Protocol ID inquiry
----------------------------------
Parameter Value Unit
protocol_id 18
------------------------------------------------
Command: ET - Total PV Generated Energy Inquiry
------------------------------------------------
Parameter Value Unit
total_pv_generated_energy 21578131 Wh
--------------------------------------------------------
Command: GS - General Status Parameters inquiry
--------------------------------------------------------
Parameter Value Unit
ac_input_voltage 208.8 V
ac_input_frequency 50.0 Hz
ac_output_voltage 229.9 V
ac_output_frequency 50.0 Hz
ac_output_apparent_power 1609 VA
ac_output_active_power 1523 W
ac_output_load 32 %
battery_voltage 53.2 V
battery_voltage_from_scc 0.0 V
battery_voltage_from_scc2 0.0 V
battery_discharge_current 10 A
battery_charging_current 0 A
battery_capacity 90 %
inverter_heat_sink_temperature 60 °C
mppt1_charger_temperature 0 °C
mppt2_charger_temperature 0 °C
mppt1_input_power 1089 W
mppt2_input_power 0 W
mppt1_input_voltage 348.4 V
mppt2_input_voltage 0.0 V
setting_value_configuration_state Nothing changed
mppt1_charger_status charging
mppt2_charger_status abnormal
load_connection connect
battery_power_direction discharge
dc/ac_power_direction DC-AC
line_power_direction donothing
parallel_instance_number Not valid
----------------------------
Command: MOD - Mode inquiry
----------------------------
Parameter Value Unit
device_mode Battery
-------------------------------------------------------------------
Command: MCHGCR - Max Charging Current Options inquiry
-------------------------------------------------------------------
Parameter Value Unit
max_charging_current_options 010,020,030,040,050,060,070,080 A
-----------------------------------------------------------------------
Command: MUCHGCR - Max Utility Charging Current Options inquiry
-----------------------------------------------------------------------
Parameter Value Unit
max_utility_charging_current 002,010,020,030,040,050,060,070,080 A
And here is the debug result of a SETTER_COMMAND
set Battery Max Charging Current Solar + AC
MCHGC0,080
The "Error no Readings in Result" comes from my adaptation so that it works
2024-05-10 06:40:09,925:DEBUG:apicoordinator:announce@134: Not announcing obj: Device: Inverter1, self.device_info.device_id='a123456789', self.device_info.model='HybridV25048', self.device_info.manufacturer='MPP-Solar', port: <powermon.ports.usbport.USBPort object at 0x7ccde3e504a0>, mqtt_broker: MqttBroker DISABLED, commands:[<powermon.commands.command.Command object at 0x7ccde38d32f0>] as api DISABLED
2024-05-10 06:40:09,926:DEBUG:selector_events:__init__@64: Using selector: EpollSelector
2024-05-10 06:40:09,926:INFO:device:run@192: Running command: Command: self.code='MCHGC0,080' self.full_command=None, self.command_type='basic', [_outs='outputs.Screen: outputs the results to the screen as per the formatter supplied'], last_run='Not yet run', next_run='10 May 2024 06:40:09', trigger: every 60 loops togo: 0, CommandDefinition: self.code='MCHGC', self.description='Set Battery Max Charging Current Solar + AC', self.result_type=<ResultType.ACK: 2>, reading_definition count: 1, self.command_code=None, self.command_type=<CommandType.PI18_SETTER: 'pi18_setter'> self.override=None self.template=None
2024-05-10 06:40:09,927:DEBUG:abstractport:run_command@75: Command Command: self.code='MCHGC0,080' self.full_command=None, self.command_type='basic', [_outs='outputs.Screen: outputs the results to the screen as per the formatter supplied'], last_run='Not yet run', next_run='10 May 2024 06:40:09', trigger: every 60 loops togo: 0, CommandDefinition: self.code='MCHGC', self.description='Set Battery Max Charging Current Solar + AC', self.result_type=<ResultType.ACK: 2>, reading_definition count: 1, self.command_code=None, self.command_type=<CommandType.PI18_SETTER: 'pi18_setter'> self.override=None self.template=None
2024-05-10 06:40:09,927:DEBUG:usbport:connect@83: USBPort connecting. path:/dev/hidraw0, protocol:PI18 protocol handler
2024-05-10 06:40:09,986:DEBUG:usbport:connect@86: USBPort port number $6
2024-05-10 06:40:09,987:INFO:pi18:get_full_command@773: Using protocol: b'PI18' with 21 commands
2024-05-10 06:40:09,987:DEBUG:abstractprotocol:get_command_definition@108: Matched: MCHGC0,080 to: MCHGC value: 0,080
2024-05-10 06:40:09,988:DEBUG:helpers:crc_pi30@25: Calculating CRC for b'^S013MCHGC0,080'
2024-05-10 06:40:09,989:DEBUG:helpers:crc_pi30@75: Generated CRC 0x18 0x14 0x1814
2024-05-10 06:40:09,990:DEBUG:pi18:get_full_command@798: full command: b'^S013MCHGC0,080\x18\x14\r'
2024-05-10 06:40:09,990:DEBUG:usbport:send_and_receive@108: length of to_send: 18
2024-05-10 06:40:09,991:DEBUG:usbport:send_and_receive@118: multiple chunk send
2024-05-10 06:40:09,992:DEBUG:usbport:send_and_receive@125: sending chunk: b'^S013MCH'
2024-05-10 06:40:10,045:DEBUG:usbport:send_and_receive@125: sending chunk: b'GC0,080\x18'
2024-05-10 06:40:10,097:DEBUG:usbport:send_and_receive@125: sending chunk: b'\x14\r\x00\x00\x00\x00\x00\x00'
2024-05-10 06:40:10,550:DEBUG:usbport:send_and_receive@143: usb response was: b'^1\x0b\xc2\r'
2024-05-10 06:40:10,551:DEBUG:command:build_result@153: build_result: for command with 'code: MCHGC0,080, command_definition: CommandDefinition: self.code='MCHGC', self.description='Set Battery Max Charging Current Solar + AC', self.result_type=<ResultType.ACK: 2>, reading_definition count: 1, self.command_code=None, self.command_type=<CommandType.PI18_SETTER: 'pi18_setter'>'
2024-05-10 06:40:10,552:DEBUG:abstractprotocol:check_valid@155: check valid for b'^1\x0b\xc2\r', definition: CommandDefinition: self.code='MCHGC', self.description='Set Battery Max Charging Current Solar + AC', self.result_type=<ResultType.ACK: 2>, reading_definition count: 1, self.command_code=None, self.command_type=<CommandType.PI18_SETTER: 'pi18_setter'>
2024-05-10 06:40:10,552:DEBUG:pi18:check_crc@735: check crc for b'^1\x0b\xc2\r' in pi18
2024-05-10 06:40:10,553:INFO:pi18:check_crc@748: PI18 response doesnt start with ^D - but ACK or NACK
2024-05-10 06:40:10,553:DEBUG:pi18:trim_response@759: trim b'^1\x0b\xc2\r', definition: CommandDefinition: self.code='MCHGC', self.description='Set Battery Max Charging Current Solar + AC', self.result_type=<ResultType.ACK: 2>, reading_definition count: 1, self.command_code=None, self.command_type=<CommandType.PI18_SETTER: 'pi18_setter'>
2024-05-10 06:40:10,554:DEBUG:abstractprotocol:split_response@175: splitting b'^1', result_type ResultType.ACK
2024-05-10 06:40:10,554:DEBUG:abstractprotocol:split_response@230: responses: 'b'^1''
2024-05-10 06:40:10,555:INFO:result:decode_responses@104: result.response passed to decode: b'^1', result_type ResultType.ACK
2024-05-10 06:40:10,555:DEBUG:command_definition:get_reading_definition@116: looking for reading definition with: None, result_type is: ResultType.ACK
2024-05-10 06:40:10,556:DEBUG:command_definition:get_reading_definition@134: found reading definition: self.index=0, self.description='Set Battery Max Charging Current Solar + AC', self.response_type=<ResponseType.ACK: 'ack'>, self.unit='', instance=<class 'powermon.commands.reading_definition.ReadingDefinitionACK'>
2024-05-10 06:40:10,556:DEBUG:result:decode_responses@161: got readings:
2024-05-10 06:40:10,557:DEBUG:result:__init__@57: Result: Result: self.command.command_definition.description='Set Battery Max Charging Current Solar + AC': self.is_valid=True, self.error=False - self.error_messages=[], self.raw_response=b'^1\x0b\xc2\r',
2024-05-10 06:40:10,557:DEBUG:abstractport:run_command@92: after send_and_receive: Result: self.command.command_definition.description='Set Battery Max Charging Current Solar + AC': self.is_valid=True, self.error=False - self.error_messages=[], self.raw_response=b'^1\x0b\xc2\r',
2024-05-10 06:40:10,558:INFO:device:run@196: Got result: Result: self.command.command_definition.description='Set Battery Max Charging Current Solar + AC': self.is_valid=True, self.error=False - self.error_messages=[], self.raw_response=b'^1\x0b\xc2\r',
2024-05-10 06:40:10,558:DEBUG:device:run@212: Using Output: outputs.Screen: outputs the results to the screen as per the formatter supplied
2024-05-10 06:40:10,559:INFO:screen:process@19: Using output sender: screen
2024-05-10 06:40:10,559:DEBUG:screen:process@20: formatter: outputs the results to standard out in a table (optionally formatted with line art boxes), result: Result: self.command.command_definition.description='Set Battery Max Charging Current Solar + AC': self.is_valid=True, self.error=False - self.error_messages=[], self.raw_response=b'^1\x0b\xc2\r', , mqtt_broker: MqttBroker DISABLED, device_info: <powermon.device.DeviceInfo object at 0x7ccde38d3290>
2024-05-10 06:40:10,560:INFO:table:format@29: Using output formatter: table
2024-05-10 06:40:10,561:DEBUG:table:format@45: displayData: Reading: self.data_name='Error', self.data_value='No readings in result', self.data_unit='', self.is_valid=True
------------------------------------------------------------------
Command: MCHGC0,080 - Set Battery Max Charging Current Solar + AC
------------------------------------------------------------------
Parameter Value Unit
error No readings in result
great - thanks for the contribution
a couple of small comments / changes
be good to add a unit test file and some key tests - especially for crc and valid checks (but also full command etc)
Hi Jblance, I did the work to expand and test the PI18 Protocol
All queries and set functions work so far except for the Yearly/Montly/Daly PV Generated Energy Inquiry. It means that the commands don't exceed even though they are there.
With the SETTER_COMMANDS you expected a ACK or NACK. Although this is chicked up as b"^0" or b"^1", this is not processed. So I adjusted the commands/results so that the program does not break off.
Then I had to make an adjustment at the CRC Check in PI18. Since there is no "^D" back in the SETTER Commands. But only b "^0" or b "^1"
Here are the results of the QUERY_COMMANDS
And here is the debug result of a SETTER_COMMAND set Battery Max Charging Current Solar + AC MCHGC0,080
The "Error no Readings in Result" comes from my adaptation so that it works