ESP_BUSY in use

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
teltech84
 
Posts: 20
Joined: Sun Jan 23, 2022 10:20 am

ESP_BUSY in use

Post by teltech84 »

Hello,

My code runs the first loop fine but when running a second loop it returns an "Some error occured, retrying! - ESP_BUSY in use" error.

Does anyone know why this happens on my pyportal?

Code: Select all

import time
import board
from adafruit_pyportal import PyPortal

textrow = 0
authorrow = 0

def main(textrow, authorrow):
    

    # Set up where we'll be fetching data from
    DATA_SOURCE = "http://192.168.1.67/presently-backup.json"
    QUOTE_LOCATION = [textrow, 'text']
    AUTHOR_LOCATION = [authorrow, 'author']

    # the current working directory (where this file is)
    cwd = ("/"+__file__).rsplit('/', 1)[0]

    pyportal = PyPortal(url=DATA_SOURCE,
                        json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
                        #status_neopixel=board.NEOPIXEL,
                        default_bg=cwd+"/quote_background.bmp",
                        text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
                        text_position=((20, 120),  # quote location
                                    (5, 210)), # author location
                        text_color=(0xFFFFFF,  # quote text color
                                    0x8080FF), # author text color
                        text_wrap=(35, # characters to wrap for quote
                                0), # no wrap for author
                        text_maxlen=(180, 30), # max text size for quote & author
                    )

    # speed up projects with lots of text by preloading the font!
    pyportal.preload_font()
    value = pyportal.fetch()
    textrow = textrow + 1
    authorrow = authorrow + 1
    print("Response is", value)
    return value

while True:
    try:
        main(textrow, authorrow)
        time.sleep(5)
    except (ValueError, RuntimeError) as e:
        print("Some error occured, retrying! -", e)
    time.sleep(5)



User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: ESP_BUSY in use

Post by dastels »

Try only creating one PyPortal object before the main function.

Dave

User avatar
teltech84
 
Posts: 20
Joined: Sun Jan 23, 2022 10:20 am

Re: ESP_BUSY in use

Post by teltech84 »

Thanks for the reply Dave. This is what I've got so far based on your recommendations and it does remove the error although the code doesn't do what I wanted it to do.

I have a json file that has multiple key's.
[{"text":"testtext1","author":"author1"},
{"text":"testtext2","author":"author2"}]

I want my code to display testtext1, author 1 and then cycle back and display testtext2 author2 etc...
Currently it only retrieves the hardcoded value of testtext1 and author1.

Am I correct to think that if I call function PyPortal more than once it will error out and say it's busy? Do you know of a way to accomplish what I want to do?

Code: Select all

import time
import board
from adafruit_pyportal import PyPortal




#Set up where we'll be fetching data from
DATA_SOURCE = "http://192.168.1.67/presently-backup.json"
QUOTE_LOCATION = [textrow, 'text']
AUTHOR_LOCATION = [authorrow, 'author']
#the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]

pyportal = PyPortal(url=DATA_SOURCE,
                    json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
                    #status_neopixel=board.NEOPIXEL,
                    default_bg=cwd+"/quote_background.bmp",
                    text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
                    text_position=((20, 120),  # quote location
                                (5, 210)), # author location
                    text_color=(0xFFFFFF,  # quote text color
                                0x8080FF), # author text color
                    text_wrap=(35, # characters to wrap for quote
                            0), # no wrap for author
                    text_maxlen=(180, 30), # max text size for quote & author
                )
                        
def main(textrow, authorrow):
    textrow = 0
    authorrow = 0
    # speed up projects with lots of text by preloading the font!
    pyportal.preload_font()
    value = pyportal.fetch()
    textrow = textrow + 1
    authorrow = authorrow + 1
    print("Response is", value)

    return value

while True:
    try:
        main(textrow, authorrow)
        time.sleep(5)
    except (ValueError, RuntimeError) as e:
        print("Some error occured, retrying! -", e)
    time.sleep(5)

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: ESP_BUSY in use

Post by dastels »

You'll likely have to do a bit more work. Fetch the json yourself (well, your code) and loop through it extracting the two bits of information and displaying them. This is a little different than the basic usecase for the portal stuff.

When you have:

Code: Select all

QUOTE_LOCATION = [textrow, 'text']
AUTHOR_LOCATION = [authorrow, 'author']
That gets done once, i.e. textrow and authorrow are looked up then and used to create the lists. You are then passing those lists to the portal constructor. It doesn't matter if you later change textrow and authorrow... they aren't related to those lists at all, so the lists never change.

Also,

Code: Select all

 pyportal.preload_font()
can be done above as well since it only has to be done once.

Dave

User avatar
teltech84
 
Posts: 20
Joined: Sun Jan 23, 2022 10:20 am

Re: ESP_BUSY in use

Post by teltech84 »

So the following snippit can only be displayed once correct? It displays data to the screen. Should I be using another function to refresh or update that information? Because it seems like if I call this twice it errors out.

Code: Select all

pyportal = PyPortal(url=DATA_SOURCE,
                    json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
                    #status_neopixel=board.NEOPIXEL,
                    default_bg=cwd+"/quote_background.bmp",
                    text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
                    text_position=((20, 120),  # quote location
                                (5, 210)), # author location
                    text_color=(0xFFFFFF,  # quote text color
                                0x8080FF), # author text color
                    text_wrap=(35, # characters to wrap for quote
                            0), # no wrap for author
                    text_maxlen=(180, 30), # max text size for quote & author

User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: ESP_BUSY in use

Post by dastels »

I believe

Code: Select all

pyportal.fetch()
is for that.

Dave

User avatar
teltech84
 
Posts: 20
Joined: Sun Jan 23, 2022 10:20 am

Re: ESP_BUSY in use

Post by teltech84 »

Thank you I got the loop to work! If I replace the json value in each loop it updates the data that's retrieved.

Code: Select all

import time
import board
from adafruit_pyportal import PyPortal
import json



i = 0
 
#Set up where we'll be fetching data from
DATA_SOURCE = "http://192.168.1.67/presently-backup.json"
QUOTE_LOCATION = [i , 'entryContent']
AUTHOR_LOCATION = [i , 'entryDate']

#the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
var = (QUOTE_LOCATION, AUTHOR_LOCATION)
pyportal = PyPortal(url=DATA_SOURCE,
                    json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
                    #status_neopixel=board.NEOPIXEL,
                    default_bg=cwd+"/quote_background.bmp",
                    text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
                    text_position=((20, 120),  # quote location
                                (5, 210)), # author location
                    text_color=(0xFFFFFF,  # quote text color
                                0x8080FF), # author text color
                    text_wrap=(35, # characters to wrap for quote
                            0), # no wrap for author
                    text_maxlen=(180, 30), # max text size for quote & author
                )
pyportal.preload_font()


def main(i):
    
    pyportal.json_path=([ i,
                        'entryContent'],
                        [ i,
                        'entryDate'],
                        )
    # speed up projects with lots of text by preloading the font!
    value = pyportal.fetch()
    print("Response is", value)


while True:
    try:
        main(i)
        i = i + 1
        time.sleep(5)
    except (ValueError, RuntimeError) as e:
        print("Some error occured, retrying! -", e)
    time.sleep(5)


User avatar
dastels
 
Posts: 15667
Joined: Tue Oct 20, 2015 3:22 pm

Re: ESP_BUSY in use

Post by dastels »

Well done!

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”