Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input asynchronous commands from mqtt to the inverter #495

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

persuader72
Copy link

This PR add the ability to receive asynchronous commands from mqtt borker and forward them to the inverter.

For now only configuration file in daemon mode is supported.

All section with option direction set to the value in will be considered inputs and not will not be sent in the periodically. But if a mqtt topic "{TAG}/command" is received and the payload of this topic is one of input commands the commands is immediately sent to the inverter.

TODO: A method to acknowledge the command has been executed.

Follow is an example to send a asynchronous command (POP02) to inverter with tag "Inverter"

mosquitto_pub -h 127.0.0.1 -t "Inverter/command" -u <MQTTUSER> -P <MQTTPASSWORD> -m POP02
[SETUP]
pause=5
mqtt_broker=192.168.75.105
mqtt_user=<MQTTUSER>
mqtt_pass=<MQTTPASSWORD>

[Inverter_1]
protocol=PI30
port=/dev/hidraw0
baud=2400
command=QPIGS
tag=Inverter
outputs=mqtt

[Inverter_2]
protocol=PI30
port=/dev/hidraw0
baud=2400
command=QPIRI
tag=InverterConf
outputs=mqtt

[set_mode_solar]  
protocol=PI30
port=/dev/hidraw0
baud=2400   
command=POP01
tag=Inverter
outputs=mqtt
direction=in

[set_mode_sbu]  
protocol=PI30
port=/dev/hidraw0
baud=2400   
command=POP02
tag=Inverter
outputs=mqtt
direction=in

[get_configuration]  
protocol=PI30
port=/dev/hidraw0
baud=2400   
command=QPIRI
tag=Inverter
outputs=mqtt
direction=in

@jblance
Copy link
Owner

jblance commented May 26, 2024

why configure each command?
i was thinking more of an async/adhoc command approach, with a config similar to:

[async_command]  
topic=Inverter1/command
result_topic=Inverter1/results
allowed_commands=['POP02', 'POP00']
protocol=PI30
port=/dev/hidraw0
baud=2400   
tag=Inverter
outputs=mqtt

this simplifies config while allowing adhoc commands
any thoughts?

@persuader72
Copy link
Author

persuader72 commented May 27, 2024

Yes I forgot to mention that the command key is working like other commands in mpp-solar and can be provided multiple input commands on a single line separating it with the # character.

So the following configuration can work as well:

[set_mode_sol_or_sbu]  
protocol=PI30
port=/dev/hidraw0
baud=2400   
command=POP01#POP02
tag=Inverter
outputs=mqtt
direction=in

To better understand your thoughts about the following line:

[async_command]

are you proposing to remove the direction option and to consider as input commands the ones in configuration sections that starts with "async_"?

I think add this to options is a good idea. I will try to work on it.

topic=Inverter1/command
result_topic=Inverter1/results

@jblance
Copy link
Owner

jblance commented May 27, 2024

To better understand your thoughts about the following line:

[async_command]

are you proposing to remove the direction option and to consider as input commands the ones in configuration sections that starts with "async_"?

I think add this to options is a good idea. I will try to work on it.

topic=Inverter1/command
result_topic=Inverter1/results

Its to have only one config section (per inverter) that defines a topic to 'listen' to, and then runs any commands found (and optionally sends the results to the result_topic) - also optionally restricting the commands allowed
so instead of defining each 'in' command effectivetly an 'in' topic is setup

in powermon (which is the evolution of mppsolar), I define adhoc commands topic as an optional part of the mqtt broker

mqttbroker:
  name: localhost
  port: 1883
  username: null
  password: null
  adhoc_topic: powermon/adhoc_commands
  adhoc_result_topic: powermon/adhoc_commands/results

The callback for the adhoc commands topic, parses and adds any commands to a list, that is then processed as part of the main run loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants