【发布时间】:2021-06-09 02:38:12
【问题描述】:
提前感谢您阅读并花时间与我一起解决此问题!
让我先从重要的东西开始:
目标设备:
- 树莓派 4B
- 电子沙龙接力帽
开发环境:
- macOS 卡塔利娜
- PyCharm
- Python 2.7.10
在我的家里,我有一个为我家供水的泉水。我想出的解决办法是为了防止由于恶劣的阴雨天气导致地面土壤松动而导致脏水进入我的水箱,方法是关闭阀门并等待大约 12 小时让水重新清理干净。然后我打开阀门,清水流入我的蓄水池,为我的家提供水,这个解决方案非常有效。
我最近得出了一个结论,即我想用一个常开螺线管使这个过程自动化。我购买了 Raspberry Pi、Relay Hat 和 Ambient Weather 气象站。
我希望用 Python 2.7.10 做的是在分配的时间后检查同一个变量。在此示例中,我正在检查相对于自身的相对大气压力,并且我希望在该变量中寻找显着的负变化。
即“变量 A 有什么?好的,现在等待 3 秒。A 现在有什么?它改变了多少?”
这是我到目前为止所遇到的问题,我该如何改进?谢谢。
起初我在想也许我应该用数据绘制图表并比较两个绘图点之间的差异,但我不确定如何使用 Matplotlib。
# This is the executing script for the Smart Valve.
# This project is powered by raspberry pi and 120 angry pixies.
import time,imp
from ambient_api.ambientapi import AmbientAPI
# This code will pull the data from the weather computer
api = AmbientAPI()
devices = api.get_devices()
device = devices[0]
time.sleep(1) #pause for a second to avoid API limits
# The code below is meant for telling the python interpreter to behave normally whether or not it's in a RPi env or a
# developer env
try:
imp.find_module('RPi.GPIO')
import RPi.GPIO as GPIO
except ImportError:
"""
import FakeRPi.GPIO as GPIO
OR
import FakeRPi.RPiO as RPiO
"""
import FakeRPi.GPIO as GPIO
# this code compares the rate of change for the barometric pressure over time and checks if rate is negative
a1 = None
a2 = None
while True:
weatherData = device.get_data()
data = dict(weatherData[0])
pressure = data[u'baromrelin']
wind = data[u'windspeedmph']
rain = data[u'hourlyrainin']
a1 = pressure
time.sleep(30)
a2 = pressure
print("A1 is equal to " + str(a1))
print("A2 is equal to " + str(a2))
if a1 > a2:
print("we should close the valve, it'll rain soon")
continue
elif a1 == a2:
print("It's all hunky dory up here!")
break
【问题讨论】:
标签: python matplotlib raspberry-pi pycharm