def main():
    conditions = get_conditions()
    astronomy = get_astronomy()
    streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
    streamer.log(":house: Location",conditions['current_observation']['display_location']['full'])
    while True:
        # -------------- Read GrovePi Sensors --------------
        try:
            [temp_c,hum] = grovepi.dht(DHT_SENSOR_PIN,DHT_SENSOR_TYPE)
            if isFloat(temp_c):
                if (CONVERT_TO_FAHRENHEIT):
                    temp_f = temp_c * 9.0 / 5.0 + 32.0
                    # print("Temperature(F) = ", temp_f)
                    streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
                else:
                    # print("Temperature(C) = ", temp_c)
                    streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)", temp_c)        
            if ((isFloat(hum)) and (hum >= 0)):
        		# print("Humidity(%) = ", hum)
            	streamer.log(":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)", hum)

        except IOError:
            print ("Error")

        # -------------- Wunderground --------------
        conditions = get_conditions()
        astronomy = get_astronomy()
        if ((conditions != False) and (astronomy != False)):
            humidity_pct = conditions['current_observation']['relative_humidity']
            humidity = humidity_pct.replace("%","")

            # Stream valid conditions to Initial State
            streamer.log(":cloud: " + CITY + " Weather Conditions",weather_status_icon(conditions, astronomy))
            streamer.log(":crescent_moon: Moon Phase",moon_icon(astronomy['moon_phase']['phaseofMoon']))
            streamer.log(":dash: " + CITY + " Wind Direction",wind_dir_icon(conditions, astronomy))
            if isFloat(conditions['current_observation']['temp_f']): 
                streamer.log(CITY + " Temperature(F)",conditions['current_observation']['temp_f'])
            if isFloat(conditions['current_observation']['dewpoint_f']):
                streamer.log(CITY + " Dewpoint(F)",conditions['current_observation']['dewpoint_f'])
            if isFloat(conditions['current_observation']['wind_mph']):
                streamer.log(":dash: " + CITY + " Wind Speed(MPH)",conditions['current_observation']['wind_mph'])
            if isFloat(conditions['current_observation']['wind_gust_mph']):
                streamer.log(":dash: " + CITY + " Wind Gust(MPH)",conditions['current_observation']['wind_gust_mph'])
            if isFloat(humidity):
                streamer.log(":droplet: " + CITY + " Humidity(%)",humidity)
            if isFloat(conditions['current_observation']['pressure_in']):
                streamer.log(CITY + " Pressure(IN)",conditions['current_observation']['pressure_in'])
            if isFloat(conditions['current_observation']['precip_1hr_in']):
                streamer.log(":umbrella: " + CITY + " Precip 1 Hour(IN)",conditions['current_observation']['precip_1hr_in'])
            if isFloat(conditions['current_observation']['precip_today_in']):
                streamer.log(":umbrella: " + CITY + " Precip Today(IN)",conditions['current_observation']['precip_today_in'])
            if isFloat(conditions['current_observation']['solarradiation']):
                streamer.log(":sunny: " + CITY + " Solar Radiation (watt/m^2)",conditions['current_observation']['solarradiation'])
            if isFloat(conditions['current_observation']['UV']):
                streamer.log(":sunny: " + CITY + " UV Index:",conditions['current_observation']['UV'])
            streamer.flush()
        time.sleep(60*MINUTES_BETWEEN_READS)
Beispiel #2
0
 def analog_read(self, mode="analog"):
     try:
         if mode is 'analog':
             data = grovepi.analogRead(self.pin)
             if data > 1023:
                 return None
             return data
         elif mode == 'dht':
             temp, hum = grovepi.dht(self.pin, 0)
             return temp, hum
         elif mode == 'ultrasonic':
             distance = grovepi.ultrasonicRead(self.pin)
             return distance
     except IOError:
         return None
def publish_dht11():
    try:
        [temp,humidity] = grovepi.dht(GROVE_DHT_SENSOR_PORT, GROVE_DHT_SENSOR_TYPE)
        #logger.info(os.path.basename(__file__) + " --- temp " + str(temp) + " - humi " + str(float(humidity) * 10))
        logger.info(os.path.basename(__file__) + " --- temp " + str(temp) + " - humi " + str(float(humidity)*10))

	# Skip to the next reading if a valid measurement couldn't be taken.
        #This might happen if the CPU is under a lot of load and the sensor
        # can't be reliably read (timing is critical to read the sensor).
        if humidity is None or temp is None:
            raise ValueError('Sensor reading failed')

        # occasional number are > 100 which is not viable
        #if humidity < 20: # and humidity > 0:
        #    message_queue.put(MqttMessage(MQTT_TOPIC_HUMI, float(humidity)*10.0))
        message_queue.put(MqttMessage(MQTT_TOPIC_HUMI, float(humidity)*10))

	message_queue.put(MqttMessage(MQTT_TOPIC_TEMP, float(temp)))

    except ValueError as err:
        # we just don't publish bad readings
        #print(err.args)
        logger.warning(os.path.basename(__file__) + " - publish_dht11: %s " % err.args)
