0

pyportal pynt does not connect to WiFi
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

pyportal pynt does not connect to WiFi

by evanthomas on Sun Jan 26, 2020 11:31 pm

I just received 2 pyportals, a normal size and a pynt. The normal sized one works fine - so there is no issue with my AP.

However, pynt only connected twice to the AP over many hours of testing and when it did it couldn't retrieve data. I have tried circuit python versions 4.0.0-beta5, 4.1.2 and 5.0.0-beta4. The code is the quote demo that comes with the device.

Mostly it simply fails to connect with the message 'No such ssid'.

There are a couple of threads on forums about pyportal wifi issues however customer support have asked me to raise a topic here.
viewtopic.php?f=60&t=149924&p=741770&hilit=pyportal+no+such+ssid#p741770
viewtopic.php?f=60&t=149970#p741743

Thanks,
Evan.

evanthomas
 
Posts: 10
Joined: Sun Jan 26, 2020 11:11 pm

Re: pyportal pynt does not connect to WiFi

by evanthomas on Mon Jan 27, 2020 2:12 am

Looking at the PyPortal code I realise that it is connecting to the AP but it is unable to retrieve data from the quotes URL. I've tried with a non-SSL endpoint in my own network and it is more reliable.

evanthomas
 
Posts: 10
Joined: Sun Jan 26, 2020 11:11 pm

Re: pyportal pynt does not connect to WiFi

by adafruit_support_carter on Tue Jan 28, 2020 3:27 pm

It sounds like it's working now?

adafruit_support_carter
 
Posts: 14475
Joined: Tue Nov 29, 2016 2:45 pm

Re: pyportal pynt does not connect to WiFi

by evanthomas on Tue Jan 28, 2020 8:06 pm

Not really. I couldn't retrieve data from the quotes URL. It can sometimes get data from a non-SSL URL in my home network but nowhere close to reliably. FWIW, the normal size pyportal is now showing the same symptoms so presumably not a hardware error.

I'm now using a code based on https://github.com/adafruit/Adafruit_Ci ... pletest.py
that connects to the AP, usually on the second attempt, and polls an endpoint in my home network every 10s. It will work for a while but then go into a mode where it continually fails with:

Timed out waiting for SPI char

until it is reset.

Should I handling this error in some way.

Thanks,
Evan.

evanthomas
 
Posts: 10
Joined: Sun Jan 26, 2020 11:11 pm

Re: pyportal pynt does not connect to WiFi

by adafruit_support_carter on Tue Jan 28, 2020 8:44 pm

It sounds like you are in general dealing with some kind of intermittent internet connection issue. Adding some try/except loops similar to what is done during initial connection:
https://github.com/adafruit/Adafruit_Ci ... est.py#L39
could be one way to catch the errors and then try again.

adafruit_support_carter
 
Posts: 14475
Joined: Tue Nov 29, 2016 2:45 pm

Re: pyportal pynt does not connect to WiFi

by evanthomas on Tue Jan 28, 2020 10:41 pm

It is in a try/execpt loop but once it starts failing it never recovers, even though there is nothing wrong with the network (other devices connect to that endpoint point without any problems). The question is, does that error require some sort of special handling? Do I need to disconnect from the AP and reconnect.

Just to provide a bit of context moving forward, I am an experienced software engineer and I have used esp32s with the arduino framework as well (and the WiFi is rock solid).

evanthomas
 
Posts: 10
Joined: Sun Jan 26, 2020 11:11 pm

Re: pyportal pynt does not connect to WiFi

by adafruit_support_carter on Wed Jan 29, 2020 2:43 pm

What library version are you using in conjunction with the 5.0.0 beta CP firmware on the Pynt?

adafruit_support_carter
 
Posts: 14475
Joined: Tue Nov 29, 2016 2:45 pm

Re: pyportal pynt does not connect to WiFi

by evanthomas on Wed Jan 29, 2020 7:08 pm

So, I have the same behaviour on the pynt and the normal. One of, them I can't remember which, I specifically installed CP 4.1.2 and the all the relevant libraries from the 4.x library bundle.

Could it be the eps32 firmware? I'm not at home atm so I can't check the version.

I'm currently counting the number of times I get the same error in a row and if it reaches 5 I do a supervisor.reload(). It works, but it's pretty ugly.

Thanks for persisting with this.

Evan.

evanthomas
 
Posts: 10
Joined: Sun Jan 26, 2020 11:11 pm

Re: pyportal pynt does not connect to WiFi

by adafruit_support_carter on Thu Jan 30, 2020 2:55 pm

Hopefully it's not the ESP32 firmware. We should at least vet out other things first.

Can you verify that you are getting the same issue on both a PyPortal and PyPortal Pynt using CP 4.1.2 and latest libraries for both?

And you say "code based on" the simpletest example. How modified is it? Can you test using the example as is?
https://github.com/adafruit/Adafruit_Ci ... pletest.py

adafruit_support_carter
 
Posts: 14475
Joined: Tue Nov 29, 2016 2:45 pm

Re: pyportal pynt does not connect to WiFi

by evanthomas on Thu Jan 30, 2020 6:47 pm

