jonask1337 / esp-lwip

ESP-IDF lwIP library with NAT
Other
53 stars 10 forks source link

Comprehensive Guide in Building #6

Closed proDev-Theron closed 4 years ago

proDev-Theron commented 4 years ago

I already installed the idf [https://github.com/espressif/esp-idf] and I'm sure because I can run it image. The only thing missing is how to build the edited main.c and flash it to the esp32 board. I hope you can make a comprehensive guide, preferably with video or screenshot.

proDev-Theron commented 4 years ago

image I think I'm making progress. Forgive me for I'm such a newbie. I'm still hoping for a comprehensive guide.

proDev-Theron commented 4 years ago

image I ran idf.py app I hope I can make this work soon. though I've been waiting for 10 minutes already, I hope it's building now.

proDev-Theron commented 4 years ago

image I think I already built and flashed this to the ESP32 board, but nothing happens. It's not yet connected to the router nor displaying an Access Point to other devices.

image

proDev-Theron commented 4 years ago

I think It's done. image Though no one answered me, I want to thank the author for this post. Finally after days of searching and an hour of installing and configuring idf. Next step I want to know is how can I monitor it remotely.

Thank you again @jonask1137

Sze-Huang commented 4 years ago

Can you make a comprehensive guide based on what you did? I am new to this too

proDev-Theron commented 4 years ago

I just figured it out a while ago and the process just took me an hour all in all. I update here live despite of the slow internet connection.

First I did was to download esp-idf(link in the first post) I just read the docs on how to install. This is where I spent most of my time because of big file sizes you'll need to download.

Then proceed to copying @jonask1337 lwip to esp-idf/components/lwip folder as he instructed in the original post.

Clone the example he provided and modify it according to your needs

After that just build it and flash to your esp32 Instructions are on esp-idf docs

proDev-Theron commented 4 years ago

I guess we're on the same time zone, please do yourself a favor, sleep.

jonask1337 commented 4 years ago

Hi, does everything work for you now? Sorry that the installation caused problems, I will add a more detailed installation guide in the next days.

Sze-Huang commented 4 years ago

I am able to do all the steps following the instructions. But I dont have connection to the internet. Anyway to debug it?

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6356
load:0x40078000,len:11624
load:0x40080400,len:6648
entry 0x40080764
I (28) boot: ESP-IDF v3.3-dirty 2nd stage bootloader
I (28) boot: compile time 03:15:01
I (28) boot: Enabling RNG early entropy source...
I (33) boot: SPI Speed      : 40MHz
I (37) boot: SPI Mode       : DIO
I (41) boot: SPI Flash Size : 4MB
I (45) boot: Partition Table:
I (49) boot: ## Label            Usage          Type ST Offset   Length
I (56) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (64) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (71) boot:  2 factory          factory app      00 00 00010000 00100000
I (79) boot: End of partition table
I (83) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x17e08 ( 97800) map
I (126) esp_image: segment 1: paddr=0x00027e30 vaddr=0x3ffb0000 size=0x0301c ( 12316) load
I (131) esp_image: segment 2: paddr=0x0002ae54 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at C:/Users/huang/Desktop/esp/esp-idf/components/freertos/xtensa_vectors.S:1779

I (133) esp_image: segment 3: paddr=0x0002b25c vaddr=0x40080400 size=0x04db4 ( 19892) load
I (150) esp_image: segment 4: paddr=0x00030018 vaddr=0x400d0018 size=0x667cc (419788) map
0x400d0018: _stext at ??:?

I (298) esp_image: segment 5: paddr=0x000967ec vaddr=0x400851b4 size=0x0a888 ( 43144) load
0x400851b4: set_most_pwr_reg at /home/aiqin/git_tree/chip7.1_phy/chip_7.1/board_code/app_test/pp/phy/phy_chip_v7.c:1355

I (325) boot: Loaded app from partition at offset 0x10000
I (326) boot: Disabling RNG early entropy source...
I (326) cpu_start: Pro cpu up.
I (330) cpu_start: Application information:
I (334) cpu_start: Project name:     esp-idf-nat-example
I (340) cpu_start: App version:      ab495ce-dirty
I (346) cpu_start: Compile time:     Jan  9 2020 03:15:39
I (352) cpu_start: ELF file SHA256:  759249f08790797c...
I (358) cpu_start: ESP-IDF:          v3.3-dirty
I (363) cpu_start: Starting app cpu, entry point is 0x400810d0
0x400810d0: call_start_cpu1 at C:/Users/huang/Desktop/esp/esp-idf/components/esp32/cpu_start.c:270

I (0) cpu_start: App cpu up.
I (374) heap_init: Initializing. RAM available for dynamic allocation:
I (380) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (386) heap_init: At 3FFB8F38 len 000270C8 (156 KiB): DRAM
I (393) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (399) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (405) heap_init: At 4008FA3C len 000105C4 (65 KiB): IRAM
I (412) cpu_start: Pro cpu start user code
I (94) cpu_start: Chip Revision: 1
W (95) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.
I (98) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (223) wifi: wifi driver task: 3ffc0b94, prio:23, stack:3584, core=0
I (223) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (223) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (253) wifi: wifi firmware version: aeed694
I (253) wifi: config NVS flash: enabled
I (253) wifi: config nano formating: disabled
I (253) wifi: Init dynamic tx buffer num: 32
I (263) wifi: Init data frame dynamic rx buffer num: 32
I (263) wifi: Init management frame dynamic rx buffer num: 32
I (273) wifi: Init management short buffer num: 32
I (273) wifi: Init static rx buffer size: 1600
I (283) wifi: Init static rx buffer num: 10
I (283) wifi: Init dynamic rx buffer num: 32
I (303) wifi apsta: DNS IP:8.8.8.8
I (393) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0
I (393) wifi: mode : sta (3c:71:bf:f1:31:24) + softAP (3c:71:bf:f1:31:25)
I (403) wifi: Total power save buffer number: 16
I (403) wifi: Init max length of beacon: 752/752
I (403) wifi: Init max length of beacon: 752/752
I (413) wifi apsta: wifi_init_apsta finished.
I (413) wifi apsta: connect to ap SSID: W6315R
I (533) wifi: ap channel adjust o:1,1 n:5,1
I (533) wifi: new:<5,1>, old:<1,0>, ap:<5,1>, sta:<5,1>, prof:1
I (533) wifi: state: init -> auth (b0)
I (543) wifi: state: auth -> assoc (0)
I (543) wifi: state: assoc -> run (10)
I (573) wifi: connected with W6315R, channel 5, 40U, bssid = 88:10:8f:21:35:94
I (583) wifi: pm start, type: 1

I (2703) event: sta ip: 192.168.8.129, mask: 255.255.255.0, gw: 192.168.8.1
I (2703) wifi apsta: got ip:192.168.8.129
I (4413) wifi: new:<5,1>, old:<5,1>, ap:<5,1>, sta:<5,1>, prof:5
I (4413) wifi: station: e0:dc:ff:cb:a0:d3 join, AID=1, bgn, 20
I (4443) wifi apsta: station connected
I (6503) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
jonask1337 commented 4 years ago

@Sze-Huang Looks like NAT is not enabled. If the lwIP library with NAT is used correctly by the ESP-IDF there should be a "NAT is enabled" message in the log.

Did you clone the lwIP library with NAT or did you just download it? It is only working if you clone the lwIP library with NAT and copy the repository to /esp-idf/component/lwip (after renaming or deleting the old /esp-idf/component/lwip/lwip directory).

So make sure you do the following steps:

  1. Get the lwIP library with NAT git clone https://github.com/jonask1337/esp-lwip.git
  2. Rename or delete original lwIP library folder (/esp-idf/component/lwip/lwip)
  3. Copy the lwIP library with NAT repository folder from step 1 to /esp-idf/component/lwip and rename it to lwip.
  4. Build and flash the example project again.
jonask1337 commented 4 years ago

I added a short instruction for the setup of the project to the readme here: https://github.com/jonask1337/esp-idf-nat-example

I hope this can clarify the installation process for you. If there are any suggestions for improvement please let me know.

Sze-Huang commented 4 years ago

I understood step 2 wrongly and deleted /esp-idf/component/lwip folder. I had redo again, but still unsuccessful. Still no connection to the internet.

$ make monitor ESPPORT=COM5
WARNING: esp-idf git submodule components/lwip/lwip may be out of date. Run 'git submodule update' in IDF_PATH dir to update.
Toolchain path: /opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: crosstool-ng-1.22.0-80-g6c4433a5
Compiler version: 5.2.0
Python requirements from C:/Users/huang/Desktop/esp/esp-idf/requirements.txt are satisfied.
MONITOR
--- idf_monitor on COM5 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6356
load:0x40078000,len:11624
load:0x40080400,len:6648
entry 0x40080764
I (28) boot: ESP-IDF v3.3-dirty 2nd stage bootloader
I (28) boot: compile time 04:34:33
I (28) boot: Enabling RNG early entropy source...
I (33) boot: SPI Speed      : 40MHz
I (37) boot: SPI Mode       : DIO
I (41) boot: SPI Flash Size : 4MB
I (45) boot: Partition Table:
I (49) boot: ## Label            Usage          Type ST Offset   Length
I (56) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (64) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (71) boot:  2 factory          factory app      00 00 00010000 00100000
I (79) boot: End of partition table
I (83) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x17da0 ( 97696) map
I (126) esp_image: segment 1: paddr=0x00027dc8 vaddr=0x3ffb0000 size=0x03020 ( 12320) load
I (131) esp_image: segment 2: paddr=0x0002adf0 vaddr=0x40080000 size=0x00400 (  1024) load
0x40080000: _WindowOverflow4 at C:/Users/huang/Desktop/esp/esp-idf/components/freertos/xtensa_vectors.S:1779

I (133) esp_image: segment 3: paddr=0x0002b1f8 vaddr=0x40080400 size=0x04e18 ( 19992) load
I (150) esp_image: segment 4: paddr=0x00030018 vaddr=0x400d0018 size=0x6777c (423804) map
0x400d0018: _stext at ??:?

I (299) esp_image: segment 5: paddr=0x0009779c vaddr=0x40085218 size=0x0a824 ( 43044) load
0x40085218: bb_wdt_int_enable at /home/aiqin/git_tree/chip7.1_phy/chip_7.1/board_code/app_test/pp/phy/phy_chip_v7.c:1355

I (327) boot: Loaded app from partition at offset 0x10000
I (327) boot: Disabling RNG early entropy source...
I (327) cpu_start: Pro cpu up.
I (331) cpu_start: Application information:
I (336) cpu_start: Project name:     esp-idf-nat-example
I (342) cpu_start: App version:      ab495ce-dirty
I (347) cpu_start: Compile time:     Jan  9 2020 04:35:01
I (353) cpu_start: ELF file SHA256:  a5209b6d6fddb122...
I (359) cpu_start: ESP-IDF:          v3.3-dirty
I (364) cpu_start: Starting app cpu, entry point is 0x400810d0
0x400810d0: call_start_cpu1 at C:/Users/huang/Desktop/esp/esp-idf/components/esp32/cpu_start.c:270

I (0) cpu_start: App cpu up.
I (375) heap_init: Initializing. RAM available for dynamic allocation:
I (382) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (388) heap_init: At 3FFB8F58 len 000270A8 (156 KiB): DRAM
I (394) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (400) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (407) heap_init: At 4008FA3C len 000105C4 (65 KiB): IRAM
I (413) cpu_start: Pro cpu start user code
I (96) cpu_start: Chip Revision: 1
W (96) cpu_start: Chip revision is higher than the one configured in menuconfig. Suggest to upgrade it.
I (99) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (225) wifi: wifi driver task: 3ffc3e18, prio:23, stack:3584, core=0
I (225) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (225) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
I (255) wifi: wifi firmware version: aeed694
I (255) wifi: config NVS flash: enabled
I (255) wifi: config nano formating: disabled
I (255) wifi: Init dynamic tx buffer num: 32
I (265) wifi: Init data frame dynamic rx buffer num: 32
I (265) wifi: Init management frame dynamic rx buffer num: 32
I (275) wifi: Init management short buffer num: 32
I (275) wifi: Init static rx buffer size: 1600
I (285) wifi: Init static rx buffer num: 10
I (285) wifi: Init dynamic rx buffer num: 32
I (305) wifi apsta: DNS IP:8.8.8.8
I (395) phy: phy_version: 4102, 2fa7a43, Jul 15 2019, 13:06:06, 0, 0
I (395) wifi: mode : sta (3c:71:bf:f1:31:24) + softAP (3c:71:bf:f1:31:25)
I (405) wifi: Total power save buffer number: 16
I (405) wifi: Init max length of beacon: 752/752
I (405) wifi: Init max length of beacon: 752/752
I (415) wifi apsta: wifi_init_apsta finished.
I (415) wifi apsta: connect to ap SSID: W6315R
I (425) wifi apsta: NAT is enabled
I (535) wifi: ap channel adjust o:1,1 n:5,1
I (535) wifi: new:<5,1>, old:<1,0>, ap:<5,1>, sta:<5,1>, prof:1
I (535) wifi: state: init -> auth (b0)
I (545) wifi: state: auth -> assoc (0)
I (545) wifi: state: assoc -> run (10)
I (585) wifi: connected with W6315R, channel 5, 40U, bssid = 88:10:8f:21:35:94
I (585) wifi: pm start, type: 1

I (2705) event: sta ip: 192.168.8.129, mask: 255.255.255.0, gw: 192.168.8.1
I (2705) wifi apsta: got ip:192.168.8.129
I (34015) wifi: new:<5,1>, old:<5,1>, ap:<5,1>, sta:<5,1>, prof:5
I (34015) wifi: station: e0:dc:ff:cb:a0:d3 join, AID=1, bgn, 20
I (34065) wifi apsta: station connected
I (34235) tcpip_adapter: softAP assign IP to station,IP is: 192.168.4.2
jonask1337 commented 4 years ago

@Sze-Huang Ok, NAT seems to be enabled now. Did you set the "Enable copy between Layer2 and Layer3 packets" option via menuconfig? (Just added this step to the Readme of the esp-idf-nat-example project because it was only in the Readme of the lwIP library)

Sze-Huang commented 4 years ago

@jonask1337 Thanks for the help! I am now able to connect to the internet after the menuconfig steps, guessed I missed that too. Appreciate your detailed instruction :)