Beispiel #4
0
import time
from datetime import datetime
from grovepi import grovepi

while True:
    # define pin number for sensors here
    dht = 4
    light_sensor = 1
    sound_sensor = 0
    moist_sensor = 2

    temp = grovepi.dht(dht, 0)[0]
    humidity = grovepi.dht(dht, 0)[1]
    lightlvl = grovepi.analogRead(light_sensor)
    soundlvl = grovepi.analogRead(sound_sensor)
    moistlvl = grovepi.analogRead(moist_sensor)

    # timestamp is UTC, and UTC time shall be used across
    myData = {
        "d": {
            'temp': temp,
            'humidity': humidity,
            'lightlvl': lightlvl,
            'soundlvl': soundlvl,
            'moistlvl': moistlvl
        },
        "ts": datetime.utcnow().isoformat() + "Z"
    }
    print(myData)
    time.sleep(1)
def main():
    conditions = get_conditions()
    astronomy = get_astronomy()
    streamer = Streamer(bucket_name=BUCKET_NAME,
                        bucket_key=BUCKET_KEY,
                        access_key=ACCESS_KEY)
    streamer.log(":house: Location",
                 conditions['current_observation']['display_location']['full'])
    while True:
        # -------------- Read GrovePi Sensors --------------
        try:
            [temp_c, hum] = grovepi.dht(DHT_SENSOR_PIN, DHT_SENSOR_TYPE)
            if isFloat(temp_c):
                if (CONVERT_TO_FAHRENHEIT):
                    temp_f = temp_c * 9.0 / 5.0 + 32.0
                    # print("Temperature(F) = ", temp_f)
                    streamer.log(
                        ":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)",
                        temp_f)
                else:
                    # print("Temperature(C) = ", temp_c)
                    streamer.log(
                        ":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)",
                        temp_c)
            if ((isFloat(hum)) and (hum >= 0)):
                # print("Humidity(%) = ", hum)
                streamer.log(
                    ":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)",
                    hum)

        except IOError:
            print("Error")

        # -------------- Wunderground --------------
        conditions = get_conditions()
        astronomy = get_astronomy()
        if ((conditions != False) and (astronomy != False)):
            humidity_pct = conditions['current_observation'][
                'relative_humidity']
            humidity = humidity_pct.replace("%", "")

            # Stream valid conditions to Initial State
            streamer.log(":cloud: " + CITY + " Weather Conditions",
                         weather_status_icon(conditions, astronomy))
            streamer.log(":crescent_moon: Moon Phase",
                         moon_icon(astronomy['moon_phase']['phaseofMoon']))
            streamer.log(":dash: " + CITY + " Wind Direction",
                         wind_dir_icon(conditions, astronomy))
            if isFloat(conditions['current_observation']['temp_f']):
                streamer.log(CITY + " Temperature(F)",
                             conditions['current_observation']['temp_f'])
            if isFloat(conditions['current_observation']['dewpoint_f']):
                streamer.log(CITY + " Dewpoint(F)",
                             conditions['current_observation']['dewpoint_f'])
            if isFloat(conditions['current_observation']['wind_mph']):
                streamer.log(":dash: " + CITY + " Wind Speed(MPH)",
                             conditions['current_observation']['wind_mph'])
            if isFloat(conditions['current_observation']['wind_gust_mph']):
                streamer.log(
                    ":dash: " + CITY + " Wind Gust(MPH)",
                    conditions['current_observation']['wind_gust_mph'])
            if isFloat(humidity):
                streamer.log(":droplet: " + CITY + " Humidity(%)", humidity)
            if isFloat(conditions['current_observation']['pressure_in']):
                streamer.log(CITY + " Pressure(IN)",
                             conditions['current_observation']['pressure_in'])
            if isFloat(conditions['current_observation']['precip_1hr_in']):
                streamer.log(
                    ":umbrella: " + CITY + " Precip 1 Hour(IN)",
                    conditions['current_observation']['precip_1hr_in'])
            if isFloat(conditions['current_observation']['precip_today_in']):
                streamer.log(
                    ":umbrella: " + CITY + " Precip Today(IN)",
                    conditions['current_observation']['precip_today_in'])
            if isFloat(conditions['current_observation']['solarradiation']):
                streamer.log(
                    ":sunny: " + CITY + " Solar Radiation (watt/m^2)",
                    conditions['current_observation']['solarradiation'])
            if isFloat(conditions['current_observation']['UV']):
                streamer.log(":sunny: " + CITY + " UV Index:",
                             conditions['current_observation']['UV'])
            streamer.flush()
        time.sleep(60 * MINUTES_BETWEEN_READS)