The code you've linked to works - but all it does is connect and do a couple of calls. I'm using that code to connect to my AP. Connecting is not the issue, even I thought it was initially.

I'll check that both devices are running the current stable releases tonight and upload the code I'm using.

evanthomas
 
Posts: 10
Joined: Sun Jan 26, 2020 11:11 pm

Re: pyportal pynt does not connect to WiFi

by adafruit_support_carter on Thu Jan 30, 2020 6:52 pm

That test is intentionally simple. If it didn't work, then something very fundamental would be wrong.

Issues with more complex programs can be various things. If you can figure out the specific additional code, relative to the above, that then makes it stop working, that would help narrow down where the issue is.

adafruit_support_carter
 
Posts: 14475
Joined: Tue Nov 29, 2016 2:45 pm

Re: pyportal pynt does not connect to WiFi

by evanthomas on Fri Jan 31, 2020 4:52 am

Both portals are running CP 4.1.2 and 4.x libraries. Both are firmware 1.2.2. Both are running the same code.py. Both fail in the same way - but not at the same time.

I have copied the code below. As you can see, it connects using the code in esp32spi_simpletest.py. It then loops, polling an endpoint with the requests library (line 94). It will retry on error and for most error types that seems to work. But if it gets:

Timed out waiting for SPI char

it never recovers.

It typically gets this after about an hour but I don't have accurate data. It's not a problem with the endpoint or my network because other clients don't have this problem.

Thanks,
Evan.

Code: Select all | TOGGLE FULL SIZE
import time
import board
import gc
import supervisor
# from adafruit_pyportal import PyPortal
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text.label import Label
import displayio
import busio
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
import adafruit_requests as requests
from secrets import secrets

# Set up where we'll be fetching data from
DATA_SOURCE = "http://192.168.0.24/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System"

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

board.DISPLAY.auto_brightness = False
board.DISPLAY.brightness = 1

# load font(s)
fontb = bitmap_font.load_font(cwd+"/fonts/Helvetica-Bold-36.bdf")
fontb.load_glyphs(b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()')
fonts = bitmap_font.load_font(cwd+"/fonts/Helvetica-Bold-24.bdf")
fonts.load_glyphs(b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()')

# Make the display context
splash = displayio.Group(max_size=200)
board.DISPLAY.show(splash)

# Build the screen early to hide the diagnostic output.
color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x3D0068

h = Label(fontb, text='Solar status', color=0x5555FF, max_glyphs=40)
h.x = 50
h.y = 35
splash.append(h)

c = Label(fonts, text='Current: --', color=0x55FF55, max_glyphs=40)
c.x = 60
c.y = 110
splash.append(c)

t = Label(fonts, text='Today:   --', color=0x55FF55, max_glyphs=40)
t.x = 60
t.y = 140
splash.append(t)


# Start WiFi
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_gpio0 = DigitalInOut(board.ESP_GPIO0)
esp32_reset = DigitalInOut(board.ESP_RESET)
esp32_cs = DigitalInOut(board.ESP_CS)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset, esp32_gpio0)

requests.set_socket(socket, esp)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])

for ap in esp.scan_networks():
    print("\t%s\t\tRSSI: %d" % (str(ap['ssid'], 'utf-8'), ap['rssi']))

print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets['ssid'], secrets['password'])
    except RuntimeError as e:
        print("could not connect to AP, retrying: ",e)
        continue
print("Connected to", str(esp.ssid, 'utf-8'), "\tRSSI:", esp.rssi)
print("My IP address is", esp.pretty_ip(esp.ip_address))
print("IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com")))
print("Ping google.com: %d ms" % esp.ping("google.com"))

total = 0
current = 0
error_cnt = 0
last_error = None
while True:
  try:
    gc.collect()
    r = requests.get(DATA_SOURCE, timeout=5)
    json = r.json()
    current = json['Body']['Data']['PAC']['Values']['1']
    total = json['Body']['Data']['DAY_ENERGY']['Values']['1']
    print("Response is current={current}W, total={total}Wh".format(current=current, total=total))

    error_cnt = 0
    last_error = None

  except RuntimeError as e:
    current_error = str(e)
    print("Error: ", current_error)
    current = 0

    if current_error == last_error:
      error_cnt += 1
      if error_cnt == 5:
        print("Same error {last_error} times, restarting.".format(last_error=last_error))
        supervisor.reload()
    else:
      last_error = current_error
      error_cnt = 1


  c.text = 'Current: {current}W'.format(current=current)
  t.text = 'Today:   {total}kWh'.format(total=round(total/1000))

  time.sleep(10)


evanthomas
 
Posts: 10
Joined: Sun Jan 26, 2020 11:11 pm

Re: pyportal pynt does not connect to WiFi

by adafruit2 on Fri Jan 31, 2020 11:44 pm

you may want to try a better power supply - it could be that voltage fluctuations are confusing the ESP32. use a short, quality USB cable and connect to your computer motherboard.

adafruit2
Site Admin
 
Posts: 19043
Joined: Fri Mar 11, 2005 7:36 pm

Please be positive and constructive with your questions and comments.