Question
Add to code below so specifications are met: Frequency of Data: Readings must be taken once every 30 minutes, and the readings must be incrementally
Add to code below so specifications are met:
Frequency of Data: Readings must be taken once every 30 minutes, and the readings must be incrementally stored in a JSON file. To clarify, each reading must be added to a single JSON file so that a flat file of readings is stored over time.
Output Visual Using LEDs:
*Green LED lights up when the last conditions are: temperature > 60 and < 85, and humidity is < 80%
*Blue LED lights upwhen the last conditions are: temperature > 85 and < 95, and humidity is < 80%
*Red LED lights up when the last conditions are: temperature > 95
*Green and Blue LED light up when the last conditions are: humidity >80%
Code
from grovepi import *
from grove_rgb_lcd import *
import math
import json
dht_sensor_port = 7 # connect the DHt sensor to port 7
dht_sensor_type = 0 # use 0 for the blue-colored sensor and 1 for the white-colored sensor
# set green as backlight color
# we need to do it just once
# setting the backlight color once reduces the amount of data transfer over the I2C line
setRGB(0,255,0)
# temp_humidity_sensor_type
# Grove Base Kit comes with the blue sensor.
blue = 0 # The Blue colored sensor.
white = 1 # The White colored sensor.
while True:
try:
# This example uses the blue colored sensor.
# The first parameter is the port, the second parameter is the type of sensor.
[temp,humidity] = grovepi.dht(sensor,blue)
if math.isnan(temp) == False and math.isnan(humidity) == False:
print("temp = %.356f F humidity =%.356f%%"%(temp, humidity))
except IOError:
print ("Error")
tempHumid={ #Making json array here
'Temp' :tempF
'Humidity': humidity
}
with open('temperature_humidity.json', 'w') as json_tempHumid_file: #writing to json file
json.dump(tempHumid, json_tempHumid_file)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started