Spanni26 / pyHPSU

Python Script to read and send commands to a Rotex HPSU
26 stars 15 forks source link

Autostart after reboot #47

Closed KalaNagHTD closed 3 years ago

KalaNagHTD commented 3 years ago

I‘d like to autostart pyHPSU after rebooting my Raspberry Pi. Can anyone help me with a working procedure?

regards Karl

Spanni26 commented 3 years ago

With wihich paramaters shozuld it be started?

Regards

Daniel

Am 18.03.2021 um 09:54 schrieb KalaNagHTD:

I‘d like to autostart pyHPSU after reboot of my Raspberry Pi. Can anyone help me with a working procedure?

regards Karl

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Spanni26/pyHPSU/issues/47, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2I5HDEVMICAYE4JRMMQ4TTEG5VHANCNFSM4ZMF5DPA.

KalaNagHTD commented 3 years ago

pyHPSU.py -a -o MQTT

Am 18.03.2021 um 10:18 schrieb Spanni26 @.***>:

 With wihich paramaters shozuld it be started?

Regards

Daniel

Am 18.03.2021 um 09:54 schrieb KalaNagHTD:

I‘d like to autostart pyHPSU after reboot of my Raspberry Pi. Can anyone help me with a working procedure?

regards Karl

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Spanni26/pyHPSU/issues/47, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2I5HDEVMICAYE4JRMMQ4TTEG5VHANCNFSM4ZMF5DPA.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

Spanni26 commented 3 years ago

Hello,

set "OUTPUT_TYPE = MQTT" in /etc/pyHPSU/pyhpsu.conf, so you don't have to set it at the command line.

There is a systemd service for pyHPSU. To Enable ist: systemctl enable hpsu.service To start it: systemctl start hpsu.service

Thats all.

Regards

Daniel

Am 18.03.2021 um 10:52 schrieb KalaNagHTD:

pyHPSU.py -a -o MQTT

Am 18.03.2021 um 10:18 schrieb Spanni26 @.***>:

 With wihich paramaters shozuld it be started?

Regards

Daniel

Am 18.03.2021 um 09:54 schrieb KalaNagHTD:

I‘d like to autostart pyHPSU after reboot of my Raspberry Pi. Can anyone help me with a working procedure?

regards Karl

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Spanni26/pyHPSU/issues/47, or unsubscribe

https://github.com/notifications/unsubscribe-auth/AC2I5HDEVMICAYE4JRMMQ4TTEG5VHANCNFSM4ZMF5DPA.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spanni26/pyHPSU/issues/47#issuecomment-801783646, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2I5HE3L4KK4DU5ZVXYFLDTEHENLANCNFSM4ZMF5DPA.

martinbischofff commented 3 years ago

I'm using a script in /etc/init.d that calls pyHPSU.py -a.

Don't know whether Daniel's approach is better or whether it's more or less the same.

Regards Martin

KalaNagHTD commented 3 years ago

Which section header do I need in pyhpsu.conf?

Spanni26 commented 3 years ago

Can you show us your pyhpsu.conf?

Am 18.03.2021 um 12:15 schrieb KalaNagHTD:

Defining MQTT output in pyhpsu.conf configparser.MissingSectionHeaderError: File contains no section headers. file: '/etc/pyHPSU/pyhpsu.conf', line: 1

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spanni26/pyHPSU/issues/47#issuecomment-801837119, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2I5HFXYTLTKYLBDNXLQR3TEHOFHANCNFSM4ZMF5DPA.

Spanni26 commented 3 years ago

/etc/init.d works only for compatibility. Nearly every linux distribution uses systemd. But systemd can work with initd scripts.

Am 18.03.2021 um 11:54 schrieb martinbischofff:

I'm using a script in /etc/init.d that calls pyHPSU.py -a.

Don't know whether Daniel's approach is better or whether it's more or less the same.

Regards Martin

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spanni26/pyHPSU/issues/47#issuecomment-801825458, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2I5HHRHD6OODWD3WZOR7LTEHLYDANCNFSM4ZMF5DPA.

KalaNagHTD commented 3 years ago

Here is my pyhpsu.conf. I had added the "OUTPUT_TYPE = MQTT" as the first line (removed here):

pi@raspberrypi:/etc/pyHPSU $ cat pyhpsu.conf

[PYHPSUD] PYHPSUD_DEVICE=PYCAN PYHPSUD_LANG=EN PYHPSUD_PORT=/dev/ttyUSB0

[PYHPSU] PYHPSU_DEVICE = PYCAN PYHPSU_PORT = PYHPSU_LANG = DE OUTPUT_TYPE = MQTT

[CANPI] timeout=0.05

[MQTT] BROKER = localhost PORT = 1883 USERNAME = pi PASSWORD = raspberry CLIENTNAME = rotex_hpsu PREFIX = rotex

[JOBS] bpv = 5 posmix = 5 flow_rate = 5 water_pressure = 60 t_dhw_set = 60

Spanni26 commented 3 years ago

" I had added the "OUTPUT_TYPE = MQTT" as the first line (removed here):"

Thats wrong. It hast to be under [PYHPSU] In the conf you posted, it is alread configured.

Am 18.03.2021 um 14:02 schrieb KalaNagHTD:

I had added the "OUTPUT_TYPE = MQTT" as the first line (removed here):

KalaNagHTD commented 3 years ago

Sorry, I accidentally managed to close this issue :-(

MQTT doesn‘t work with just the setting in the pyhpsu.conf as shown above. I need to specify MQTT in the command line. Otherwise I get the default JSON output. I have no idea why!

Spanni26 commented 3 years ago

Hmmm, possibly a bug. I will inspect this. You can modify /etc/systemd/system/hpsu.service to youre needs and you have to call "systemctl --system daemon-reload" and "systemctl restart hpsu.service"

Regards

Daniel

Am 18.03.2021 um 15:45 schrieb KalaNagHTD:

Sorry, I accidentally managed to close this issue :-(

MQTT doesn‘t work with just the setting in the pyhpsu.conf as shown above. I need to specify MQTT in the command line. Otherwise I get the default JSON output. I have no idea why!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Spanni26/pyHPSU/issues/47#issuecomment-801986996, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2I5HFG3VVNVB25JF3QGM3TEIGXZANCNFSM4ZMF5DPA.

KalaNagHTD commented 3 years ago

Many thanks, Daniel! I added „-o MQTT“ to the hpsu.service and got it running :-)

regards Karl

segaura commented 3 years ago

IMHO the power of systemctl is in its ability to restart the process when something bad happened, and also to enforce an order between various services at startup, this is my modified hpsu.service file. Please note the Restart=on-failure and the various After instructions

[Unit]
Description=HPSU in auto mode with output to influxDB and MQTT plus MQTT Daemon mode activated
Requires=canable.service
After=canable.service
After=network-online.target

[Service]
Type=simple
ExecStartPre=
#EnvironmentFile=/etc/pyHPSU/pyhpsu.conf
ExecStart=python3 /usr/bin/pyHPSU.py -a -o influxdb -o mqtt --mqtt_daemon --log_level WARNING --log /tmp/pyHPSU.log
ExecReload=
ExecStop=
Restart=on-failure
WorkingDirectory=/root
User=root

[Install]
WantedBy=multi-user.target