回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页
best-icon

新物联网挑战二+黄河流域低碳生态环境监测 简单

头像 绘编程吴老师 2023.06.21 638 8

                                                         黄河流域低碳生态环境监测

 

 

         根据中共中央 国务院印发《黄河流域生态保护和高质量发展规划纲要》重要指示

         黄河是中华民族的母亲河,孕育了古老而伟大的中华文明,保护黄河是事关中华民族伟大复兴的千秋大计。

        早在上古时期,黄河流域就是华夏先民繁衍生息的重要家园。中华文明上下五千年,在长达3000多年的时间里,黄河流域一直是全国政治、经济和文化中心,以黄河流域为代表的我国古代发展水平长期领先于世界。九曲黄河奔流入海,以百折不挠的磅礴气势塑造了中华民族自强不息的伟大品格,成为民族精神的重要象征。

下载.jpg

 

        生态类型多样。黄河流域横跨青藏高原、内蒙古高原、黄土高原、华北平原等四大地貌单元和我国地势三大台阶,拥有黄河天然生态廊道和三江源、祁连山、若尔盖等多个重要生态功能区域。

        然而随着时代经济的高速发展,重工业、交通运输、环境破坏等众多的因素碳排放超标日益严重。对人们的生活、工作以及后代的健康提出了严重的挑战;因此生态功能区重点保护好生态环境,不盲目追求经济总量;调整区域产业布局,把经济活动限定在资源环境可承受范围内;发展新兴产业,推动清洁生产,坚定走绿色、可持续的高质量发展之路。

作品图片:

微信图片_20230621140000.jpg

 

微信图片_20230621135937.jpg

 

 

微信图片_20230621135948.jpg

 

可视化显示图片:

1687309812028.jpg

数据监测:

1687309715928.jpg
1687309730761.jpg

 

 

 

步骤1 测试软件和硬件的兼容性,并进行安装;调试

步骤2 制作模型:https://www.bilibili.com/video/BV1Nz4y1H7LT/?vd_source=ddf4b251ef46e80ce40f30accaa33b52

步骤3 运行并记录数据,录制视频等;

步骤4 根据资料拟定要实现的功能,并通过Mind+软件进行编程,调整程序的准确性;

步骤5 设定低碳主题,查阅资料定稿需要监测的数据和日常实用性的功能;

材料清单

  • 行空板 X1 链接
  • Gravity: SCI采集模块 X1 链接
  • Gravity: ENS160 空气质量传感器 X1 链接
  • Gravity: 模拟声级计/分贝计/噪音计 X1 链接
  • Gravity: I2C 氧气传感器(0-25%Vol) X1 链接
  • Gravity: 电容式土壤湿度传感器 X1 链接
  • Gravity: 模拟TDS传感器 X1 链接
  • Gravity: 18B20 防水温度传感器套件 X1 链接
  • 二哈识图(HuskyLens) X1 链接
  • WS2812 RGB 全彩灯带(7灯珠) X1 链接
  • 直流水泵(DC2.1接口) X1 链接
  • SHT31-F数字温湿度传感器 X1 链接
  • Trig超声波测距传感器 X1 链接
代码
#  -*- coding: UTF-8 -*-

# MindPlus
# Python
import base64
from io import BytesIO
from PIL import Image
from pinpong.libs.dfrobot_huskylens import Huskylens
from pinpong.libs.dfrobot_ens160 import Ens160
from pinpong.libs.dfrobot_tds import TDS
from pinpong.extension.unihiker import *
from pinpong.board import SR04_URM10
from pinpong.board import Board,Pin
from pinpong.board import NeoPixel
from pinpong.board import DS18B20
from dfrobot_rp2040_sci import *
from pinpong.board import Board
from pinpong.board import Pin
from unihiker import GUI
import siot
import time
import cv2

# 自定义函数
def HuanJingGuang():
    HuanJingGuangXian = light.read()
    siot.publish_save(topic="siot/光线强度", data=HuanJingGuangXian)
    if (HuanJingGuangXian < 50):
        np1.range_color(2,7,0xFFFFFF)
    else:
        np1.clear()
def ShuiWenDu():
    ShuiWenDu = ds1.temp_c()
    siot.publish_save(topic="siot/水温", data=ShuiWenDu)
def ShuiZhiShuJu():
    TDSShuZhi = tds1.get_value()
    siot.publish_save(topic="siot/水质等级", data=TDSShuZhi)
def ShuZiWenShiDu():
    KongQiShuZiWenDu = SCI1.get_value1(SCI1.eALL,"Temp_Air")
    KongQiShuZiShiDu = SCI1.get_value1(SCI1.eALL,"Humi_Air")
    siot.publish_save(topic="siot/空气温湿度", data=(str(KongQiShuZiWenDu) + str((str(",") + str(KongQiShuZiShiDu)))))
def FenBeiZhi():
    fFenBeiZhi = SCI1.get_value1(SCI1.eALL,"Analog")
    siot.publish_save(topic="siot/分贝值", data=fFenBeiZhi)
def TuRangShiDu():
    TuRangShiDu = p_p2_analog.read_analog()
    siot.publish_save(topic="siot/土壤制度值", data=TuRangShiDu)
    if (TuRangShiDu > 3000):
        buzzer.play(buzzer.ENTERTAINER,buzzer.Once)
def GuoShiChengShu():
    p_huskylens.command_request()
    if p_huskylens.is_learned(1):
        if p_huskylens.is_appear_direct("blocks"):
            siot.publish_save(topic="siot/农作物成熟度", data=(str(p_huskylens.read_count("blocks", id=1)) + str((str(",") + str((str(p_huskylens.read_count("blocks", id=2)) + str((str(",") + str(p_huskylens.read_count("blocks", id=3))))))))))
