Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5744

MicroPython • Will I be able to run this code on MicroPython?

$
0
0
Specifically the call to

Code:

requests.get
and the call to

Code:

json.loads
and I'm not sure what

Code:

headers.update
does near the start.
This is just part of the code I have running on a Pi ZeroW and I was thinking of trying to move it onto a PicoW.
The rest of the code is pretty simple standard python. I've never used MicroPython before although I've done lots of Python on the Pi and C on the Pico.

I guess the other problem is that I may run out of memory although the string data returned from the

Code:

requests.get
is generally < 30kB

Code:

def retrieve_forecast(baseUrl, timesteps, requestHeaders, latitude, longitude, excludeMetadata, includeLocation):        url = baseUrl + timesteps         headers = {'accept': "application/json"}    headers.update(requestHeaders)    params = {        'excludeParameterMetadata' : excludeMetadata,        'includeLocationName' : includeLocation,        'latitude' : latitude,        'longitude' : longitude        }    success = False    retries = 5    while not success and retries >0:        try:            req = requests.get(url, headers=headers, params=params)            success = True        except Exception as e:            log.warning("Exception occurred", exc_info=True)            retries -= 1            #time.sleep(10)            if retries == 0:                #log.error("Retries exceeded", exc_info=True)                #sys.exit()    req.encoding = 'utf-8'    data_dict = json.loads(req.text)    if not isinstance(data_dict, dict) :        #print("Not successfully converted into a dictionary - check API key")    else :        location = (data_dict['features'][0]['properties']['location']['name'])        print("Location found is : {}".format(location))        time0 = (data_dict['features'][0]['properties']['timeSeries'][0]['time'])        windSpeed0 = (data_dict['features'][0]['properties']['timeSeries'][0]['windSpeed10m'])        temperature0 = (data_dict['features'][0]['properties']['timeSeries'][0]['screenTemperature'])        probofrain0 = (data_dict['features'][0]['properties']['timeSeries'][0]['probOfPrecipitation'])        swc0 = (data_dict['features'][0]['properties']['timeSeries'][0]['significantWeatherCode'])

Statistics: Posted by MarkDH102 — Thu Feb 08, 2024 3:36 pm



Viewing all articles
Browse latest Browse all 5744

Trending Articles