A test automation frontend hosted on Raspberry Pi with instrument communication handled by a flask backend.
- Perform automation tests over GPIB or ethernet
- Monitor, review, and anlyze test data from react frontend
- Self-Hosted
- Free and Open Source (GPLv3)
- Encrypt communication to the client
- client-side face detection
- thermal imager image processing
- easier setup and deployment
When users connect to the Raspberry Pi’s IP address through their web browser, they are greeted with CalPi’s dashboard page, which provides basic hardware stats for the raspberry pi including CPU, memory, and disk utilization.
The main goal of CalPi
was to be flexible to the user. Whether on-site or remote, users can manage tests, request results, or observe on the status of a currently running test.
-
The frontend is a Node.js enabled React-based web framework providing performant statically generated web pages with server-side rendering.
-
The backend is a flask endpoint running on Python. This means any api calls to our backend are routed back to the Raspberry Pi where Python handles hardware communication.
Given the limited resources available on the Raspberry Pi, much of the post processing and data analytics occurs on the client-side while much of the server-side functions are visa communication to instruments, GPIO manipulation, and data logging to csv files.
A Qt interface will allow users a physical interface directly to the Raspberry Pi. For instance users will be able to use the touchscreen to run tests in the future, but for now, we are focusing on the web interface.
PiCal
is designed to be deployed flexibly.
-
Make a projects directory:
$ mkdir ~/Documents/projects
-
Change directory:
$ cd ~/Documents/projects
-
Clone this repository:
$ git clone https://github.com/Tektronica/flask-nextjs-pyqt-app
Creat the virtual environment the backend Flask app will run inside
-
Navigate to the cloned directory:
$ cd flask-nextjs-pyqt-app
-
Navigate to the backend directory:
$ cd flask-backend
-
Create a virtual environment called venv:
$ py -m venv venv
-
Activate the environment:
$ source venv/bin/activate
-
Update pip:
(venv) $ python -m pip install --upgrade pip
-
Install python libraries to the environment:
(venv) $ pip install -r requirements.txt
GPIB resources requires to install a gpib driver. Unfortunately, there are no native solutions from National Instruments compatible with Raspbian OS. Fortunately, linux-gpib does the trick.
-
Follow the instructions and use their script by reviewing:
-
The important piece is the shell script,
install_linux_gpib.sh
, located insde:$ ~/Documents/projects/flask-nextjs-pyqt-app/flask-backend
- Enter
yes
to update and install system software. Yes
to reboot once the update finishes.$ cd /boot
$ sh install_linux_gpib.sh
No
to update softwareYes
to install linux-gpibNo
to install teckitNo
to install sambaNo
to install Pitft
- Enter
The Nextjs is an opinionated framework built on top of React.js, which uses Node.js libraries
-
update the packages running on the Raspberry Pi OS:
$ sudo apt update
$ sudo apt upgrade
-
Add the repository for the current LTS release of NodeJS to the Raspberry Pi:
$ curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash -
-
Install the Package:
$ sudo apt install nodejs
-
Navigate to the
nextjs-frontend
directory of the react project and install the dependencies:$ cd ~/Documents/projects/flask-nextjs-pyqt-app/nextjs-frontend
$ npm i
The application is intended to run on your LAN by broadcasting from the Raspberry Pi's IP address. Consider setting up a static IP for the Raspberry Pi. However, in order for the frontend to talk to the backend, we need to proxy all frontend api calls to the backend. In this example, the Raspberry Pi is hosted on 192.168.1.211
and the flask backend is broadcasting off port 5000
.
-
open
package.json
from thenextjs-frontend
directory. Replace the following address atline 35
with your desired address:[ 35 ]
"proxy": "http://localhost:5000"
[ 35 ]
"proxy": "http://192.168.1.211:5000"
-
Now open
next.config.js
from the samenextjs-frontend
directory. Replace the following address atline 14
with your desired address:[ 14 ]
destination: 'http://localhost:5000/:slug*'
[ 14 ]
destination: 'http://192.168.1.211:5000/:slug*'
Two running terminals are required for this process. A flask app runs in one terminal while the react app runs in the other. There are shell scripts available to help perform these steps faster, but we're covering the manual setup for completeness. In no particular order...
-
First Terminal:
-
Navigate inside the
flask-backend
directory:$ cd ~/Documents/projects/flask-nextjs-pyqt-app/flask-backend
-
Run the flask app using the Raspberry Pi IP address has the host argument
$ venv/bin/flask run --debugger --host=192.168.1.211
-
-
Second Terminal:
-
Navigate inside the
nextjs-frontend
directory:$ cd ~/Documents/projects/flask-nextjs-pyqt-app/nextjs-frontend
-
Run the react app using the Raspberry Pi IP address has the host argument:
$ npm run dev
-
-
Finally, in your browser, navigate to:
192.168.1.211:3000