Skip to content

Controlling a pi_scalextric via a single page web application. A whole load of mqtt, python and node-red

Notifications You must be signed in to change notification settings

aliceliveprojects/pi_scalextric

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

pi_scalextric

Have a look at the schematic.

Project Structure

  • 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.

Summary

This is the parent project covering the above projects, which use a Rasberry Pi to control a modified Scalextric set.

  1. Set-up a development system connecting the Raspberry Pi and your PC / Mac, via a local network connection, using a router.
  2. Deploy alice-mqtt-broker to Heroku.
  3. Clone pi_scalextric_mqtt onto Raspberry Pi:
    1. Edit the config.json, resources.json and sensors.json files with appropriate details
    2. Run node-red-start and import the mqtt_flow.json flow into Node-RED
    3. Change global context: configPath to the absolute path to the config.json file
    4. In Node-RED: Setup new Mqtt connections for each Mqtt module and deploy
  4. Clone alice-mqtt-dynamic to the Raspberry Pi
    1. Use the instructions in the repo to replace the mqtt-dynamic node with alice-mqtt-dynamic.
  5. Deploy pi_scalextric_spwa to GitHub pages.
  6. Create a QR Code wich will load the SPWA onto a recent Android or iPhone:
    1. On the RPi: Run python qrCodeGen.py [PATH_TO_CONFIG_FILE] [HOST_OF_SPWA]
    2. Generated Qr code can be scanned to direct users to SPWA

How To

Here's how I'm setting up the system:

  1. Web: Create a project alias on a GMail account

  2. Web: Create a Heroku account, using the project alias

  3. Web: Create an app in the Heroku account

  4. Web: Connect Heroku to the alice-mqtt-broker and deploy

  5. Dev Machine: Use an MQTT debug client to check all is OK

  6. Download fresh Raspbian.

  7. Pi: Install onto SD Card.

  8. Boot Pi from SD Card, into Desktop

  9. Pi: Update Raspbian

  10. Pi: Update Node-RED

    1. see Node-RED update for Raspberry Pi
    2. start the Node-RED server, as instructed
  11. Install the development environment:

    1. see Development Environment
  12. Pi: Clone the pi_scalextric_mqtt project

    1. we'll refer to it as <pi_scalextric_mqtt>
  13. 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
  14. 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
  15. Pi: Node-RED: change parameters

    • Mqtt Subscribe: Set Global Context: configPath
      • set value to the path: <pi_scalextric_mqtt>/mqtt/src/config.json
    • Mqtt Subscribe: Set sensor definition path
      • Set value on the Sensors File node: <pi_scalextric_mqtt>/mqtt/src/sensors.json
  16. 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
  17. 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:

Raspbian Download Page

MQTT.fx

GitCola

pi pinout

LED

resistor lookup

TIP3055 (NPN)

back emf supression

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.

About

Controlling a pi_scalextric via a single page web application. A whole load of mqtt, python and node-red

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published