def YangQiZhi():
    YangQiZhi = SCI1.get_value1(SCI1.eALL,"O2")
    siot.publish_save(topic="siot/氧气数值", data=YangQiZhi)
def KongQiZhiLiang():
    co2 = p_ens160.get_eco2()
    TVOC = p_ens160.get_tvoc()
    AQI = p_ens160.get_aqi()
    siot.publish_save(topic="siot/空气质量", data=(str((str(co2) + str((str(",") + str(TVOC))))) + str(AQI)))
def ChaoShengBoZhi():
    ChaoShengBoZhi = sonar1.distance_cm()
    siot.publish_save(topic="siot/防溺水", data=ChaoShengBoZhi)
    if (ChaoShengBoZhi < 10):
        buzzer.play(buzzer.WEDDING,buzzer.Once)
def SheXiangTou():
    while True:
        if vd.grab():
            ret, grab = vd.read()
            siot.publish_save(topic="siot/摄像头", data=base642base64(grab))
        else:
            print("没有下一帧")

# 事件回调函数
def on_message_callback(client, userdata, msg):
    if (msg.payload.decode() == (str("on"))):
        p_p25_out=Pin(Pin.P25, Pin.OUT)
        p_p25_out.write_digital(1)
    if (msg.payload.decode() == (str("off"))):
        p_p25_out=Pin(Pin.P25, Pin.OUT)
        p_p25_out.write_digital(0)


Board().begin()
u_gui=GUI()
siot.init(client_id="8945261728000184",server="10.1.2.3",port=1883,user="siot",password="dfrobot")
siot.connect()
siot.loop()
p_p2_analog=Pin(Pin.P2, Pin.ANALOG)
siot.set_callback(on_message_callback)

def frame2base64(frame):
    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    img = Image.fromarray(frame) #将每一帧转为Image
    output_buffer = BytesIO() #创建一个BytesIO
    img.save(output_buffer, format='JPEG') #写入output_buffer
    byte_data = output_buffer.getvalue() #在内存中读取
    base64_data = base64.b64encode(byte_data) #转为BASE64
    return base64_data #转码成功 返回base64编码

def base642base64(frame):
    data=str('data:image/png;base64,')
    base64data = str(frame2base64(frame))
    framedata = base64data[2:(len(base64data)-1)]
    base642base64_data = data + str(framedata)
    return base642base64_data
vd = cv2.VideoCapture()
vd.open(-1)
while not (vd.isOpened()):
    print("摄像头初始化中....")
print("摄像头初始化完成")
p_huskylens = Huskylens()
p_huskylens.command_request_algorthim("ALGORITHM_COLOR_RECOGNITION")
np1 = NeoPixel(Pin((Pin.P13)),7)
np1.brightness(148)
SCI1 = DFRobot_RP2040_SCI_IIC(addr=0x21)
while SCI1.begin() != 0:
    print("Initialization Sensor Universal Adapter Board failed.")
    time.sleep(1)
print("Initialization Sensor Universal Adapter Board done.")
buzzer.redirect(Pin.P0)
ds1 = DS18B20(Pin((Pin.P1)))
p_ens160 = Ens160(0x52)
p_ens160.set_pwr_mode(p_ens160.ENS160_STANDARD_MODE)
tds1 = TDS(Pin((Pin.P22)))
sonar1 = SR04_URM10(Pin((Pin.P8)),Pin((Pin.P9)))
u_gui.draw_image(image="下载.jpg",x=0,y=0)
u_gui.draw_text(text="黄河流域生态环境",x=0,y=0,font_size=20, color="#FF0000")
siot.getsubscribe(topic="siot/光线强度")
siot.getsubscribe(topic="siot/空气温湿度")
siot.getsubscribe(topic="siot/水温")
siot.getsubscribe(topic="siot/土壤制度值")
siot.getsubscribe(topic="siot/空气质量")
siot.getsubscribe(topic="siot/水质等级")
siot.getsubscribe(topic="siot/分贝值")
siot.getsubscribe(topic="siot/进出城人数")
siot.getsubscribe(topic="siot/氧气数值")
siot.getsubscribe(topic="siot/摄像头")
siot.getsubscribe(topic="siot/开关")
siot.getsubscribe(topic="siot/防溺水")
siot.getsubscribe(topic="siot/农作物成熟度")
SheXiangTou()

while True:
    GuoShiChengShu()
    YangQiZhi()
    ChaoShengBoZhi()
    FenBeiZhi()
    HuanJingGuang()
    ShuZiWenShiDu()
    KongQiZhiLiang()
    TuRangShiDu()
    ShuiWenDu()
    ShuiZhiShuJu()
    time.sleep(0.2)

评论

user-avatar
  • 花生编程

    花生编程2023.08.11

    不错不错

    0
    • 花生编程

      花生编程2023.08.11

      厉害厉害

      0
      • 三春牛-创客

        三春牛-创客2023.08.08

        赞赞赞赞

        0
        • 三春牛-创客

          三春牛-创客2023.08.08

          厉害厉害

          0
          • 腿毛利小五郎

            腿毛利小五郎2023.07.01

            666

            0
            • hacker_

              hacker_2023.06.21

              666

              1
              • 绘编程吴老师

                绘编程吴老师2023.06.27

                666

            • 匿名

              匿名

              该评论已删除

              1
              • 绘编程吴老师

                绘编程吴老师2023.06.27

                ok