For the software side, I wanted to: log the data with the other Pis via the RadPi system, and publish the data to Weather Underground.
Pour le logiciel, je voulais : enregistrer les données avec les autres Pi via le systÚme RadPi, et publier les données sur Weather Underground.
Python: reading sensor data
Python : lecture des capteurs
from sense_hat import SenseHat
sense = SenseHat()
# Température du CPU
with open('/sys/class/thermal/thermal_zone0/temp') as f:
tempC = float(f.read()) / 1000
# Capteurs du Sense Hat
t1 = sense.get_temperature()
t2 = sense.get_temperature_from_pressure()
t3 = sense.get_temperature_from_humidity()
p = sense.get_pressure()
h = sense.get_humidity()
# Correction de la chaleur du CPU
avgtemp = (t1 + t2 + t3) / 3
calctemp = avgtemp - ((tempC - avgtemp) / 10)
calchum = h + 4
calcp = p + 6
# Sauvegarder pour le serveur RadPi
with open('/var/www/html/temp.html', 'w') as f:
f.write(f'{calctemp}!{calchum}!{calcp}')
# Afficher sur l'écran LED du Sense Hat
sense.show_message(f'T={calctemp:.1f} P={calcp:.0f} H={calchum:.0f}', scroll_speed=0.05)
The Sense Hat has a known flaw: sensors are close to the Pi CPU and are affected by its heat. The adjustments above compensate based on readings from a nearby reference station.
Le Sense Hat a un défaut connu : les capteurs sont proches du CPU du Pi et sont affectés par sa chaleur. Les ajustements ci-dessus compensent en se basant sur une station de référence voisine.
PHP: publishing to Weather Underground
PHP : publication vers Weather Underground
<?php
$data = file_get_contents('/var/www/html/temp.html');
$a = explode('!', $data);
$dew = $a[0] - ((100 - $a[1]) / 5); // point de rosée approximatif
$url = 'http://weatherstation.wunderground.com/weatherstation/updateweatherstation.php'
. '?action=updateraw&ID=VOTREIDENTIFIANT&PASSWORD=VOTREMOTDEPASSE'
. '&dateutc=' . urlencode(gmdate('Y-M-d H:i:s'))
. '&humidity=' . $a[1]
. '&tempf=' . ($a[0] * 1.8 + 32)
. '&baromin=' . ($a[2] / 1000 * 29.5)
. '&dewptf=' . ($dew * 1.8 + 32);
echo file_get_contents($url);
?>