access point setup on boot

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
kermit
Posts: 3
Joined: Thu Aug 10, 2017 7:42 pm

access point setup on boot

Post by kermit » Fri Aug 11, 2017 2:48 pm

Hello,
I am new here so in the beginning i want to thank you guys for awesome work that you`ve done. Currently i work on project that requires esp module to setup as access point as esp8266 did, but as i can see esp32(i use esp-wroom-32 to be precise) doesn`t do that i suspect that is because webrepl is not implemented yet, but is there way to enable wifi in access point mode in current stage ?
Greetings ;)

update:
i think that is the case, when i try to import network module from repl i get error like this:

>>> import network
E (64192) wifi: invalid magic number 3ffcf140, call WIFI_INIT_CONFIG_DEFAULT to init config
E (64192) wifi: wifi_init 1361 ret=258
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: Wifi Invalid Argument


so maybe that is why the access point is not starting ?

kermit
Posts: 3
Joined: Thu Aug 10, 2017 7:42 pm

Re: access point setup on boot

Post by kermit » Sat Aug 12, 2017 8:28 am

Next edit. As i done further research i discovered that when i flash with today`s daily build: http://micropython.org/resources/firmwa ... c00f0d.bin network module works fine, but this didn`t solve my problem as i want to add some modules as frozen bytecode so i need to built it by myself, so question is how to deal with this error or where i can get code from which today`s built was done. I built my binary from latest git repo: https://github.com/micropython/micropython-esp32 , maybe checkout to older version will help but i don`t know to which commit i should checkout.

cokegen
Posts: 1
Joined: Wed Aug 16, 2017 7:58 pm

Re: access point setup on boot

Post by cokegen » Thu Aug 17, 2017 1:12 pm

Just bought a couple esp-wroom-32 modules the other day and started playing with them since the idea was to start learning Python (the hard way probably ?) and stumbled with the same problem as you.

Also tried the binary firmware the MicroPython guys currently provide at:

https://micropython.org/resources/firmw ... ad3fdb.bin

and it worked like a charm, but that leaves you without the ability to "tune" the firmware, as you correctly said in your post.

An lsb_release -a reports "Linux Mint 18 Sarah" for me, which is a base of Ubuntu Xenial to the best of my knowledge.

Did some git-fu and stole some of the versions this guy used in his video https://youtu.be/qa2406iiSbI (Adafruit Tony D)

My setup (everything goes under my home ~/esp/directories_here and following official instructions):

# xtensa-esp32-elf
- version = https://dl.espressif.com/dl/xtensa-esp3 ... 2.0.tar.gz
- just uncompress

# esp-idf
- version = tags/v2.0-rc1-22-gb8e2edc @ b8e2edc99f369eaa069e478604c47907972b2585
- ran a "git submodule update --recursive" inside the esp-idf/ directory, this is important apparently since it checks out additional esp32 code like I show below:

~/esp/esp-idf $ git submodule update --recursive
Submodule path 'components/bt/lib': checked out '9c1eea6bb03adc3b3847fff79c3f017652840a46'
Submodule path 'components/esp32/lib': checked out '45414a6778e1bf2855f18a8c6b954d5cf575bb40'
Submodule path 'components/esptool_py/esptool': checked out 'e9e9179f6fc3f2ecfc568987d3224b5e53a05f06'

