incognitum
Posts: 767
Joined: Tue Oct 30, 2018 3:34 pm

Webserver example

Sat Mar 13, 2021 10:50 pm

Since some folks are having problems with the webserver example from pico-playground (see other thread).

I thought I'll share you my attempt to get the original TinyUSB webserver example to build on a Pico.
Slightly modified code here: https://github.com/maxnet/pico-webserver
pico-webserver.png
pico-webserver.png (148.43 KiB) Viewed 1833 times
When you connect Pico to your computer, the Pico will pretend to be an USB Ethernet adapter, and offers a simple webinterface at http://192.168.7.1/
Let's you toggle the Pico LED and reboot to flash mode from the webinterface.
Doesn't do much more.

Only tested when connected to a Linux computer.

User avatar
HermannSW
Posts: 4518
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Webserver example

Sun Mar 14, 2021 11:44 am

Thanks for that beautiful example!

I did fork your repo and added that the LED does not toggle only on the Pico, but on the webpage as well.
This is the small diff:
https://github.com/Hermann-SW/pico-webs ... 2cf20f8dae


Small demo of the new feature:
Image
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

mictronic
Posts: 2
Joined: Fri Apr 02, 2021 5:05 pm

Re: Webserver example

Fri Apr 02, 2021 5:08 pm

Hello,

I'm trying to build pico-webserver according to your build instrcutions on https://github.com/maxnet/pico-webserver.

The following command gives an error:
git submodule update --init --depth 1

remote: Total 0 (delta 0), reused 0 (delta 0)
error: Der Server lehnt Anfrage nach nicht angebotenem Objekt 0056522cc974d2be2005c324f37187b5b3695765 ab.
"fetch" in Submodul-Pfad 'lwip' ausgeführt, aber 0056522cc974d2be2005c324f37187b5b3695765 nicht
enthalten. Direktes Anfordern dieses Commits ist fehlgeschlagen.

Error is "Direct fetching of that commit failed."

Any idea how to fix this error?
Thanks a lot.

Best regards,
Michael

User avatar
HermannSW
Posts: 4518
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Webserver example

Fri Apr 02, 2021 10:55 pm

Hi Michael,

I am German as well, but use English language and therefore get same error you got in English.
I did update and upgrade my Pi400, but the problem remained.
It is a submodule clone problem that is new, building was easy when I did my fork.
I updated my fork README.md with an additonal step as workaround for the lwip repo issue.
With that step building just works again, please follow the steps:
https://github.com/Hermann-SW/pico-webserver
I did build and test pico_webserver.uf2, and pushed with to my repo as well for flash&trial (in uf2 directory).
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

mictronic
Posts: 2
Joined: Fri Apr 02, 2021 5:05 pm

Re: Webserver example

Sat Apr 03, 2021 4:23 pm

HermannSW wrote:
Fri Apr 02, 2021 10:55 pm
I updated my fork README.md with an additonal step as workaround for the lwip repo issue.
With that step building just works again, please follow the steps:
https://github.com/Hermann-SW/pico-webserver
I did build and test pico_webserver.uf2, and pushed with to my repo as well for flash&trial (in uf2 directory).
Hi Hermann,

thanks a lot, this helped me.

WizIO
Posts: 105
Joined: Mon Feb 22, 2021 8:34 am
Location: Sofia
Contact: Website

Re: Webserver example

Sat Apr 03, 2021 9:41 pm

for PlatformIO

https://www.youtube.com/watch?v=KU3oFQw3dRM

example link in description

User avatar
HermannSW
Posts: 4518
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Webserver example

Sun Apr 04, 2021 9:07 pm

@WizIO
Your PlatformIO is useful for people coming from Arduino world.
But why should people not coming from Arduino world use PaltformIO.

Also your webserver example looks more complex than @incognitum's and not providing interactive features like @incognitum's.

In case I use an Arduino Uno, Due, ESP32 or ESP8266, then I use Arduino IDE.
With the Pico I use Pico-SDK or MicroPython, no need for me to go the Arduino IDE route.
https://stamm-wilbrandt.de/2wheel_balancing_robot
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://github.com/Hermann-SW/raspiraw
https://stamm-wilbrandt.de/en/Raspberry_camera.html

WizIO
Posts: 105
Joined: Mon Feb 22, 2021 8:34 am
Location: Sofia
Contact: Website

Re: Webserver example

Mon Apr 12, 2021 4:27 pm

Hi,

my port for PlatformIO support:
PICO-SDK as C & C++
basic file-systems ( lfs & fatfs )
unistd, posix, FreeRTOS, ThreadX ( soon ),
PIO compiler,
OpenOCD ( soon ... waithing second pico )
for ALL system platfroms ( Win, Lin, Mac ... PI-soon )

and Arduino for the kids...

jannis
Posts: 77
Joined: Tue Jan 17, 2012 3:48 pm

Re: Webserver example

Tue Apr 20, 2021 7:45 pm

Hi, thank you for this nice example. I was able to compile it, however it doesn't work properly then.
Pinging 192.168.7.1 works without issues. But as soon as the web age is accessed (tried with Firefox, Chromium and wget), the program on the rp2040 crashes and stops reacting to USB packets. No ping and a kernel stack trace about some RNDIS timeout.

