-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add MqTT handler #3
base: master
Are you sure you want to change the base?
Conversation
With this, we can now remove the web server, right? |
Thats right. it allows to set the same animations as the webserver and also handles shutdown/reboot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of changing the crappy webinterface to mqtt. Nevertheless, even the webinterface contains some ugly mess of which we should get rid off. It's a good time to do it now.
Please remove the webinterface as well if we don't use it any longer. We especially need to test robustness: what happens if the mqtt server isn't reachable when starting the application (e.g., network cable disconnect on boot) or disappears spuriously (e.g., network disconnect, mosquittod reboot, ...)
I'll test those changes asap.
daemon/mqtt/CMakeLists.txt
Outdated
install(FILES matrix-mqtt | ||
DESTINATION sbin/ | ||
PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_READ OWNER_EXECUTE GROUP_READ GROUP_EXECUTE) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing newline
@@ -0,0 +1,90 @@ | |||
#!/usr/bin/env python3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we missed this so far -- please add a license header when creating new files. I'll amend this in existing files soon…
daemon/mqtt/matrix-mqtt
Outdated
|
||
def on_message_shutdown(client, userdata, message): | ||
if not message.retain: | ||
system("poweroff") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use systemd-poweroff service to power off the system and grant the user poweroff abilities? This would avoid running the script as root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know that this is even possible. Will search for some documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you run a KDE session and press the shutdown button, then your user also must somehow have the permission to shutdown the system.
Seems liks this is done via dbus or console-kit.
That's worth a look:
https://stackoverflow.com/questions/23013274/shutting-down-computer-linux-using-python
Maybe we can instrument python to perform the shutdown directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is a good idea, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks a bit easier: https://wiki.ubuntuusers.de/systemd/systemctl/#System-Kommandos
Just call systemctl reboot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! We only need to make sure that a user may invoke this command.
daemon/mqtt/matrix-mqtt
Outdated
TOPIC_REBOOT = TOPIC_BASE + 'reboot' | ||
TOPIC_SHUTDOWN = TOPIC_BASE + 'shutdown' | ||
|
||
# no root no fun. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm… This has been a mess ever since. We should change that.
daemon/mqtt/matrix-mqtt
Outdated
mqttc.connect_async(MQTT_HOSTNAME) | ||
|
||
try: | ||
mqttc.loop_forever() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the mqtt server suddenly disappears? Will the client automatically reconnect on connection failures or stall/crash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's test it, but based on the documentation a reconnect will be performed until its connected again
daemon/mqtt/matrix-mqtt
Outdated
try: | ||
mqttc.loop_forever() | ||
except KeyboardInterrupt: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A keyboard interrupt will break the loop?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I applied the same logic as you did in the web server
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Hmm, don't know why I handles this exception. Maybe for debugging. Could be that a keyboard interrupt will end the loop. The catch of the exception will shutdown the webserver without failing. Don't think we need this for mqtt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm that's required to quit the loop by pressing ctrl+c.
Allows control of the matrix via mqtt instead of the web gui