This project consists of two parts: a backend that runs on a Raspberry Pi written in Python, and a front end website client written using React.js. The two communicate over a point-to-point wifi connection.
Contents:
Installation:
git clone git@github.com:ANU-Rocketry/control-panel.git
and cd control-panel
control-panel/reactfront
, run npm ci
to install dependencies for the React.js front endcontrol-panel/src
, run pip install -r requirements.txt
to install server dependencies (this is so you can use your computer for a development server with fake data instead of a Raspberry Pi)Then every time you want to run it:
reactfront
run npm start
to launch the app on http://localhost:3000/
src
run python server.py --dev
to start a development backend server generating fake data, and paste the IP address it prints out into the "R-Pi IP" field in the appYou'll need a Raspberry Pi and your laptop, and some way of putting them on the same network. You can network with point-to-point ethernet or a hotspot + Linux compatible wifi dongle (don't need wifi dongle on newer Pi's). You cannot use ResNet as they block the ports we need.
Set-up takes about 20 minutes of supervised work, then several hours (~1 for RPi 4b, 4 for RPi 2b) of waiting in the final step where you build Python 3.10 from source, plus a quick command at the end.
192.168.0.5
sudo apt-get update && sudo apt-get install git screen python3-pip libusb-1.0-0 libusb-1.0-0-dev
(note the dashes where you'd expect periods to be in the libusb headers)screen -S rocketry_session
(this opens a fresh terminal which you can close without stopping running processes, so your SSH window can be closed)
screen -r
to resume it.git clone https://github.com/labjack/exodriver
)cd exodriver && sudo ./install.sh && cd ~
)git clone https://github.com/ANU-Rocketry/control-panel
)sudo nano /etc/rc.local
#!/bin/sh -e
sudo sh /home/pi/control-panel/startup.sh &
exit 0
Set up static IP
sudo nano /etc/dhcpcd.conf
and paste this at the bottom:
interface eth0
static ip_address=192.168.0.5/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
Then it will have the IP 192.168.0.5
. This assumes the router has the IP 192.168.0.1
.
If you need to use another ethernet connection you have two options: plug the outside network into the WAN port of the router you normally use, or connect directly and comment out these lines with #
at the start of each line temporarily if you need to.
apcupsd
daemon to get UPS battery messages
sudo apt-get install apcupsd
sudo nano /etc/default/apcupsd
and change no
to yes
sudo nano /etc/apcupsd/apcupsd.conf
and set UPSNAME rock-ups
(because it's an 8 char limit), UPSCABLE usb
, UPSTYPE usb
, DEVICE
(without the /dev/tty*
part so it searches all serial connections), MINUTES 0
(avoid auto-shutdown)sudo apcupsd restart
or sudo /etc/init.d/apcupsd restart
or sudo reboot
- whichever worksapcaccess status
comes up with a status other than COMMLOST
(it should say STATUS : ONBATT
or STATUS : ONLINE
)ssh-copy-id pi@192.168.0.5
in a terminal on your laptop to copy your SSH key so you don't need a password when using ssh pi@192.168.0.5
wget -qO - https://raw.githubusercontent.com/tvdsluijs/sh-python-installer/main/python.sh | sudo bash -s 3.10.0
(this will take an hour for a new Pi and 3-4 hours for an older one!)
Python-XXX.tar.xz
and Python-XXX
folderssudo python3.10 -m pip install --upgrade pip && cd ~/control-panel/src && sudo python3.10 -m pip install -r requirements.txt
Whenever the pi is turned on from now on, the startup script will automatically host the frontend on http://192.168.0.5:3000
and the backend on http://192.168.0.5:8888
. The backend will fail to run if the Pi is powered before the LabJack USBs are plugged in. If this happens, you can SSH into it and sudo reboot
when it should be ready
Ground site:
sudo reboot
it later!)Range/control site:
http://192.168.0.5:3000
. Set R-Pi IP
to 192.168.0.5
in the browser.Sequences:
src/sequences/sequence_name.py
files on the Pi server. Use SSH to edit them (if you've got internet, it's better to update the repo and pull the changes on the Pi).src/commands.py
and the valve naming scheme is in src/stands.py
. These are interpreted on the fly by the server in src/server.py
's load_sequence
method..py
)To run the processes manually so you can see their output, SSH in and pkill python3.10
. Then just use python3.10 server.py
in the src
folder to run a WebSockets Python server on port 8888. If you want to test without LabJacks connected, you can get a simulated LabJack with sine wave pressure data by using python3.10 server.py --dev
.
The front end is written using Node and React, but the version in the build
folder is static and already built and just needs to be locally hosted. python http.server
is one way of doing this, but there are others. When pushing front-end changes, make sure to run npm run build
to make sure the static already built version is kept up to date. You'll also need to pull/scp
the new version on the Pi.
For developing and debugging the front-end, you do need Node.js installed. To develop the front-end, you need nodejs. Run npm ci
in the reactfront
folder to install dependencies. Run npm run build
to generate the reactfront/build
folder which is what the Pi hosts on http:192.168.0.5:3000
. To go into a local interactive debugging mode with hot reloading, run npm start
and set R-Pi IP
to 192.168.0.5
in the browser.
Whenever you make changes on your laptop, you need to copy them over to the Pi via scp
(if you're on a test site on the same network without internet) or push to git and pull on the Pi (if the Pi has internet access).
To test the server locally, run python3 server.py --dev
on your laptop. In the frontend, you'll need to change R-Pi IP
to your local IP address. You should see simulated sine wave pressure data.
If you have any problems, just file a GitHub Issue, contact us on Microsoft Teams or email our student emails.
The startup script on the Pi runs a static server with reactfront/build
, so you can update these files with scp
and then reload the page to update the front end on any device:
# delete old build (on the raspberry pi!)
ssh pi@192.168.0.5
cd ~/control-panel/reactfront
rm -r build
logout
# scp over new build (on your machine!)
cd reactfront
npm run build
scp -r build pi@192.168.0.5:/home/pi/control-panel/reactfront
# Reload http://192.168.0.5:3000 in your browser