Beispiel #6
0
# ---------------------------------


def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False


streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)

while True:
    try:
        [temp_c, hum] = grovepi.dht(DHT_SENSOR_PIN, DHT_SENSOR_TYPE)
        if isFloat(temp_c):
            if CONVERT_TO_FAHRENHEIT:
                temp_f = temp_c * 9.0 / 5.0 + 32.0
                # print("Temperature(F) = ", temp_f)
                streamer.log("Temperature(F)", temp_f)
            else:
                # print("Temperature(C) = ", temp_c)
                streamer.log("Temperature(C)", temp_c)
        if (isFloat(hum)) and (hum >= 0):
            # print("Humidity(%) = ", hum)
            streamer.log(":sweat_drops: Humidity(%)", hum)
        streamer.flush()

    except IOError:
        print("Error")
def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False


streamer = Streamer(bucket_name=BUCKET_NAME,
                    bucket_key=BUCKET_KEY,
                    access_key=ACCESS_KEY)

while True:
    try:
        [temp_c, hum] = grovepi.dht(DHT_SENSOR_PIN, DHT_SENSOR_TYPE)
        airSensorVal = grovepi.analogRead(AIR_SENSOR_PIN)

        if isFloat(temp_c):
            if (METRIC_UNITS):
                # print "Temperature(C) = " + str(temp_c)
                streamer.log("Temperature(C)", temp_c)
            else:
                temp_f = temp_c * 9.0 / 5.0 + 32.0
                temp_f = float("{0:.2f}".format(temp_f))
                # print "Temperature(F) = " + str(temp_f)
                streamer.log("Temperature(F)", temp_f)
        if ((isFloat(hum)) and (hum >= 0)):
            # print "Humidity(%) = " + str(hum)
            streamer.log(":sweat_drops: Humidity(%)", hum)
 def read_dht(self):
     return grovepi.dht(self.pins['sensors']['dht'], 1)
	url = "https://api.thingspeak.com/update"
	payload = { "key" : "WWMPY3RJZHFCIJMR", "field1" : temp, "field3" : humidity }
	r = requests.post(url, data=payload)
	print( "Thingspeak " + ('succeeded' if r!= 0 else " did not succeed" ))

#print 'Logging sensor measurements to {0} every {1} seconds.'.format(GDOCS_SPREADSHEET_NAME, FREQUENCY_SECONDS)
#print 'Press Ctrl-C to quit.'
worksheet = None
# Login if necessary.
if worksheet is None:
	worksheet = login_open_sheet(GDOCS_OAUTH_JSON, GDOCS_SPREADSHEET_NAME)


# Attempt to get sensor reading.
# humidity, temp = Adafruit_DHT.read(DHT_TYPE, DHT_PIN)
[temp,humidity] = grovepi.dht(GROVE_SENSOR,0)

# Skip to the next reading if a valid measurement couldn't be taken.
# This might happen if the CPU is under a lot of load and the sensor
# can't be reliably read (timing is critical to read the sensor).
if humidity is None or temp is None:
	time.sleep(2)
	#continue
	exit(1)

print( 'Temperature: {0:0.1f} C'.format(temp))
print( 'Humidity:    {0:0.1f} %'.format(humidity))
 
# Append the data in the spreadsheet, including a timestamp
try:
	worksheet.append_row((datetime.datetime.now(), temp, humidity))