# micropython-esp32
- version = tags/v1.8.7-259-g975df68 @ 975df68fac1885b4a7d27bf54dab47c74a0e2d36
- created micropython-esp32/esp32/makefile (case being important since there's also a Makefile there) with the following content (replace accordingly):

ESPIDF = /home/replaceme/esp/esp-idf
PORT = /dev/ttyUSB0
FLASH_MODE = dio
FLASH_SIZE = 4MB
#CROSS_COMPILE = xtensa-esp32-elf-

- ran "make -C mpy-cross" inside the micropython-esp32/ folder and then just a "make" inside micropython-esp32/esp32
- ran "make erase" (to erase the flash, since this is what they recommend to always do)
- ran "make deploy" (to flash the firmware)

The REPL works fine and the wifi seems to initialize now, with proof going below:

>>>
PYB: soft reboot
could not open file 'boot.py' for reading
could not open file 'main.py' for reading
MicroPython v1.8.7-259-g975df68-dirty on 2017-08-17; ESP32 module with ESP32
Type "help()" for more information.
>>> import network
>>> wlan = network.WLAN(network.STA_IF)
>>> wlan.active(True)
True
>>> wlan.scan()
I (1703272) wifi: event 1
[(b'removed', b'removed', 2, -45, 3, False)]
>>> print("cool !")
cool !
>>>

There it goes my first post ! hope to be of help and please let me know how that went for you ...

kermit
Posts: 3
Joined: Thu Aug 10, 2017 7:42 pm

Re: access point setup on boot

Post by kermit » Sat Aug 19, 2017 10:28 am

Hey, thanks Cokegen for your detailed answer, unfortunately last days i didn`t had time to check your solution, but i will do it as soon as possible and post result here. As i needed fast solution for this problem, i dealed with it by flashing my board with daily build and simply uploading needed scripts, fortunately there was enough memory to do this, but probably for production i should go with frozen bytecode so i will try your solution. Meanwhile you can check github, NyxMC posted same issue and found solution for it, but i didn`t check it yet : https://github.com/micropython/micropyt ... issues/163

sudhanchal@gmail.com
Posts: 1
Joined: Sat Dec 23, 2017 6:20 am

Re: access point setup on boot

Post by sudhanchal@gmail.com » Mon Dec 25, 2017 6:43 am

I want to communicate with an ESP32 from my mobile app. Ihave the following micropython code:
import network
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid='ESP32')
ap.config(authmode=3, password='123456789')

In this code the access point is created and it is visible in my Android mobile.
But when connect my mobile to the access point it is showing the “saved” message instead of “connected” even though I have entered the correct password.
I followed the same procedure using Arduino code and I was able to connect my mobile with the access point created bythe ESP32. Any help is highly appreciated

Capstan
Posts: 99
Joined: Sun Jan 29, 2017 4:03 pm
Location: Texas, USA

Re: access point setup on boot

Post by Capstan » Thu Dec 28, 2017 6:05 am

I tried that exact code just now on an ESP32 development board with a WROOM-32 and it worked. Was able to see the access point on my phone and connect.

OutoftheBOTS_
Posts: 300
Joined: Mon Nov 20, 2017 10:18 am

Re: access point setup on boot

Post by OutoftheBOTS_ » Thu Dec 28, 2017 9:31 am

I am quite new to MicroPython and ESP boards but this si what I did

I only used the first 2 lines of code to activate the AP and connect to it with my PC

ap = network.WLAN(network.AP_IF)
ap.active(True)

If you want it to do this on every boot just add it to the boot.py most people also seem to add a bit of error checking too to make sure ap.active returns true and may also include ap_if.ifconfig() to write the IP address to the serial console.

Hope this helped and I hope my advice is correct as I am also new to the platform :)

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

Re: access point setup on boot

Post by pythoncoder » Sat Dec 30, 2017 8:35 am

OutoftheBOTS_ wrote:
Thu Dec 28, 2017 9:31 am
...If you want it to do this on every boot just add it to the boot.py...
In general user code should go in main.py. Putting code in boot.py can lead to problems if you make a mistake, in the worst case requiring the firmware to be re-flashed. By contrast a defective main.py can be interrupted with ctrl-C.
Peter Hinch

OutoftheBOTS_
Posts: 300
Joined: Mon Nov 20, 2017 10:18 am

Re: access point setup on boot

Post by OutoftheBOTS_ » Sat Dec 30, 2017 9:12 pm

I am quite new to this platform but what I have been doing is putting all my setup stuff that I always want to do in boot.py and using main.py for if I want to start a program headless automatically on boot up then I will rename the program too main.py.

I am doing lots of experimenting so am constantly trying different options in firmware anyway and re-flashing firmware only takes a few seconds

Post Reply