elcritch / esp32_nim_net_example

esp32_nim_net_example
4 stars 1 forks source link

Simple wifi example #2

Closed stisa closed 4 years ago

stisa commented 4 years ago

A basic example that connects to wifi and starts an http server. The c code is a little hacked together, but it seems to work.

Still crashes after a few requests, probably due to ARC:

wifi setup!
Wait for wifi
running server
starting http server on port 8181
req #1
req #2
req #3
req #4
req #5
req #6
req #7
req #8
req #9
req #10
req #11
req #12
req #13
req #14
req #15
req #16
req #17
req #18
req #19
req #20
req #21
req #22
req #23
req #24
req #25
req #26
req #27
Guru Meditation Error: Core  0 panic'ed (StoreProhibited). Exception was unhandled.
Core 0 register dump:
PC      : 0x4000c46c  PS      : 0x00060d30  A0      : 0x80100bf4  A1      : 0x3ffbb6b0
A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000048  A5      : 0x00000000
A6      : 0x00000038  A7      : 0x00000004  A8      : 0x800950e8  A9      : 0x3ffbb680
A10     : 0x00000000  A11     : 0x0000000c  A12     : 0x3f4050d8  A13     : 0x3fffff54
A14     : 0x00000001  A15     : 0x00000003  SAR     : 0x00000000  EXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000  LBEG    : 0x4000c46c  LEND    : 0x4000c477  LCOUNT  : 0x00000003

ELF file SHA256: c547ee7fdc868918

Backtrace: 0x4000c469:0x3ffbb6b0 0x40100bf1:0x3ffbb6c0 0x400f68af:0x3ffbb710 0x400ee5c9:0x3ffbb760 0x400e74b1:0x3ffbb810 0x400d961d:0x3ffbb870 0x400da8c6:0x3ffbb8e0 0x400da951:0x3ffbbcd0 0x400da9dc:0x3ffbbd10 0x400d709d:0x3ffbbd50 0x400d7139:0x3ffbbda0 0x400d714f:0x3ffbbde0 0x400d71d5:0x3ffbbe00 0x400d5ce9:0x3ffbbe30 0x400d1e5a:0x3ffbbe50 0x4009219d:0x3ffbbe70
0x40100bf1: nimSetMem__JE6t4x7Z3v2iVz27Nx0MRAmemory at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_system.nim.c:954
 (inlined by) nimZeroMem at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_system.nim.c:959
 (inlined by) nimNewObj at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_system.nim.c:2192

0x400f68af: recvLineInto__oM6RSAsSAZHNSzsm0Xjbbg at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_asyncnet.nim.c:3041

0x400ee5c9: processRequestIter__9bFW7o03uH9aU8ZP0CEQpILA_3 at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_asynchttpserver.nim.c:2906

0x400e74b1: processRequestNimAsyncContinue__0f5XHRBN20CBOjiT69cdDnQ at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_asynchttpserver.nim.c:4217

0x400d961d: processPendingCallbacks__xdICRvJ1ns9byYHPjM07uJQ at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_asyncdispatch.nim.c:1711 (discriminator 1)

0x400da8c6: runOnce__nEnn7ilZ6aSkcXTtLEKnJA at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_asyncdispatch.nim.c:1941

0x400da951: poll__wcvh7vf5dGU1VYto9aiAnpA at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_asyncdispatch.nim.c:1965

0x400da9dc: waitFor__zz9aVsJN0aTuFUXvzKrFo9cA at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/stdlib_asyncdispatch.nim.c:1984

0x400d709d: run_http_server at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/@mserver.nim.c:916

0x400d7139: NimMainModule at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/@mserver.nim.c:982

0x400d714f: NimMainInner at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/@mserver.nim.c:960

0x400d71d5: NimMain at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../src/nimcache/@mserver.nim.c:968

0x400d5ce9: app_main at c:\users\stisa\onedrive\progetti\esp32_nim_net_example\simplewifi\build/../main/wifi_example_main.c:127

0x400d1e5a: main_task at C:/Dev/esp-idf/components/esp32/cpu_start.c:553

0x4009219d: vPortTaskWrapper at C:/Dev/esp-idf/components/freertos/port.c:143

Rebooting...
elcritch commented 4 years ago

Great! Hope to try this out soon. It might be a good idea to make a raw socket handler HTTP server version.

elcritch commented 4 years ago

P.S. Would you also be interested in helping with a Nim library to wrap FreeRTOS primitives? I've not done too much programming with esp-idf but most of the FreeRTOS API isn't too complicated. I've actually already wrapped a fair bit of the core FreeRTOS stuff, but it'd be great to have someone else help with checking it and whatnot. Actually, it'd be pretty easy to get the basics for ethernet, wifi, logging wrapped up pretty quickly. Do you know the best way to create a Nim library, like using Nimble?

stisa commented 4 years ago

P.S. Would you also be interested in helping with a Nim library to wrap FreeRTOS primitives?

I would be interested yeah, although I'm not very experienced and I only have one board, but it would be cool to improve support so whatever I can do 👍 . Worst case, I'll learn or ask for help.

Do you know the best way to create a Nim library, like using Nimble?

I guess nimble init is the recommended way, but I usually just use this https://github.com/stisa/nimbasepkg, click use template, then clone it somewhere and run nimble develop in it, then I think you can nimble publish to send the pr to the package list, or just open the pr yourself.

What did you have in mind? A esp nimble package with a module per header?

Also, I'd like to find out what idf.py does exactly and port that to nim, so I can use a normal terminal powershell terminal instead of the cmd they make me open on windows