Have a look at the schematic.
- pi_scalextric_mqtt contains mqtt broker setup, python scripts and configuration files
- pi_scalextric_spwa contains a simple single page web app to control scalextrix cars via mqtt
- alice-mqtt-broker contains an Aedes MQTT broker implementation, with in-memory persistence, ready for deployment on Heroku. Supports websockets only.
- alice-mqtt-dynamic contains an implementation of the Node-RED mqtt-dynamic node, which supports communication to an MQTT broker via websockets.
This is the parent project covering the above projects, which use a Rasberry Pi to control a modified Scalextric set.
- Set-up a development system connecting the Raspberry Pi and your PC / Mac, via a local network connection, using a router.
- Deploy
alice-mqtt-broker
to Heroku. - Clone
pi_scalextric_mqtt
onto Raspberry Pi:- Edit the
config.json
,resources.json
andsensors.json
files with appropriate details - Run
node-red-start
and import themqtt_flow.json
flow into Node-RED - Change global context: configPath to the absolute path to the
config.json
file - In Node-RED: Setup new Mqtt connections for each Mqtt module and deploy
- Edit the
- Clone
alice-mqtt-dynamic
to the Raspberry Pi- Use the instructions in the repo to replace the mqtt-dynamic node with
alice-mqtt-dynamic
.
- Use the instructions in the repo to replace the mqtt-dynamic node with
- Deploy
pi_scalextric_spwa
to GitHub pages. - Create a QR Code wich will load the SPWA onto a recent Android or iPhone:
- On the RPi: Run
python qrCodeGen.py [PATH_TO_CONFIG_FILE] [HOST_OF_SPWA]
- Generated Qr code can be scanned to direct users to SPWA
- On the RPi: Run
Here's how I'm setting up the system:
-
Web: Create a project alias on a GMail account
-
Web: Create a Heroku account, using the project alias
-
Web: Create an app in the Heroku account
-
Web: Connect Heroku to the
alice-mqtt-broker
and deploy -
Dev Machine: Use an MQTT debug client to check all is OK
-
Download fresh Raspbian.
-
Pi: Install onto SD Card.
-
Boot Pi from SD Card, into Desktop
-
Pi: Update Raspbian
-
Pi: Update Node-RED
- see Node-RED update for Raspberry Pi
- start the Node-RED server, as instructed
-
Install the development environment:
-
Pi: Clone the pi_scalextric_mqtt project
- we'll refer to it as <pi_scalextric_mqtt>
-
Pi: Alter the config file:
- located at path:
<pi_scalextric_mqtt>/mqtt/src/config.json
- set the values for the broker as those you have in your MQTT broker account settings
- set the values for the paths:
- resources:
<pi_scalextric_mqtt>/mqtt/src/pythonScripts/specialWeaponScripts
- sensors:
<pi_scalextric_mqtt>/mqtt/src/pythonScripts/sensorScripts/sensors.py
- resources:
- located at path:
-
Pi: Node-RED: import the project:
- Edit
<pi_scalextric_mqtt>/mqtt_flow.json
. Select all,copy to clipboard, use the Node-RED 'import' function. - Install the correct node types, using the instructions in
- Edit
-
Pi: Node-RED: change parameters
- Mqtt Subscribe: Set Global Context: configPath
- set value to the path:
<pi_scalextric_mqtt>/mqtt/src/config.json
- set value to the path:
- Mqtt Subscribe: Set sensor definition path
- Set value on the Sensors File node:
<pi_scalextric_mqtt>/mqtt/src/sensors.json
- Set value on the Sensors File node:
- Mqtt Subscribe: Set Global Context: configPath
-
Pi:Node-RED: set the mqtt connection parameters
- select any one of the Nodes of type: mqtt-dynamic
- in the sidebar click on the gear icon to bring up the configuration
- the configuration sets the values for all nodes of this type.
- set the MQTT connection info to the same as that entered for the
config.json
-
Pi: Python: Install packages for mqtt - python checks the sensor values and sends to MQTT.
- PLEASE NOTE: PYTHON 3
pip3 install paho-mqtt
Useful refs:
grove pi board - used for convenience
grove pi ir reflective sensors - used for lap-times
This is the work of Yusof Bandar for DigitalLabs@MMU.