def main():
    conditions = get_conditions()
    astronomy = get_astronomy()
    if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
        print "Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!"
        if 'error' in conditions['response']:
            print "Error Type: " + conditions['response']['error']['type']
            print "Error Description: " + conditions['response']['error']['description']
        exit()
    else:
        streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY)
        streamer.log(":house: Location",conditions['current_observation']['display_location']['full'])
    while True:
        # -------------- Read GrovePi Sensors --------------
        try:
            [temp_c,hum] = grovepi.dht(DHT_SENSOR_PIN,DHT_SENSOR_TYPE)
            if isFloat(temp_c):
                if (METRIC_UNITS):
                    # print("Temperature(C) = ", temp_c)
                    streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)", temp_c)        
                else:
                    temp_f = temp_c * 9.0 / 5.0 + 32.0
                    # print("Temperature(F) = ", temp_f)
                    streamer.log(":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)", temp_f)
            if ((isFloat(hum)) and (hum >= 0)):
        		# print("Humidity(%) = ", hum)
            	streamer.log(":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)", hum)

        except IOError:
            print ("Error")

        # -------------- Wunderground --------------
        conditions = get_conditions()
        astronomy = get_astronomy()
        if ('current_observation' not in conditions) or ('moon_phase' not in astronomy):
		print "Error! Wunderground API call failed. Skipping a reading then continuing ..."
	else:
            humidity_pct = conditions['current_observation']['relative_humidity']
            humidity = humidity_pct.replace("%","")

            # Stream valid conditions to Initial State
            streamer.log(":cloud: " + CITY + " Weather Conditions",weather_status_icon(conditions, astronomy))
            streamer.log(":crescent_moon: Moon Phase",moon_icon(astronomy['moon_phase']['phaseofMoon']))
            streamer.log(":dash: " + CITY + " Wind Direction",wind_dir_icon(conditions, astronomy))
            if (METRIC_UNITS):
                if isFloat(conditions['current_observation']['temp_c']): 
                    streamer.log(CITY + " Temperature(C)",conditions['current_observation']['temp_c'])
                if isFloat(conditions['current_observation']['dewpoint_c']):
                    streamer.log(CITY + " Dewpoint(C)",conditions['current_observation']['dewpoint_c'])
                if isFloat(conditions['current_observation']['wind_kph']):
                    streamer.log(":dash: " + CITY + " Wind Speed(KPH)",conditions['current_observation']['wind_kph'])
                if isFloat(conditions['current_observation']['wind_gust_kph']):
                    streamer.log(":dash: " + CITY + " Wind Gust(KPH)",conditions['current_observation']['wind_gust_kph'])
                if isFloat(conditions['current_observation']['pressure_mb']):
                    streamer.log(CITY + " Pressure(mb)",conditions['current_observation']['pressure_mb'])
                if isFloat(conditions['current_observation']['precip_1hr_metric']):
                    streamer.log(":umbrella: " + CITY + " Precip 1 Hour(mm)",conditions['current_observation']['precip_1hr_metric'])
                if isFloat(conditions['current_observation']['precip_today_metric']):
                    streamer.log(":umbrella: " + CITY + " Precip Today(mm)",conditions['current_observation']['precip_today_metric'])
            else:
                if isFloat(conditions['current_observation']['temp_f']): 
                    streamer.log(CITY + " Temperature(F)",conditions['current_observation']['temp_f'])
                if isFloat(conditions['current_observation']['dewpoint_f']):
                    streamer.log(CITY + " Dewpoint(F)",conditions['current_observation']['dewpoint_f'])
                if isFloat(conditions['current_observation']['wind_mph']):
                    streamer.log(":dash: " + CITY + " Wind Speed(MPH)",conditions['current_observation']['wind_mph'])
                if isFloat(conditions['current_observation']['wind_gust_mph']):
                    streamer.log(":dash: " + CITY + " Wind Gust(MPH)",conditions['current_observation']['wind_gust_mph'])
                if isFloat(conditions['current_observation']['pressure_in']):
                    streamer.log(CITY + " Pressure(IN)",conditions['current_observation']['pressure_in'])
                if isFloat(conditions['current_observation']['precip_1hr_in']):
                    streamer.log(":umbrella: " + CITY + " Precip 1 Hour(IN)",conditions['current_observation']['precip_1hr_in'])
                if isFloat(conditions['current_observation']['precip_today_in']):
                    streamer.log(":umbrella: " + CITY + " Precip Today(IN)",conditions['current_observation']['precip_today_in'])
            if isFloat(conditions['current_observation']['solarradiation']):
                streamer.log(":sunny: " + CITY + " Solar Radiation (watt/m^2)",conditions['current_observation']['solarradiation'])
            if isFloat(humidity):
                streamer.log(":droplet: " + CITY + " Humidity(%)",humidity)
            if isFloat(conditions['current_observation']['UV']):
                streamer.log(":sunny: " + CITY + " UV Index:",conditions['current_observation']['UV'])
            streamer.flush()
        time.sleep(60*MINUTES_BETWEEN_READS)
