Modifications

Sauter à la navigation Sauter à la recherche
Ligne 330 : Ligne 330 :  
## Send message
 
## Send message
 
## Turn of the LED
 
## Turn of the LED
 +
 +
{{underline|'''Reading sensor data:'''}}}
 +
 +
Reading the BMP280 sensor data relies on the {{fname|bme280.py} library previously detailled.
 +
 +
Reading the temperature from TMP36 relies on analog reading and some conversion calculation.
 +
 +
<syntaxhighlight lang="python"># read BMP280
 +
t,hpa,rh =  bmp.raw_values # Temp, press_hPa, humidity
 +
# Read tmp36 (analog)
 +
value = adc.read_u16()
 +
mv = 3300.0 * value / 65535
 +
temp = (mv-500)/10
 +
</syntaxhighlight>
 +
 +
Next the mainloop do prepare the string message (variable {{fname|msg}} by using the powerful Python string formatting feature.
 +
 +
This can be done with one single line. Notice the expression {{fname|time.time()-ctime}} calculating the elapse time (in second) since the mainloop started. 
 +
<syntaxhighlight lang="python"># message: iteration_count,time_sec,pressure_hpa,tmp36_temp,bmp280_temp (coma separated)
 +
msg = ":%i,%i,%6.2f,%5.2f,%5.2f;" % (counter,time.time()-ctime,hpa,temp,t)
 +
</syntaxhighlight>
 +
 +
led.on() # Led ON while sending data
 +
print( msg )
 +
# Send a packet without ACK - Send it, don't care if it is received or not
 +
rfm.send(bytes(msg , "utf-8") )
 +
led.off()
    
== Fault tolerant design ==
 
== Fault tolerant design ==
29 917

modifications

Menu de navigation