RPi0只是在几个星期后挂起

2024-05-20 22:03:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个RPi0设置在我的爬行空间来测量和记录温度/湿度随时间的变化。简单地说,Python程序每隔几分钟使用Chron运行一次,收集温度/湿度并使用一个简单的HTTP页面将它们发送到基于云的数据库(“one and one”),该页面运行一个简单的PHP程序,向MySQL数据库表添加一行。没有反馈(至少没有故意的…)db会像预期的那样更新几个星期(足够长的时间让我陷入一种错误的安全感…),然后它就停止了。无法使用SSH访问RPi0

我拔下它,把它带到我的办公室,插上电源,它又开始工作了,没问题…没有磁盘满的症状(总使用率19%),虚假的python消息出现了,但它们只是谈论类型转换警告

冲洗并重复

忽略本地数据库的插入设置。我已经注释掉了实际的命令执行,因为我不再使用本地数据库

#!/usr/bin/python
import sys
import Adafruit_DHT
import MySQLdb
import time
import urllib2

from Adafruit_BME280 import *

# BMP working, DHT not so much

sensor = BME280(address=0x76,t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8)

# conn=MySQLdb.connect(host="192.168.2.204",user="jim",passwd="xxxx",db="EnviroLogger")
# c=conn.cursor()
humidity=0
temperaturec=0
# humidity, temperaturec = Adafruit_DHT.read_retry(11, 4)
temperaturef=((temperaturec*9.000)/5.000)+32.000

datatime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())

dhtvalues="(null,'DHT-8200-Crawl',"+str(temperaturef)+","+str(humidity)+",null,'"+datatime+"')"


time.sleep(1)
BMPtemperaturef = ((sensor.read_temperature()*9.000)/5.000)+32.000
hectopascals = sensor.read_pressure()/100.0000
BMPhumidity = sensor.read_humidity()

bmpvalues="(null,'BMP-8200-Crawl',"+str(BMPtemperaturef)+","+str(BMPhumidity)+","+str(hectopascals)+",'"+datatime+"');"

finalSQLstring="INSERT INTO ResDataLog(ID,Location,Temperature, Humidity, Pressure, RecDate) VALUES " + dhtvalues +","+bmpvalues
# c.execute (finalSQLstring)
# conn.commit()

#Get Weather info from DarkSky

from forecastiopy import *

MyLatLong=[34.985928,-80.767389]
DarkSkyKey='587336fab8f4f5e8766aee23ca5cfee79f390943221acedddwerreffafde'

fio=ForecastIO.ForecastIO(DarkSkyKey, latitude=MyLatLong[0], longitude=MyLatLong[1])
current = FIOCurrently.FIOCurrently(fio)
ambienttemp=current.temperature
ambienthumidity=current.humidity
ambientpressure=current.pressure

url="http://telemetry.mywebhost.com/add_data.php?loc="+"BMP-8200-Crawl"+"&temp="+str(BMPtemperaturef)+"&hum="+str(BMPhumidity)+"&pr="+str(hectopascals)+"&atemp="+str(ambienttemp)+"&ahum="+str(ambienthumidity)+"&apress="+str(ambientpressure)
urllib2.urlopen(url)

我怎样才能在它死之前捕捉到这里发生的事情并把它保存在某个地方呢


Tags: fromimportadafruit数据库readtimemodecurrent