Menu

[Solved]Need Help Condition Statements Python Coding Raspberry Pi 3 Currently Working Project Pull Q37130942

I need help with condition statements for python coding on araspberry pi 3. I am currently working on a project that pullsweather data from a online source and depending on that data itwill light up LEDs that will signal what temperature is in acertain range (0-32F, 33-50F, 51-75F, 76_100F) then it will havemore conditioning statements to figure out if its sunny, rainy,snowy, ect depending on which temperature increment is active forthat day.

Currently I have the following python script that is attached.The weather data is being pulled correctly but I don’t know how touse this information to plug into conditioning statements. (it isin json)

Also if you could teach me how to turn the raspberry pi onautomatically at a certain time of the day and off that whileautomatically running this script that would be fantastic.

Below is what i have so far………………

from requests import get
import json
from pprint import pprint
from haversine import haversine

stations =’https://apex.oracle.com/pls/apex/raspberrypi/weatherstation/getallstations’
weather =’https://apex.oracle.com/pls/apex/raspberrypi/weatherstation/getlatestmeasurements/’

my_lat = 37.821591
my_lon = -97.652353

all_stations = get(stations).json()[‘items’]

def find_closest():
smallest = 20036
for station in all_stations:
station_lon = station[‘weather_stn_long’]
station_lat = station[‘weather_stn_lat’]
distance = haversine(my_lon, my_lat, station_lon,station_lat)
if distance < smallest:
smallest = distance
closest_station = station[‘weather_stn_id’]
return closest_station

closest_stn = find_closest()
weather = weather + str(closest_stn)
my_weather = get(weather).json()[‘items’]
pprint(my_weather)
#END OF WEATHER RETRIEVAL#

#BEGINNING LEDs INFO#
from rpi_ws281x import *

LED_COUNT = 300
LED_PIN = 18
LED_FREQ_HZ = 800000
LED_DMA = 10
LED_BRIGHTNESS = 50
LED_INVERT = False
LED_CHANNEL = 0

strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
#END OF LEDs INFO#

#START OF CONDITIONING STATEMENTS FOR WEATHER#

strip.begin()
import json
#convert the json into dictionary

weather_data=”'(“air_pressure”:, “air_quality”:,”ambient_temp”:, “created_by”:, “created_on”:, “ground_temp”:,”humidity”:, “id”:)”’

y=json.loads(weather_data)
#values can be accessed using the following notation
temperature=(y[“ambient_temp”])
#conditional statement for different temperature zones

if temperature <= 0:
for x in range(0, 5):
strip.setPixelColor(x, Color(0,255,0))
elif 0.01<=temperature<10:
for x in range(6, 10):
strip.setPixelColor(x, Color(255,0,0))
elif 10.001<=temperature<24:
for x in range(11, 15):
strip.setPixelColor(x, Color(0,0,255))
elif 24.001<=temperature<10000:
for x in range(16, 20):
strip.setPixelColor(x, Color(255,255,255))

strip.show()

Expert Answer


Answer to I need help with condition statements for python coding on a raspberry pi 3. I am currently working on a project that pu… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *