Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement cubieboard PM2.5 Monitoring Mini Program

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report