Skip to content

Connected Raspberry props for Escape Room, to echo back messages received from MQTT server.

License

Notifications You must be signed in to change notification settings

xcape-io/PyEchoProps

Repository files navigation

PyEcho props

A connected props to echo messages to its sender.

Smiley face Discontinued, prefer PyBlinkEcho in PyProps library

PyEcho props is pure python application to build a Raspberry connected props for Escape Room. It can be used as a base example to hack for creating your own props. It is used in the Room plugin tutorial.

This props listen to MQTT messages received in its inbox and replies the message to its sender.

The props is intended to be controlled from xcape.io Room software, see Add a Raspberry props in the Room manual.

Installation

Download PyEchoProps-master.zip from this GitHub repository and unflate it on your Raspberry Pi.

Install dependencies

pip3 install -r requirements.txt

Edit definitions.ini to set MQTT topics for your Escape Room:

[mqtt]
; mqtt-sub-* and app-inbox topics are subscribed by MqttApp
app-inbox = Room/My room/Props/Raspberry Echo/inbox
app-outbox = Room/My room/Props/Raspberry Echo/outbox
mqtt-sub-room-scenario = Room/My room/Control/game:scenario
;mqtt-sub-control-scenario = Room/My room/Control/game:scenario
;mqtt-sub-control-clock-minutes=Room/My room/Control/game:clock:minutes
;mqtt-sub-control-countdown-minutes=Room/My room/Control/game:countdown:minutes
;mqtt-sub-control-players=Room/My room/Control/game:players

Usage

Start main.py script:

usage: python3 main.py [-h] [-s SERVER] [-p PORT] [-d] [-l LOGGER]

optional arguments:
 -h, --help   show this help message and exit
 -s SERVER, --server SERVER
      change MQTT server host
 -p PORT, --port PORT change MQTT server port
 -d, --debug   set DEBUG log level
 -l LOGGER, --logger LOGGER
      use logging config file

To switch MQTT broker, kill the program and start again with new arguments.

SSH relaunch command

The command to relaunch the props from xcape.io Room software is :

$ ps aux | grep python | grep -v "grep python" | grep PyEchoProps/main.py | awk '{print $2}' | xargs kill -9 && screen -d -m python3 /home/pi/Room/Props/PyEchoProps/main.py -s %BROKER%

Understanding the code

PropsApp

Echo props is built with the following files:

  • main.py main script to start the props
  • constants.py
  • definitions.ini
  • logging.ini
  • PropsApp.py props related code

It depends on:

  • MqttApp.py base class to publish/subscribe MQTT messages
  • MqttVar.ini base class to optimize network communications
  • Singleton.ini to ensure one instance of application is running

You can use PropsApp.py as a template to create your own connected props, you will also add GPIO elements.

About create-props-tgz.bat:

  • install 7-Zip on your Windows desktop
  • run create-props-tgz.bat to archive versions of your work

MQTT message protocol:

This props has been created to be controlled with Room software so MQTT messages published in the props outbox implement the Room Outbox protocol.

IDE for hacking EchoApp.py:

You can open a PyCharm Professional project to hack the code remotely, thanks to .idea folder. Or if you prefer to the code hack directly on the Raspberry, we suggest Eric6 IDE.

MqttApp and MqttVar base classes

PropsApp extends MqttApp, the python base app for Raspberry connected props.

MQTT topics are defined in definitions.ini.

PubSub variables extend MqttVar, it is an helper to track value changes and to optimize publishing values in MQTT topic outbox.

You might not modify MqttApp.py an MqttVar.py files.

Notes about MQTT QoS:

Python script hangs have been reported when paho-mqtt is running asynchronously with QoS 2 on a network with significant packet loss (particularly Wifi networks).

We have choosen MQTT QoS 1 as default (see constants.py).

Other python frameworks for connected props

At Faure Systems we engineered connected props with several frameworks for many different needs:

  • Asyncio props
    • game automation
    • relay box control (room electricity and doors)
    • GPIO only automation
  • PyGame props
    • Tetris hacked
    • mechanic Piano sound player
    • hacker intrusion puzzle
  • PyQt5 props
    • fortune telling table (alphanum LED switching)
    • electric jack cylinder control
  • Guizero props
    • teletext
  • Kivy props
    • teletext with visual effects

You may follow on our GitHub repositories, props source code is planned to be published in year 2020.

Author

Faure Systems (Oct 9th, 2019)

About

Connected Raspberry props for Escape Room, to echo back messages received from MQTT server.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages