项目目的:监测香菇大棚内温湿度变化,请求近3天的天气数据,并将数据反馈给用户,以增强用户对香菇生长的管理
项目思路:用树莓派ZERO+DHT22收集温湿度数据,并用NGINX搭建WEB服务,让用户使用手机浏览器了解温湿度信息.期间考虑过使用LED点阵显示,但考虑到LED点阵安装位置固定,不方便查看,手机随身携带比较方便,WEB服务无须安装其他应用.
项目硬件:树莓派ZERO,DHT22,乐光CPE,斐讯K3,小米3A,监控录像机,监控摄像头,网线若干
硬件连接:

项目软件:python,nginx,html,和风天气API
软件思路:使用python加载DHT库读取DHT22温湿度数据,使用python的openpyxl库将温湿度数据以天为单位保存成.xlsx文件.使用和风天气API,获取近3天的天气数据,最后将温湿度数据及天气数据保存到index.html.编写python自运行shell脚本,防止python意外停止,并将shell脚本设置开机自启.调整nginx配置文件,并加入开机自启.将树莓派ZERO设成静态IP地址,防止访问出现IP变动的问题.
项目代码:
greenhouse.sh

#!/bin/bash
while [ 1 ];dopython3 /home/pi/greenhouse/greenhousedetection.py
done

greenhousedetection.py

