Due to high demand, expect some shipping delays at this time - orders may not ship for up to 2-3 business days.
0

ESP_BUSY in use
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ESP_BUSY in use

by teltech84 on Mon Jan 24, 2022 9:31 am

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 | TOGGLE FULL SIZE
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)



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

Re: ESP_BUSY in use

by dastels on Mon Jan 24, 2022 12:14 pm

Try only creating one PyPortal object before the main function.

Dave

dastels
 
Posts: 9742
Joined: Tue Oct 20, 2015 3:22 pm

Re: ESP_BUSY in use

by teltech84 on Mon Jan 24, 2022 12:39 pm

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 | TOGGLE FULL SIZE
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)

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

Re: ESP_BUSY in use

by dastels on Mon Jan 24, 2022 1:40 pm

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 | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
 pyportal.preload_font()
can be done above as well since it only has to be done once.

Dave

dastels
 
Posts: 9742
Joined: Tue Oct 20, 2015 3:22 pm

Re: ESP_BUSY in use

by teltech84 on Mon Jan 24, 2022 9:54 pm

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 | TOGGLE FULL SIZE
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

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

Re: ESP_BUSY in use

by dastels on Mon Jan 24, 2022 10:16 pm

I believe
Code: Select all | TOGGLE FULL SIZE
pyportal.fetch()
is for that.

Dave

dastels
 
Posts: 9742
Joined: Tue Oct 20, 2015 3:22 pm

Re: ESP_BUSY in use

by teltech84 on Tue Jan 25, 2022 11:39 am

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 | TOGGLE FULL SIZE
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)


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

Re: ESP_BUSY in use

by dastels on Tue Jan 25, 2022 11:45 am

Well done!

Dave

dastels
 
Posts: 9742
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.