def main():
    conditions = get_conditions()
    astronomy = get_astronomy()
    if ('current_observation' not in conditions) or ('moon_phase'
                                                     not in astronomy):
        print "Error! Wunderground API call failed, check your STATE and CITY and make sure your Wunderground API key is valid!"
        if 'error' in conditions['response']:
            print "Error Type: " + conditions['response']['error']['type']
            print "Error Description: " + conditions['response']['error'][
                'description']
        exit()
    else:
        streamer = Streamer(bucket_name=BUCKET_NAME,
                            bucket_key=BUCKET_KEY,
                            access_key=ACCESS_KEY)
        streamer.log(
            ":house: Location",
            conditions['current_observation']['display_location']['full'])
    while True:
        # -------------- GrovePi Zero --------------
        # Read the sensors
        try:
            [temp_c, hum] = grovepi.dht(DHT_SENSOR_PIN, DHT_SENSOR_TYPE)
            airSensorVal = grovepi.analogRead(AIR_SENSOR_PIN)

            if isFloat(temp_c):
                if (METRIC_UNITS):
                    streamer.log(
                        ":sunny: " + SENSOR_LOCATION_NAME + " Temperature(C)",
                        temp_c)
                else:
                    temp_f = temp_c * 9.0 / 5.0 + 32.0
                    temp_f = float("{0:.2f}".format(temp_f))
                    streamer.log(
                        ":sunny: " + SENSOR_LOCATION_NAME + " Temperature(F)",
                        temp_f)
            if ((isFloat(hum)) and (hum >= 0)):
                streamer.log(
                    ":sweat_drops: " + SENSOR_LOCATION_NAME + " Humidity(%)",
                    hum)

            if isFloat(airSensorVal):
                if airSensorVal > 700:
                    streamer.log(SENSOR_LOCATION_NAME + " Air Quality",
                                 ":fog: :bangbang:")
                elif airSensorVal > 300:
                    streamer.log(SENSOR_LOCATION_NAME + " Air Quality",
                                 ":foggy: :exclamation:")
                else:
                    streamer.log(SENSOR_LOCATION_NAME + " Air Quality",
                                 ":rainbow:")
                streamer.log(SENSOR_LOCATION_NAME + " Air Quality Sensor",
                             airSensorVal)
        except IOError:
            print("Error")

        # -------------- Wunderground --------------
        conditions = get_conditions()
        astronomy = get_astronomy()
        if ('current_observation' not in conditions) or ('moon_phase'
                                                         not in astronomy):
            print "Error! Wunderground API call failed. Skipping a reading then continuing ..."
        else:
            humidity_pct = conditions['current_observation'][
                'relative_humidity']
            humidity = humidity_pct.replace("%", "")

            # Stream valid conditions to Initial State
            streamer.log(":cloud: " + CITY + " Weather Conditions",
                         weather_status_icon(conditions, astronomy))
            streamer.log(":crescent_moon: Moon Phase",
                         moon_icon(astronomy['moon_phase']['phaseofMoon']))
            streamer.log(":dash: " + CITY + " Wind Direction",
                         wind_dir_icon(conditions, astronomy))
            if (METRIC_UNITS):
                if isFloat(conditions['current_observation']['temp_c']):
                    streamer.log(CITY + " Temperature(C)",
                                 conditions['current_observation']['temp_c'])
                if isFloat(conditions['current_observation']['dewpoint_c']):
                    streamer.log(
                        CITY + " Dewpoint(C)",
                        conditions['current_observation']['dewpoint_c'])
                if isFloat(conditions['current_observation']['wind_kph']):
                    streamer.log(":dash: " + CITY + " Wind Speed(KPH)",
                                 conditions['current_observation']['wind_kph'])
                if isFloat(conditions['current_observation']['wind_gust_kph']):
                    streamer.log(
                        ":dash: " + CITY + " Wind Gust(KPH)",
                        conditions['current_observation']['wind_gust_kph'])
                if isFloat(conditions['current_observation']['pressure_mb']):
                    streamer.log(
                        CITY + " Pressure(mb)",
                        conditions['current_observation']['pressure_mb'])
                if isFloat(conditions['current_observation']
                           ['precip_1hr_metric']):
                    streamer.log(
                        ":umbrella: " + CITY + " Precip 1 Hour(mm)",
                        conditions['current_observation']['precip_1hr_metric'])
                if isFloat(conditions['current_observation']
                           ['precip_today_metric']):
                    streamer.log(
                        ":umbrella: " + CITY + " Precip Today(mm)",
                        conditions['current_observation']
                        ['precip_today_metric'])
            else:
                if isFloat(conditions['current_observation']['temp_f']):
                    streamer.log(CITY + " Temperature(F)",
                                 conditions['current_observation']['temp_f'])
                if isFloat(conditions['current_observation']['dewpoint_f']):
                    streamer.log(
                        CITY + " Dewpoint(F)",
                        conditions['current_observation']['dewpoint_f'])
                if isFloat(conditions['current_observation']['wind_mph']):
                    streamer.log(":dash: " + CITY + " Wind Speed(MPH)",
                                 conditions['current_observation']['wind_mph'])
                if isFloat(conditions['current_observation']['wind_gust_mph']):
                    streamer.log(
                        ":dash: " + CITY + " Wind Gust(MPH)",
                        conditions['current_observation']['wind_gust_mph'])
                if isFloat(conditions['current_observation']['pressure_in']):
                    streamer.log(
                        CITY + " Pressure(IN)",
                        conditions['current_observation']['pressure_in'])
                if isFloat(conditions['current_observation']['precip_1hr_in']):
                    streamer.log(
                        ":umbrella: " + CITY + " Precip 1 Hour(IN)",
                        conditions['current_observation']['precip_1hr_in'])
                if isFloat(
                        conditions['current_observation']['precip_today_in']):
                    streamer.log(
                        ":umbrella: " + CITY + " Precip Today(IN)",
                        conditions['current_observation']['precip_today_in'])
            if isFloat(conditions['current_observation']['solarradiation']):
                streamer.log(
                    ":sunny: " + CITY + " Solar Radiation (watt/m^2)",
                    conditions['current_observation']['solarradiation'])
            if isFloat(humidity):
                streamer.log(":droplet: " + CITY + " Humidity(%)", humidity)
            if isFloat(conditions['current_observation']['UV']):
                streamer.log(":sunny: " + CITY + " UV Index:",
                             conditions['current_observation']['UV'])
            streamer.flush()
        time.sleep(60 * MINUTES_BETWEEN_READS)
