This git repo is for the code on the Raspberry Pi
Heroku Cloud Server & Web Browser Repo | Raspberry Pi (Network Adapter) Repo | Ventilator (Arduino) Repo |
---|---|---|
Ruby on Rails | Flask | Arduino Board |
Javascript | Python | C++ |
Create a lightweight Raspberry Pi application to serve as a network adapter to relay data from ventilators to a central monitoring dashboard (javascript web-browser application).
As of 22-April-2020: Currently, the app is in demo/testing mode only. This software is not approved to be used in a medical setting.
Many of the rapidly manufacturable ventiltor designs utilize and arduino-based control system which does not have a network interface. The raspberry pi provides this network interface, serving as an API endpoint which can connect to central monitoring dashboard (javascript web-browser application). Raspberry pi's are affordable, easy to program, available in large quantities, locally sourceable, and reliable (by consumer hardware standards).
- Obtain a Raspberry Pi board. Many raspberry pi's will work, but the Raspberry Pi 3 Model B+ is widely available for an affordable price (~$ USD). These products are widely avialable, so shop around. Newark is the main US distributor and currently has about 56,000 Raspberry Pi 4 Model B's in stock for ~$55 USD each.
- Obtain a power supply and a The Rasperry Pi is power hungry, especially when you have an arduino plugged in, so be sure to pick up a beefy power supply if you don't already have one. Be sure to pick up the correct power supply for your board - the Raspberry Pi Model 4's now use a USB-C power supply instead of the old boards, which use a USB micro power supply.
- If you'll be using a display monitor with your pi (recommended - easier than headless mode) you will need the appropriate HDMI cable. Please note that the Raspberry Pi 4 now uses a mini-HDMI instead of a full size HDMI video cable.
- Obtain an SD card - buy a high quality one with a good amount of memory. The Sandick Ultra Plus microSDHC UHS-I 32 GB seems to work nicely.
- Obtain an SD card reader if you don't already have one.
The flask server is configured to start automatically when the pi is booted and restart if there is an error.
- Flask server code folder: /opt/remote-ventilator-monitor
The Provisioning Script makes it easy to generate an SD card image for your raspberry pi.
The pi runs the following services:
Service | Purpose |
---|---|
set-hostname | Set hostname of the pi |
remote-ventilator-monitor | Flask Server |
avahi-daemon | Implement Bonjour |
- Services are managed using systemctl
- These services are configured to run automatically when the pi is booted, and to restart automatically in the event of an error
- To check the current status of a service,
sudo systemctl status <service-name>
Here is a quick primer in using systemctl if you need to troubleshoot the services:
- Service unit files are located in the /lib/systemd/system directory with a .service extension
- To manually start a service,
sudo systemctl start, <service-name>
- To manually restart a service,
sudo systemctl restart, <service-name>
- To manually stop a running service,
sudo systemctl stop, <service-name>
- To tell systemd to automatically start a service at boot,
sudo systemctl enable <service-name>
- To disable a service from starting automatically at boot,
sudo systemctl disable <service-name>
The easiest way to get your raspberry pi up & running is to create an SD card image with our provisioning script. However, if you want to manually set up a raspbbery pi, here's how:
- Download the SD Card Formatter tool to your desktop computer and format your SD card.
- Download the Raspberry Pi Imager for your desktop computer operating system.
- Open the Raspberry Pi Imager and install the Rasbian Lite Image onto your SD card
- Insert your SD card into your pi, connect your desktop monitor, keyboard, and mouse, and plug your pi into your power supply
- When the pi boots, enter the default username: pi and password: raspberry
- Either plug your raspberry pi into your local ethernet network or add your wifi credentials to the wpa_supplicant.conf file.
- The default hostname of the pi is
raspberrypi
which will make your pi accessible on your local network via the url http://www.raspberrypi.local. Here, we will change the host name toventilator-1
so the pi will be accessible on our LAN via the url http://www.ventilator-1.local. Change the host name of your raspberry pi using the nano (new to nano?):sudo nano /etc/hostname
-> change the host name toventilator-1
or similar. Use a different host name for each pi. - Edit the /etc/host file
sudo nano /etc/hosts
and changeraspberrypi
toventilator-1
- Update the apt package manager
sudo apt-get update
- Install git
sudo apt-get install git
- Install the python 3 package manager
sudo apt-get install python3-pip
- Install pipenv
sudo apt-get install pipenv
- Clone this git repo:
git clone https://github.com/Open-Ventilator-Remote-Monitoring/remote-ventilator-monitor-pi.git
cd remote-ventilator-monitor-pi
- Intall the python dependencies for the virtual environment
pipenv install
- Open a virtual environment
sudo pipenv shell
- Update the
application-*.yml
files with the correct config
ventilator:
name: <name of ventilator>
connection:
type: <random (testing) or serial(ardunio connection)>
link: <serial port>
baud: <baud speed>
timeout: <timeout amount>
alarm:
pin: <-1 (testing) or gpio port on pi>
device:
id: <self set id of raspberry pi>
roles:
ventilatorAlarmSoundMonitor: <true(enable alarm plugin) or false(disable)>
ventilatorDataMonitor: <true(enable ventilator plugin) or false(disable)>
- Start the server using the start script:
FLASK_ENV=development FLASK_PORT=80 ./start.sh
(You may need to runchmod 777 start.sh
first). - Open a web browser on your desktop (connected to the same network as your pi) and visit the url
http://ventilator-1.local
You should see the index info page. - After you connect your properly programmed Arduino via a USB cable, you should be able to visit
http://ventilator-1.local/api/ventilator
and view JSON result of the latest ventilator stats. Refresh the page to query the Arduino again and get different values.
If you would like to run the web UI and hit a local simulation interface, make sure you have all the dependencies installed:
pivenv install
- Run the dev start script:
./start_dev.sh
- You should now be able to hit
localhost:5000/api/ventilator
and get the JSON response back.
You can also run it under the gunicorn script in dev mode:
FLASK_ENV=development ./start.sh
The start.sh
script supports two environmental variables, FLASK_PORT and FLASK_LISTEN, if you need
to customize the port and listen address of the app, like this:
Having a problem? Leave a message on the Slack Channel or an issue on the Github and we'll help you out.