I tried the uf2-file from https://github.com/Hermann-SW/pico-webs ... e/main/uf2 and this works without a problem. So this seems to be a problem of the toolchain I'm using. I tried with gcc 9.3.0 and gcc 10.2.0 but the result is the same. Other programs (with different USB interfaces and C + C++ mixed) work without a problem.

Does anyone have an idea?

jannis
Posts: 77
Joined: Tue Jan 17, 2012 3:48 pm

Re: Webserver example

Tue Apr 20, 2021 9:32 pm

Since I assume that the answer would understandably be: "you might want to debug it" I did so ;)
Stack trace:

Code: Select all

Thread 1 received signal SIGTRAP, Trace/breakpoint trap.
isr_hardfault () at /home/kripton/pico/pico-webserver/pico-sdk/src/rp2_common/pico_standard_link/crt0.S:92
92      decl_isr_bkpt isr_hardfault
(gdb) bt
#0  isr_hardfault () at /home/kripton/pico/pico-webserver/pico-sdk/src/rp2_common/pico_standard_link/crt0.S:92
#1  <signal handler called>
#2  0x1000f7a0 in string_desc_arr ()
#3  0x1000755c in fs_open (file=0x0, file@entry=0x20000f28 <ram_heap+92>, name=0x0, name@entry=0x10010dac "/index.shtml") at /home/kripton/pico/pico-webserver/lwip/src/apps/http/fs.c:73
#4  0x10007202 in http_find_file (hs=hs@entry=0x20000f28 <ram_heap+92>, uri=<optimized out>, uri@entry=0x20006f3e <memp_memory_PBUF_POOL_base+23054> "/", is_09=is_09@entry=0) at /home/kripton/pico/pico-webserver/lwip/src/apps/http/httpd.c:2248
#5  0x100073dc in http_parse_request (inp=inp@entry=0x20006ef4 <memp_memory_PBUF_POOL_base+22980>, hs=hs@entry=0x20000f28 <ram_heap+92>, pcb=pcb@entry=0x20007d04 <memp_memory_TCP_PCB_base+624>)
    at /home/kripton/pico/pico-webserver/lwip/src/apps/http/httpd.c:2122
#6  0x10007462 in http_recv (arg=0x20000f28 <ram_heap+92>, pcb=0x20007d04 <memp_memory_TCP_PCB_base+624>, p=0x20006ef4 <memp_memory_PBUF_POOL_base+22980>, err=<optimized out>) at /home/kripton/pico/pico-webserver/lwip/src/apps/http/httpd.c:2587
#7  0x1000b068 in tcp_input (p=p@entry=0x20006ef4 <memp_memory_PBUF_POOL_base+22980>, inp=inp@entry=0x20008c70 <netif_data>) at /home/kripton/pico/pico-webserver/lwip/src/core/tcp_in.c:501
#8  0x1000e426 in ip4_input (p=p@entry=0x20006ef4 <memp_memory_PBUF_POOL_base+22980>, inp=inp@entry=0x20008c70 <netif_data>) at /home/kripton/pico/pico-webserver/lwip/src/core/ipv4/ip4.c:743
#9  0x1000ea20 in ethernet_input (p=0x20006ef4 <memp_memory_PBUF_POOL_base+22980>, netif=netif@entry=0x20008c70 <netif_data>) at /home/kripton/pico/pico-webserver/lwip/src/netif/ethernet.c:186
#10 0x10000578 in service_traffic () at /home/kripton/pico/pico-webserver/tusb_lwip_glue.c:190
#11 0x100003f6 in main () at /home/kripton/pico/pico-webserver/webserver.c:53
I'll see if I can continue fixing it

jannis
Posts: 77
Joined: Tue Jan 17, 2012 3:48 pm

Re: Webserver example

Sun Apr 25, 2021 8:18 pm

I more or less solved it but I'm not really happy. My pico will crash on every call to "strcmp" (at least in the pico-webserver example). When I replace the strcmp with a combination of "strlen" and "memcmp", everything is fine and the board behaves as it should. I've got no idea why this would happen. The pico-sdk doesn't seem to contain "optimized" versions of "strcmp" so it really seems to be the toolchain I'm using ...
Nevertheless, thanks for this interesting example :)

incognitum
Posts: 767
Joined: Tue Oct 30, 2018 3:34 pm

Re: Webserver example

Sun Apr 25, 2021 8:33 pm

jannis wrote:
Sun Apr 25, 2021 8:18 pm
The pico-sdk doesn't seem to contain "optimized" versions of "strcmp" so it really seems to be the toolchain I'm using ...
Probably indeed your toolchain's newlib using an instruction the Pico does not support.

Do seem to be CPU specific #ifdef's there (thumb, thumb2, __ARM_FEATURE_DSP, etc): https://github.com/eblot/newlib/blob/ma ... m/strcmp.S

jannis
Posts: 77
Joined: Tue Jan 17, 2012 3:48 pm

Re: Webserver example

Fri Apr 30, 2021 8:43 am

Solved by changing some toolchain parameters: https://forums.gentoo.org/viewtopic-t-1134474.html

Return to “SDK”