Beispiel #12
0
 def read_dht(self):
     return grovepi.dht(self.pins['sensors']['dht'], 1)
Beispiel #13
0
import time
from datetime import datetime
from grovepi import grovepi

while True:
	# define pin number for sensors here
	dht = 4
	light_sensor = 1
	sound_sensor = 0
	moist_sensor = 2

	temp = grovepi.dht(dht,0)[0]
	humidity = grovepi.dht(dht,0)[1]
	lightlvl = grovepi.analogRead(light_sensor)
	soundlvl = grovepi.analogRead(sound_sensor)
	moistlvl = grovepi.analogRead(moist_sensor)


	# timestamp is UTC, and UTC time shall be used across
	myData={"d": {'temp':temp, 'humidity':humidity, 'lightlvl':lightlvl, 'soundlvl':soundlvl, 'moistlvl':moistlvl}, "ts": datetime.utcnow().isoformat()+"Z"}
	print(myData)
	time.sleep(1)


# def myCommandCallback(cmd):
#   print("Command received: %s" % cmd.data)
#   if cmd.command == "TurnOn":
#     grovepi.digitalWrite(2,1)
#     print("LED is now turned ON")
#   elif cmd.command == "TurnOff":
#     grovepi.digitalWrite(2,0)
Beispiel #14
0
data_available = False
time.sleep(1)


while True:

        #init
        if not initialized:
                setRGB(0, 50, 0)
                setText("Getting data..")
                initialized = True

    #Try to read the sensor measurements
    try:
            light_intensity = grovepi.analogRead(light_sensor)
        [temp, hum] = grovepi.dht(dht_sensor_port, dht_sensor_type)
                sound_level = grovepi.analogRead(sound_sensor)
        wind_dir_raw = grovepi.analogRead(rotary_sensor)
                switch = grovepi.digitalRead(button)
                distance = grovepi.ultrasonicRead(ultrasonic_ranger)

        if wind_dir_raw == 0:
            wind_direction = 0
        else:
            wind_direction = wind_dir_raw * (360 / 1024.0)

                wind_direction = float("{0:.1f}".format(wind_direction))

                #Save locally
                sensor_values[0] = light_intensity
                sensor_values[1] = temp