simpleaq-device

Firmware for SimpleAQ Devices

https://github.com/simpleairquality/simpleaq-device

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.3%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Firmware for SimpleAQ Devices

Basic Info
  • Host: GitHub
  • Owner: simpleairquality
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage: https://www.simpleaq.org
  • Size: 419 KB
Statistics
  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • Open Issues: 8
  • Releases: 0
Created about 4 years ago · Last pushed 7 months ago
Metadata Files
Readme License Citation

README.md

SimpleAQ-Device

Generic firmware for a Raspberry Pi based SimpleAQ device.

If you want a more detailed overview of the design, see our design document here.

I Just Want to Image My Device

Downloading an Image

First, you will have to select the image you want. You can find an image by selecting Actions in this repository, then selecting a successful Build Image run. Then, at the bottom of the page you will see Artifacts. Click the artifact to download it.

Writing the Image

You can unzip your image with bash unzip your_downloaded_image_file.zip

Once you have the contained .img file, you can write it to your MicroSD card. First, you will need to find the device corresponding to your MicroSD card. bash sudo fdisk -l | grep MicroSD -B 1 -A 5

Now you will have a list of all MicroSD cards attached to your system, whether mounted or not. The device name will look like /dev/sdx, where x is some letter. It is critical that you select the correct device name, or you will cause unwanted data loss on your host system.

Next, we must ensure that the device is not mounted. bash df -h | grep /dev/sdx where /dev/sdx/ is the device name for your MicroSD card will show whether your device is mounted.

For each mounted partition listed, unmount it with bash sudo umount /dev/sdxy where x is your device's letter that you found with fdisk and y may be a number.

It may be the case that your drive wasn't mounted at all. In any event, if your device is mounted, the following step will not work.

Now we will write your image with bash sudo dd bs=4M of=/dev/sdx if=your_image_file.img where x is your device's letter that you found with fdisk above. This step may take a while.

You should now be able to mount the ext4 Linux partition of your written image to inspect the written files.

Dev Quickstart

First Time

You can install needed dependencies in virtualenv with: bash virtualenv venv -p python3 source venv/bin/activate pip install -r requirements.txt

When you return to your work later, you can simply use: bash source venv/bin/activate

The Flask HostAP Configuration Tool

You can run this locally to test it out. bash cp example.env .env source .env flask run

Manually Configuring Your Device To Connect to Wifi

You can configure Wifi on your device without using ssh. First, insert the imaged MicroSD card into a standard card reader, then edit /etc/wpa_supplicant/wpa_supplicant-wlan0.conf in the root filesystem "rootfs". At the end of the file, add:

network={ ssid="Your Wireless Network ID Here!" psk="Your Wireless Network Password Here!" }

Note that if you are concerned about the security of storing your key in plain-text, you can run: bash wpa_passphrase YourWirelessNetworkID YourWirelessNetworkPassword and get a hash that you can use in the PSK field instead.

SSH Into your SimpleAQ Device For Testing

Our build process automatically creates Raspbian images appropriate for both a production environment and for development. In order to SSH into your SimpleAQ device, you will need to select a development image labeled INSECURE-DEBUG. These devices use the default username pi and the default password simpleaq and would be compromised immediately if placed on the public internet.

Note that since our transition to systemd-networkd based networking, link-local connections through your device's data/peripherals USB port are no longer supported. You have two options to connect to your device.

  1. If you have configured wifi in the step above, you may use your router to find the simpleaq device's IP address on your network, then connect with e.g., ssh pi@192.168.1.xxx.
  2. If your device's wifi is not configured, you can connect through the device's hostap network by connecting to wireless at SimpleAQ-xxxx. Then, connect with ssh pi@192.168.4.1.
  3. You can connect a keyboard to the device's data/peripheral port and a monitor to the device's HDMI pirt.

Our devices automatically switch between hostap and wlan modes based on whether wlan is working.
Therefore, if you have a correctly configured and working wlan connection, ssh into your hostap connection will not work. A service will periodically retry the wlan connection, but in doing so it will briefly take down the hostap.

Manually Configuring Your Device To Write Data to InfluxDB

Create a Temporary InfluxDB Instance For Testing

First, you'll need an instance of InfluxDB to write into! If you already have one, you can skip this step.