greenhousedetection.py
# -*- coding: utf-8 -*-
import Adafruit_DHT as dht
import datetime
import requests
import time
import os
from openpyxl import Workbook# 传感器型号
sensor = dht.DHT22
# 树莓派GPIO BCM引脚号
pin1 = 5
pin2 = 6
pin3 = 13
pin4 = 19# xlsx文件初始化
wb = Workbook() #创建文件对象
ws = wb.active #获取第一个sheet# xlsx文件标头
ws['A1'] = "时间"
ws['B1'] = "室外标准温度"
ws['C1'] = "室外标准湿度"
ws['D1'] = "大棚北部温度"
ws['E1'] = "大棚北部湿度"
ws['F1'] = "大棚中部温度"
ws['G1'] = "大棚中部湿度"
ws['H1'] = "大棚南部温度"
ws['I1'] = "大棚南部湿度"# xlsx偏移参数
i = 1# 标准时间获取
time1 = time.strftime("%Y%m%d",time.localtime())# 网页内容写入
def xieru():
f=open('/home/pi/greenhouse/html/index.html','w')
f.write('<!DOCTYPE html>'+'\n'
+'<html><head><meta charset="utf-8"><title></title></head>'+'\n'
+'<body>'+'\n'
+'<p style="text-align:center">'+'\n'
+'<font size="26" face="Time" color="orange">庆宝香菇大棚温湿度显示</font>'+'\n'
+'</p>'+'\n'+'<p><font size="26" face="Time">室外标准温湿度</font></p>'+'\n'
+'<p><font size="26" face="Time">' + '温度:' + str(wendu1) + '&nbsp;&nbsp;&nbsp;&nbsp;' + '湿度:' + str(shidu1) + '</font></p>' + '\n'
+'<p><font size="26" face="Time">大棚北部温湿度</font></p>' + '\n'
+'<p><font size="26" face="Time">' + '温度:' + str(wendu2) + '&nbsp;&nbsp;&nbsp;&nbsp;' + '湿度:' + str(shidu2) + '</font></p>' + '\n'
+'<p><font size="26" face="Time">大棚中部温湿度</font></p>' + '\n'
+'<p><font size="26" face="Time">' + '温度:' + str(wendu3) + '&nbsp;&nbsp;&nbsp;&nbsp;' + '湿度:' + str(shidu3) + '</font></p>' + '\n'
+'<p><font size="26" face="Time">大棚南部温湿度</font></p>' + '\n'
+'<p><font size="26" face="Time">' + '温度:' + str(wendu4) + '&nbsp;&nbsp;&nbsp;&nbsp;' + '湿度:' + str(shidu4) + '</font></p>' + '\n'+ '<p><font size="26" face="Time">今天天气' + str(date1) + '</font></p>' + '\n'
+ '<p><font size="8" face="Time">白天天气:' + str(cond_d1) + '&nbsp;&nbsp;' + '夜晚天气:' + str(
cond_n1) + '&nbsp;&nbsp;' + '最高温度:' + str(tmp_max1) + '&nbsp;&nbsp;' + '最低温度:' + str(
tmp_min1) + '&nbsp;&nbsp;' + '相对湿度:' + str(hum1) + '&nbsp;&nbsp;' + '能见度:' + str(
vis1) + '公里' + '&nbsp;&nbsp;' + '风向:' + str(wind_dir1) + '&nbsp;&nbsp;' + '风力:' + str(
wind_sc1) + '</font></p>' + '\n'+ '<p><font size="26" face="Time">明天天气' + str(date2) + '</font></p>' + '\n'
+ '<p><font size="8" face="Time">白天天气:' + str(cond_d2) + '&nbsp;&nbsp;' + '夜晚天气:' + str(
cond_n2) + '&nbsp;&nbsp;' + '最高温度:' + str(tmp_max2) + '&nbsp;&nbsp;' + '最低温度:' + str(
tmp_min2) + '&nbsp;&nbsp;' + '相对湿度:' + str(hum2) + '&nbsp;&nbsp;' + '能见度:' + str(
vis2) + '公里' + '&nbsp;&nbsp;' + '风向:' + str(wind_dir2) + '&nbsp;&nbsp;' + '风力:' + str(
wind_sc2) + '</font></p>' + '\n'+ '<p><font size="26" face="Time">后天天气' + str(date3) + '</font></p>' + '\n'
+ '<p><font size="8" face="Time">白天天气:' + str(cond_d3) + '&nbsp;&nbsp;' + '夜晚天气:' + str(
cond_n3) + '&nbsp;&nbsp;' + '最高温度:' + str(tmp_max3) + '&nbsp;&nbsp;' + '最低温度:' + str(
tmp_min3) + '&nbsp;&nbsp;' + '相对湿度:' + str(hum3) + '&nbsp;&nbsp;' + '能见度:' + str(
vis3) + '公里' + '&nbsp;&nbsp;' + '风向:' + str(wind_dir3) + '&nbsp;&nbsp;' + '风力:' + str(
wind_sc3) + '</font></p>' + '\n'+'<meta http-equiv="Refresh" content="90";/>'+'\n'
+'</body>'+'\n'
+'</html>')
f.close()# 主进程
while True:
i = i+1r = requests.get(
'https://free-api.heweather.net/s6/') #自己的key
r.encoding = 'utf-8'date1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['date']
cond_d1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['cond_txt_d']
cond_n1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['cond_txt_n']
tmp_max1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['tmp_max']
tmp_min1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['tmp_min']
hum1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['hum']
vis1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['vis']
wind_dir1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['wind_dir']
wind_sc1 = r.json()['HeWeather6'][0]['daily_forecast'][0]['wind_sc']
# print(cond_d1, cond_n1, tmp_max1, tmp_min1, hum1, vis1, wind_dir1, wind_sc1)date2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['date']
cond_d2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['cond_txt_d']
cond_n2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['cond_txt_n']
tmp_max2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['tmp_max']
tmp_min2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['tmp_min']
hum2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['hum']
vis2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['vis']
wind_dir2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['wind_dir']
wind_sc2 = r.json()['HeWeather6'][0]['daily_forecast'][1]['wind_sc']
# print(cond_d2, cond_n2, tmp_max2, tmp_min2, hum2, vis2, wind_dir2, wind_sc2)date3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['date']
cond_d3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['cond_txt_d']
cond_n3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['cond_txt_n']
tmp_max3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['tmp_max']
tmp_min3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['tmp_min']
hum3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['hum']
vis3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['vis']
wind_dir3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['wind_dir']
wind_sc3 = r.json()['HeWeather6'][0]['daily_forecast'][2]['wind_sc']
# print(cond_d3, cond_n3, tmp_max3, tmp_min3, hum3, vis3, wind_dir3, wind_sc3)time2 = time.strftime("%Y%m%d",time.localtime())
shidu1,wendu1 = dht.read_retry(sensor,pin1)
shidu2,wendu2 = dht.read_retry(sensor,pin2)
shidu3,wendu3 = dht.read_retry(sensor,pin3)
shidu4,wendu4 = dht.read_retry(sensor,pin4)if time2 > time1:
name = time2
time1 = time2
i = 2
# 写入一个自定义的时间格式
ws['A' + str(i)] = time.strftime("%Y%m%d%H%M", time.localtime())
#print("日期更新")
if shidu1 is not None and wendu1 is not None:
wendu1 = round(wendu1,3)
shidu1 = round(shidu1,3)
wendu2 = round(wendu2,3)
shidu2 = round(shidu2,3)
wendu3 = round(wendu3,3)
shidu3 = round(shidu3,3)
wendu4 = round(wendu4,3)
shidu4 = round(shidu4,3)
ws['B' + str(i)] = wendu1
ws['C' + str(i)] = shidu1
ws['D' + str(i)] = wendu2
ws['E' + str(i)] = shidu2
ws['F' + str(i)] = wendu3
ws['G' + str(i)] = shidu3
ws['H' + str(i)] = wendu4
ws['I' + str(i)] = shidu4
xieru()
else:
ws['J' + str(i)] = "传感器异常"
else:
name = time1ws['A' + str(i)] = time.strftime("%Y%m%d%H%M", time.localtime())
#print("日期更新")
if shidu1 is not None and wendu1 is not None:
wendu1 = round(wendu1, 3)
shidu1 = round(shidu1, 3)
wendu2 = round(wendu2, 3)
shidu2 = round(shidu2, 3)
wendu3 = round(wendu3, 3)
shidu3 = round(shidu3, 3)
wendu4 = round(wendu4, 3)
shidu4 = round(shidu4, 3)
ws['B' + str(i)] = wendu1
ws['C' + str(i)] = shidu1
ws['D' + str(i)] = wendu2
ws['E' + str(i)] = shidu2
ws['F' + str(i)] = wendu3
ws['G' + str(i)] = shidu3
ws['H' + str(i)] = wendu4
ws['I' + str(i)] = shidu4
xieru()
else:
ws['D' + str(i)] = "传感器异常"# Save the file
wb.save("/home/pi/greenhouse/datexlsx/"+str(name)+".xlsx")
time.sleep(90)

