def get(self):
     stationId = int(self.request.get("st"))
     status = int(memcache.get("tempStatus:"+str(stationId)))
     text = memcache.get("tempJSON:"+str(stationId))
     if text is None or status is None:
         station = WeatherStation.get_or_insert(str(stationId), id=stationId)
         text = station.getTempNow()
         status = station.getStatus()
     
     self.response.set_status(status)
     self.response.headers['Content-Type'] = 'text/plain'
     self.response.out.write(text)
Example #2
0
    def get(self):
        query = WeatherStation.all()
        query.filter('timesNotUpdated >=', 200)
        text = "{\"station\":["
        if query.count(1) > 0:
            for station in query:
                text += str(station.id) + ","
            text = text.replace(' ', '')[:-1]

        text += "]}"

        self.response.out.write(text)
 def get(self):
     query = WeatherStation.all()
     query.filter('timesNotUpdated >=', 200)
     text = "{\"station\":["
     if query.count(1)>0:
         for station in query:
             text += str(station.id) + ","
         text = text.replace(' ', '')[:-1]
     
     
     text += "]}"   
     
     self.response.out.write(text)
Example #4
0
    def get(self):
        stationId = int(self.request.get("st"))
        status = int(memcache.get("tempStatus:" + str(stationId)))
        text = memcache.get("tempJSON:" + str(stationId))
        if text is None or status is None:
            station = WeatherStation.get_or_insert(str(stationId),
                                                   id=stationId)
            text = station.getTempNow()
            status = station.getStatus()

        self.response.set_status(status)
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write(text)
import micropython
micropython.alloc_emergency_exception_buf(100)

from weatherstation import WeatherStation
ws = WeatherStation()
Example #6
0
from weatherstation import WeatherStation

MAC_ADDR = "A4:4A:38:A7:90:34"
GAUGE_T0 = Gauge('weather_temp_0', 'Temperature, Celcius')
GAUGE_T1 = Gauge('weather_temp_1', 'Temperature, Celcius')
GAUGE_H0 = Gauge('weather_humid_0', 'Humidity, percent')
GAUGE_H1 = Gauge('weather_humid_1', 'Humidity, percent')

# Start up the server to expose the metrics.
start_http_server(8000)

#
# Generate some requests.
while True:
    try:
        ws = WeatherStation(MAC_ADDR)
        if ws.monitorWeatherStation() is not None:
            ws.disconnect()
            data = []
            data.append(ws.getIndoorTemp())
            data.append(ws.getOutdoorTemp())
            data.append(ws.getHumidity0())
            data.append(ws.getHumidity1())
            for item in data:
                if item == None:
                    raise Exception(
                        'None value detected, skipping gague update ...')

            print("Setting gauges")
            GAUGE_T0.set(ws.getIndoorTemp())
            GAUGE_T1.set(ws.getOutdoorTemp())