WiFi connect problem with esp32?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
Aduka_27
Posts: 27
Joined: Thu Apr 14, 2022 11:00 am

WiFi connect problem with esp32?

Post by Aduka_27 » Fri Apr 22, 2022 10:54 am

Hi guys,
I have a problem with the connection to my WiFi network. Before I used FiPy Pycom board and this works:

Code: Select all

#wifi = WLAN(mode=WLAN.STA_IF)
#wifi.connect(ssid="my_network", auth=(WLAN.WPA2, 'my_pass'))
#while not wifi.isconnected():
    #print("I am in idle state!")
    #machine.idle()
#print("WiFi is up!")
#print(wifi.ifconfig())
First I tried the same code and it did not work. Then I found on MicroPyhon website that the definition is a bit different. Then I tried with this code but again every time it suggest me that the problem is with this part where I define essid and password:

Code: Select all

wlan = network.WLAN(network.STA_IF)
wlan.connect(essid='my_network', password='my_password')

while not wlan.isconnected():
    print("I am in idle state!")
    machine.idle()
print("WiFi is up!")
print(wlan.ifconfig())
time.sleep(1)
What is the issue here? :(

Aduka_27
Posts: 27
Joined: Thu Apr 14, 2022 11:00 am

Re: WiFi connect problem with esp32?

Post by Aduka_27 » Fri Apr 22, 2022 12:47 pm

I solved this issue by implementing this part:

Code: Select all

ssid="my_network"
password = "my_pass"


wlan = network.WLAN(network.STA_IF)
wlan.active(False)
time.sleep(1)

wlan.active(True)
wlan.connect(ssid, password)

while not wlan.isconnected():
    print("I am in idle state!")
    machine.idle()
print("WiFi is up!")
print(wlan.ifconfig())
time.sleep(1)
But now I have a problem to open image (jpg format). I am using standard filesystem functions that should enable me this functionality:

Code: Select all

FNAME = 'image2.jpg'
 f = open(FNAME, 'rb')
m = f.read()
 f.close()
Does anybody know where is the issue here? I am getting this error:

Code: Select all

Unhandled exception in thread started by <function client_thread at 0x3ffcf140>
Traceback (most recent call last):
  File "main.py", line 31, in client_thread
OSError: [Errno 2] ENOENT
Thanks in advance! :D

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: WiFi connect problem with esp32?

Post by marcidy » Sun Apr 24, 2022 1:51 am

File "main.py", line 31, in client_thread
OSError: [Errno 2] ENOENT
Are you sure the file is being saved in the location you are attempting to access? ENOENT means no such file or directory. you can use the os module to examine the file system.

Aduka_27
Posts: 27
Joined: Thu Apr 14, 2022 11:00 am

Re: WiFi connect problem with esp32?

Post by Aduka_27 » Mon Apr 25, 2022 9:25 am

Same concept with '.txt' files works without problems. Maybe f.open('.jpg') is not supported by pure MicroPython?

User avatar
Roberthh
Posts: 3668
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: WiFi connect problem with esp32?

Post by Roberthh » Mon Apr 25, 2022 10:26 am

open() does not care about the file name. The file has to exist at the given path with exactly that name. But maybe it's the size of the file which causes f.read() to fail.

Aduka_27
Posts: 27
Joined: Thu Apr 14, 2022 11:00 am

Re: WiFi connect problem with esp32?

Post by Aduka_27 » Mon Apr 25, 2022 10:43 am

That can be as well. This code was tested on FiPy and it worked, I was able to see the captured image in my browser. I am trying the same with esp32-wroom 32 but seems this one cannot support that, which can also be related to the file size...don't know :roll:

Post Reply