最终效果:

香菇大棚温湿度监测项目---及CPE架设监控安装等相关推荐

  1. 基于STM32大棚DHT11温湿度监测的Proteus仿真

    本设计仅供学习参考 基于STM32大棚DHT11温湿度监测的Proteus仿真 (代码+仿真+原理图+PCB) 原理图:Altium Designer 仿真图protues 8.9 程序编译器:kei ...

  2. 【单片机毕业设计】【mcuclub-202】大棚环境检测(土壤温湿度) | 大棚温湿度检测 | 农田灌溉系统 | 智能灌溉系统 | 智慧农业灌溉

    设计简介: 项目名:基于单片机的土壤温湿度控制系统 单片机:STC89C52 功能: 1.通过DS18B20温度传感器测量环境温度: 2.通过土壤湿度传感器测量土壤湿度: 3.通过按键可设置温湿度上下 ...

  3. 温湿度服务器系统软件,无线温湿度监测系统

    系统介绍 无线温湿度监测系统有无线温湿度采集器(监测终端).无线温湿度接收管理主机(接收器)和本地软件.云服务器软件.手机APP组成,系统利用各类传输技术(433M.WIFI.TCP/IP.GPRS) ...

  4. 基于STM32的多点温湿度无线传输检测及控制(基于单片机的蔬菜大棚温湿度智能控制系统)

    基于STM32的多点温湿度无线传输检测及控制(基于单片机的蔬菜大棚温湿度智能控制系统) 一前言(含研究目的及意义) 1.研究目的 2.研究意义 二.研究工作的主要内容 三.理论创新成果 四.实践创新成 ...

  5. java采集温湿度水浸_配电室水浸及温湿度监测系统可加强环境保障

    配电室水浸及温湿度监测系统有两大监测对象,一是管道.门窗等位置的漏水现象,二是室内各个位置的温度.湿度变化值,实现这两方面监测,能有效加强环境保障,降低漏水.高温.潮湿而引起的电力系统故障.设备损坏问 ...

  6. 室内温湿度监测系统解决方案

    应用背景 我们正处于一个机械化.信息化的时代,各式各样的机械.仪器都需要处在一个合适的环境中才能良好运行,一些实验与生产性工作对环境也有特殊需求,对温湿度等指标进行监管和控制,才能保证生产生活的良好秩 ...

  7. 数据中心机房温湿度监测

    现在,数据中心运营商都知道监测数据中心温度的重要性.数据中心温度变化,就可能会为数据中心的冷却系统和敏感设备带来不必要的压力,特别是在温度较高或在炎热的夏季. 虽然许多数据中心运营商积极监测数据中心的 ...

  8. 基于单片机的温湿度监测报警

    基于单片机的温湿度监测系统(独立按键.LCD1602.DHT11) 0.关注微信公众号(风吹摇铃 奔赴星海)下载全套资料,全套资料中包括如下内容:(需要PCB和焊接实物请阅读(使用前必读)文件下的内容 ...

  9. 【数智化案例展】杭州市某区统计局——AIxRPA数字员工技术赋能新经济监测项目...

    实在智能案例 本项目案例由实在智能投递并参与"数据猿行业盘点季大型主题策划活动--<2022中国企业数智化转型升级创新服务企业>榜单/奖项"评选. 数据智能产业创新服务 ...

最新文章

  1. iOS-消除CocoaPods内容警告
  2. Leetcode: Reverse Linked List II
  3. kernel 3.10内核源码分析--中断--中断和异常返回流程
  4. 如何在程序中添加iAd广告
  5. 一款已上市MMO手游地图同步方案总结
  6. 效果图底图 线框图_5分钟的线框图教程
  7. 对话阿里 CTO 程立:未来数字世界的根基是开源和云
  8. 新浪邮箱开通imap服务器,新浪邮箱申请
  9. 中软防水坝 怎么卸载_卸载中软防水墙软件 | 学步园
  10. 中国女篮姐妹花杨舒予、杨力维成为护肤品牌佰草集太极首组代言人
  11. Codeforces Round #469 (Div. 1 A-E)
  12. 非 Java、C、Python,我使用的第一门计算机语言是它!
  13. 最近用了一个免费的服务器
  14. vvic/搜款网API接口(item_get-根据ID取商品详情)
  15. Android Studio 不显示LogCat 日志 的几种解决办法
  16. 常见职位的英文简称_各种职位的英文简称都是什么?
  17. PDF文件不能编辑的原因
  18. 旋转目标检测:Exploring Complementary Strengths of Ivariant and Equivariant Representations for FSL(CVPR21)
  19. 哪个公司的外贸邮箱好用?
  20. 计算机模拟细胞 斯坦福,人造突触问世,计算机模拟人脑不是梦

热门文章

  1. 使用time命令测试程序
  2. 为何鲁大师为变成一个流氓软件?
  3. MOOC网深度学习应用开发4——猫狗大战
  4. 疫情期间自我修炼, 搞一搞老游戏资源解包
  5. Fiora一款二次元的Web多人在线网络聊天系统
  6. beats x白灯一直闪_我告诉你beatsx白灯不停闪烁
  7. 21年研究生入学考试(哈尔滨工程大学)复试准备——《网络安全》选择题错题总结
  8. 周傲英、熊辉、李飞飞助阵!期待与你的大数据之约(附大会终版日程)
  9. 我对于C女士的初次看法
  10. 2021年中国冷库行业现状及趋势分析:资源主要在沿海地区[图]