proDev-Theron commented 4 years ago

@Sze-Huang Looks like NAT is not enabled. If the lwIP library with NAT is used correctly by the ESP-IDF there should be a "NAT is enabled" message in the log.

Did you clone the lwIP library with NAT or did you just download it? It is only working if you clone the lwIP library with NAT and copy the repository to /esp-idf/component/lwip (after renaming or deleting the old /esp-idf/component/lwip/lwip directory).

So make sure you do the following steps:

  1. Get the lwIP library with NAT git clone https://github.com/jonask1337/esp-lwip.git
  2. Rename or delete original lwIP library folder (/esp-idf/component/lwip/lwip)
  3. Copy the lwIP library with NAT repository folder from step 1 to /esp-idf/component/lwip and rename it to lwip.
  4. Build and flash the example project again.

I guess it's better if it will be visible on the README Thank you @jonask1337

proDev-Theron commented 4 years ago

Here's mine for the mean time: I put it inside an old flashlight for protection against water and dust. I used a 5V battery from an old bluetooth headset connected to VIN and GND but I think I'm hurting the board so I switched to using power bank connected to the USB port.

I want to add functions such as: 》blinking the other built in LED when there is data transfer 》Signal strength represented by LEDs in the GPIOs 》Live Monitoring via Web Browser (bandwidth, connected clients and their MAC Addresses, Plot Monitor of Current Speed, etc.) PS: I plugged this repo on a facebook group. Some showed interest about this project. They're asking for code so I referred them here. @jonask1337 https://www.facebook.com/groups/esp8266microcontrollers/833783540404465/?comment_id=833801633735989&notif_id=1578591678996951

81872346_2683534401736650_5253150765748322304_o 81994150_2683535565069867_4377011002533740544_o 81766673_2683575511732539_5583478439945437184_o 82369128_2683540451736045_1645869753165676544_o

jonask1337 commented 4 years ago

@proDev-Theron Thanks for your feedback and sharing your project status! It is always interesting to see what other people come up with. ;)

I updated the Readme. For a detailed instruction I would refer to the Readme of the https://github.com/jonask1337/esp-idf-nat-example project. It should be easier to follow now...