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

Remote control with MQTT #584

Merged
merged 4 commits into from
Oct 1, 2019
Merged

Remote control with MQTT #584

merged 4 commits into from
Oct 1, 2019

Conversation

andreasbrett
Copy link
Contributor

First implementation of #581

  • depends on paho-mqtt lib (pip3 install paho-mqtt)
  • can connect via user/password or certificate-based authentication
  • to be done
    • create service file
    • include in install script

@MiczFlor
Copy link
Owner

Hi @andreasbrett
could you write here a few lines about how to operate this? As I said, I have no smart home...
It's a daemon, so it should be started. Even without the install script, how would that be done manually? I can then make an attempt to include it in the install script.
Thank! micz

@andreasbrett
Copy link
Contributor Author

andreasbrett commented Sep 29, 2019

@MiczFlor of course, let me see...

Starting the daemon

The daemon is run by executing the daemon_mqtt_client.py script. It's just like the rfid reader daemon script and will run in an endless loop.

How it works

Phoniebox' MQTT client connects to the MQTT server that is defined in the SETTINGS section of the script itself. It is able to connect by authenticating via

  1. user/password or
  2. with server/client certificates

depending on what the server expects (typically Mosquitto by Eclipse is used as a MQTT server in the smart home communities). Once connected it will publish messages to the mqttBaseTopic that is defined in SETTINGS (defaults to phoniebox). Other MQTT clients that are e.g. part of a smart home solution can listen and respond to this base topic and its sub-topics.

Phoniebox' MQTT client will do the following things:

  1. at startup send state and version info about Phoniebox to
    • mqttBaseTopic/version (e.g. 1.2-rc1)
    • mqttBaseTopic/edition (e.g. classic)
    • mqttBaseTopic/state (online)
  2. at shutdown send state info to
    • mqttBaseTopic/state (offline)
  3. periodically send all attributes to mqttBaseTopic/attributes/$attributeName (interval in seconds is defined in refreshIntervalPlaying and refreshIntervalIdle)
  4. listen for attribute requests on mqttBaseTopic/get/$attribute
  5. listen for commands on mqttBaseTopic/cmd/$command (if command needs a parameter it has to be provided via payload)

mqttBaseTopic/get/$attribute

MQTT clients can (additionally to the periodic updates) request an attribute of Phoniebox. Sending an empty payload to mqttBaseTopic/get/volume will trigger Phoniebox' MQTT client to fetch the current volume from MPD and send the result to mqttBaseTopic/attributes/volume.

Possible attributes

  • volume
  • mute
  • repeat
  • random
  • state
  • file
  • artist
  • albumartist
  • title
  • album
  • track
  • elapsed
  • duration
  • trackdate
  • last_card
  • maxvolume
  • volstep
  • idletime
  • rfid (statues of rfid service [true/false])
  • gpio (status of gpio service [true/false])

Help

Sending empty payload to mqttBaseTopic/get/help will be responded by a list of all possible attributes to mqttBaseTopic/available_attributes

mqttBaseTopic/cmd/$command

MQTT clients can send commands to Phoniebox. Sending an empty payload to mqttBaseTopic/cmd/volumeup will trigger Phoniebox' MQTT client to send that command to MPD via playout_controls.sh. If the command needs a parameter (e.g. setmaxvolume) it has to be provided in the payload.

Possible commands

  • volumeup
  • volumedown
  • mute
  • playerplay
  • playerpause
  • playernext
  • playerprev
  • playerstop
  • playerrewind
  • playershuffle
  • playerreplay
  • scan
  • shutdown
  • shutdownsilent
  • reboot
  • disablewifi

Possible commands (with parameters)

  • setvolume
  • setvolstep
  • setmaxvolume
  • setidletime [in minutes]
  • playerseek [e.g. +20 for 20sec ahead or -12 for 12sec back]
  • shutdownafter [in minutes; 0 = remove timer]
  • playerstopafter [in minutes]
  • playerrepeat [off / single / playlist]
  • rfid [start / stop]
  • gpio [start / stop]

Help

Sending empty payload to mqttBaseTopic/cmd/help will be responded by a list of all possible commands to mqttBaseTopic/available_commands and mqttBaseTopic/available_commands_with_params

- fixed some major bugs of prior version
- modified "get" and "set" topic to not listen to their payloads but rather their subtopics
- renamed "set" topic to "cmd"
- added a whole lot of commands and attributes
- introduced 2 refresh intervals based on player state (playing vs idle)
@MiczFlor
Copy link
Owner

MiczFlor commented Oct 1, 2019

Hi @andreasbrett
thanks for the contribution!!!
Please have a look here at the wiki and possible make changes as your work progresses.
https://github.com/MiczFlor/RPi-Jukebox-RFID/wiki/Smart-Home-remote-control-with-MQTT
I will merge this to master now, because it's not interferring with anything else.

@MiczFlor MiczFlor merged commit 8ea66eb into MiczFlor:develop Oct 1, 2019
@andreasbrett andreasbrett deleted the patch-1 branch October 2, 2019 20:03
@Piehti
Copy link

Piehti commented Mar 19, 2020

Awesome. Guess I got to give it another try. Last one failed. Stuck with a working MQTT polling.

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.

3 participants