If you need a temporary instance for testing purposes, you can create one using: bash docker run -p 8086:8086 \ -e DOCKER_INFLUXDB_INIT_USERNAME=influx_dev_user \ -e DOCKER_INFLUXDB_INIT_PASSWORD=influx_not_secure \ -e DOCKER_INFLUXDB_INIT_ORG=my_org \ -e DOCKER_INFLUXDB_INIT_BUCKET=my_bucket \ -e DOCKER_INFLUXDB_INIT_MODE=setup \ -e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=not_secure_admin_token \ --network host \ influxdb:latest

The InfluxDB instance will now be running on port 8086 on the host machine. You will also need to find the IP address of the host machine so that the device can write into it. One way to find the local IP address is using ifconfig. It may be helpful to confirm that you can connect to http://HOST.IP.ADDRESS.HERE:8086 from a web browser on a machine on the same network as your device. If InfluxDB is set up properly and accessible, you will see a login page for InfluxDB.

Configuring Your Device

Using the HostAP network

When you boot your SimpleAQ image, it should start a HostAP network with a name like SimpleAQ-xxxx, and a default password of SimpleAQ. If you connect to the HostAP network with any device, navigate to http://192.168.4.1 or http://simpleaq.setup in a web browser. On this page, you will be able to change relevant settings. When the device is reporting data to a backend server expected, this HostAP network will not appear.

Manually

In order to connect the device to the backend, you will need a valid org, bucket and token. If you used the example above, you can use "my_org", "my_bucket" and "not_secure_admin_token".

You do not need ssh to configure your device. First, put your imaged MicroSD card into a card reader. Edit /etc/environment in the root filesystem "rootfs". If you're following the example above, the relevant fields would then be: influx_org=my_org influx_bucket=my_bucket influx_token=not_secure_admin_token influx_server=http://HOST.IP.ADDRESS.HERE:8086

If everything is configured correctly and the device has network connectivity, your device should be auto-configured on boot and automatically start sending readings to InfluxDB.

Troubleshooting

Boot

bootlogd is installed in our images. Therefore, if booting fails for any reason, you can insert the MicroSD card into a standard reader, then check the root file system "rootfs" for boot errors using

bash sed 's/\^\[/\o33/g;s/\[1G\[/\[27G\[/' var/log/boot

Service

If there is an issue with the service, you can ssh into the device using the instructions above, then run

bash sudo service simpleaq status

to explore the issue.

Owner

  • Name: SimpleAQ.org
  • Login: simpleairquality
  • Kind: organization

Simple, extensible, open-source air quality monitors

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Kalahar"
  given-names: "Benson"
- family-names: "Li-Sauerwine"
  given-names: "Benjamin"
title: "SimpleAQ-Device"
date-released: 2022-01-04
url: "https://github.com/simpleairquality/SimpleAQ-Device"

GitHub Events

Total
  • Issues event: 26
  • Issue comment event: 52
  • Push event: 75
  • Pull request event: 8
  • Create event: 13
Last Year
  • Issues event: 26
  • Issue comment event: 52
  • Push event: 75
  • Pull request event: 8
  • Create event: 13

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 20
  • Total pull requests: 6
  • Average time to close issues: 7 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 2.95
  • Average comments per pull request: 0.0
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 10
  • Pull requests: 4
  • Average time to close issues: 24 days
  • Average time to close pull requests: less than a minute
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 1.2
  • Average comments per pull request: 0.0
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • theGOTOguy (20)
Pull Request Authors
  • theGOTOguy (6)
Top Labels
Issue Labels
good first issue (2) enhancement (1) bug (1)
Pull Request Labels

Dependencies

.github/workflows/build.yml actions
  • actions/checkout v3 composite
  • actions/upload-artifact v1 composite
  • easimon/maximize-build-space master composite
custom_pigen/Dockerfile docker
  • ${BASE_IMAGE} latest build
requirements.txt pypi
  • RPi.GPIO *
  • absl-py *
  • adafruit-blinka *
  • adafruit-circuitpython-bme680 *
  • adafruit-circuitpython-gps *
  • adafruit-circuitpython-pm25 *
  • adafruit-python-shell *
  • flask ==2.1.3
  • influxdb_client *
  • psutil *
  • python-dotenv *
  • requests *
  • requests-toolbelt *
  • sensirion-i2c-sen5x *
  • setuptools *