Picoweb on ESP32 access point

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
MrExplore
Posts: 3
Joined: Sat Mar 06, 2021 1:57 pm

Picoweb on ESP32 access point

Post by MrExplore » Sun Mar 07, 2021 5:53 pm

Hi All,

I'm a micropython newbie and I just started playing around on an ESP32 Cam (AIThinker)

The (very basic) code below works. The ESP connects to my wifi, I can access it and get the 'hello world' response from picoweb.

However, I would like to set it up as an access point, see the code commented out below. When I use this code, I have a password protected access point and I can connect my phone to the access point. But I get no response from 192.168.4.1:80

So how can I get picoweb to behave properly on an accesspoint ?

Thanks !

Code: Select all

import network
import picoweb

# =========================================================
# Connect to WiFi router

wifi = network.WLAN(network.STA_IF)
wifi.active(True)
wifi.connect('MySSID', 'MyPassword')

while not wifi.isconnected():
    pass

# =========================================================
# Setup as access point

# wifi = network.WLAN(network.AP_IF)
# wifi.active(True)
# wifi.config(essid='esp32', authmode=3, password='12345678')
# 
# while not wifi.active():
#   pass

# =========================================================

print('ESP online @' + wifi.ifconfig()[0])

app = picoweb.WebApp(__name__)

@app.route('/')
def index(req, resp):
    yield from picoweb.start_response(resp)
    yield from resp.awrite('Hey hello there!')

app.run(debug=True, host=wifi.ifconfig()[0], port=80)

User avatar
CmdrDeLiver
Posts: 27
Joined: Thu Dec 05, 2019 6:30 pm

Re: Picoweb on ESP32 access point

Post by CmdrDeLiver » Fri Mar 12, 2021 2:35 pm

Suggestion that may or may not resolve the issue. Replace

Code: Select all

# while not wifi.active():
#   pass
with

Code: Select all

# while not wifi.active():
#   utime.sleep(0.1)
The first is a tight loop. It should work, but I've found some instances on ESP where it didn't. The second gives up the processor without question and allows background processes to occur.

I'd also put a time.sleep(5) before

Code: Select all

app = picoweb.WebApp(__name__)
If those don't resolve the issue, post the output of the serial debug here in AP mode and maybe something will click.

MrExplore
Posts: 3
Joined: Sat Mar 06, 2021 1:57 pm

Re: Picoweb on ESP32 access point

Post by MrExplore » Sun Mar 14, 2021 3:02 pm

Thanks for the reply, I tried both your suggestions and it works :)

However, I was curious about which of the two did the trick. Turns out the original code now works without the modifications. I can now stream the cam to my phone when the esp cam is in accesspoint mode.

My best guess why it didn't work is that I was running it on battery (3.3 volts). I tried to verify but now at 3.3v the access point isn't showing up on my phone. So yeah, this might be a power issue (?)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Picoweb on ESP32 access point

Post by pythoncoder » Mon Mar 15, 2021 9:15 am

Power issues are common on ESP32: when it accesses WiFi the current consumption goes up, which can result in voltage drops.
Peter Hinch
Index to my micropython libraries.

stanely
Posts: 55
Joined: Fri Jan 17, 2020 5:19 am
Location: Ohio, USA

Re: Picoweb on ESP32 access point

Post by stanely » Sat Mar 27, 2021 1:18 pm

I just ran into this power problem, and my ESP32 would throw a "Brownout detector was triggered" message in the REPL. Many Chinese ESP32 boards use a 4B2X voltage regulator that can only supply 150mA. ESP32 specs suggest a minimum of 500mA supply current. If you look at the WiFi power requirements you see that the transmitter needs as much as 240mA. (Full duplex receive + transmit power is 340mA at 50% duty cycle, see pg. 44 of https://www.espressif.com/sites/default ... eet_en.pdf)

Higher end boards like the Lolin 32 Pro use an ME6211 regulator which can source the full 500mA the ESP32 needs.

I guess there's a way to control WiFi transmitter power in software, but I don't know how to do that. So, I'm curtailing the use of cheap ESP32s because who wants WiFi disconnects in the field?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Picoweb on ESP32 access point

Post by pythoncoder » Sun Mar 28, 2021 9:36 am

My opinion of much Chinese hardware is unfit for family viewing ;)

That said, for reliability every aspect of ESP32 power needs attention. Cheap wall-warts and lossy USB leads can cause trouble, even with a good quality board.
Peter Hinch
Index to my micropython libraries.

wangshujun@tom.com
Posts: 61
Joined: Fri Feb 15, 2019 9:22 am

Re: Picoweb on ESP32 access point

Post by wangshujun@tom.com » Tue Apr 06, 2021 3:14 am

In fact, the main reason is that the resistance of the USB cable is too large, most of which will be solved by replacing a high-quality USB cable when under voltage error occurs. Of course, a capacitor of more than 200uf in parallel between GND and V5 can also solve many problems

Post Reply