python - Take temperature readings every 10 minutes from a Raspberry Pi -
i have raspberry pi temperature sensors. wrote python code measure temperature , sends database. want send measurements every 10 minutes.
my code currently:
#!/usr/bin/python import adafruit_charlcd lcd import math import os import rpi.gpio gpio import spidev import string import time import urllib2,urllib3,urllib # .... timestamp = int(time.time()) print timestamp # <temperature measurement here>
do have this?
if ($timestamp < (time() - 600)): # if test ok, send measures. url = 'database address' user_agent = 'mozilla/4.0 (compatible; msie 5.5; windows nt)' param = {'timestamp' : timestamp, 'te1' : temperatures[1], te2 te3...
how can make test procedure?
you can wait loop follows:
import time ... timestamp = int(time.time()) while true: time.sleep(10) # sleep 10 sec if int(time.time()-timestamp) > 10*60*1000: savetodatabase() timestamp = int(time.time())
the infinite loop checks every 10 seconds if 10 minutes (10*60*1000 milliseconds) exceeded.
Comments
Post a Comment