Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement cubieboard PM2.5 Monitoring Mini Program

Shulou Source: shulou.com Published: 2022-06-01 04:14:18 09月30日 Update

This article mainly explains "how to achieve cubieboard PM2.5 monitoring Mini Program". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to achieve cubieboard PM2.5 monitoring Mini Program.

If the led light is green, the air quality is good (excellent and good)

If the led light is blue, the air is slightly polluted

If the led light shows orange, it means that the air pollution is serious (moderate pollution and above)

If the led light is white, air pollution data is currently not available

The data is updated every half hour.

This program is a shell script program:

#! / bin/bash

# api key: http://www.pm25.in/api_doc

Api_key= "5j1znBVAsnSf5xQyNQyq"

City= "shanghai"

Lighten_led () {

Ls / sys/class/leds/*/brightness | xargs-I-N1 echo "echo 0 > {}" | sh

Echo 1 > / sys/class/leds/$1*/brightness

}

Get_quality () {

Local api= "http://www.pm25.in/api/querys/pm2_5.json?city=$1&stations=no&token=$api_key"

Wget-- quiet-- no-check-certificate-- output-document=- $api | sed's quality.\ +, "quality": "\ ([^"]\ +\) ".\ + /\ 1bind'

}

Update_quality () {

Local quality=$ (get_quality $city)

If ["$quality" = = "excellent"] | | ["$quality" = = "good"]; then

Lighten_led green

Elif ["$quality" = = 'mild pollution']; then

Lighten_led blue

Elif ["$quality" = = 'moderate pollution'] | | ["$quality" = = 'severe pollution'] | | ["$quality" = = 'serious pollution']; then

Lighten_led orange

Else

Lighten_led white

Fi

}

While true; do

Update_quality

Sleep 1800

Done

First of all, you need to configure this script. Api_key needs to apply, and the default api_key may not work well.

Then modify the city. The value here is shanghai, which needs to be changed to the city you need to monitor.

After the configuration is complete, save this script and execute it at boot time (add / etc/rc.local)

Thank you for your reading, the above is the content of "how to achieve cubieboard PM2.5 monitoring Mini Program". After the study of this article, I believe you have a deeper understanding of how to achieve cubieboard PM2.5 monitoring Mini Program, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Pollution programs monitoring air scripts learning content data air pollution mild configuration not bad city hour that is ideas situations articles time more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi Huawei Shulou Tech Info Shulou Information