A HTTP Server in zephyr-siot

Zephyr now ships with a HTTP server. There is a sample app that builds and runs on the STM32H7:

However, the process to get this working in the zephyr-siot application is throwing a few errors:

[00:00:03.318,000] <inf> net_config: Interface 1 (0x3ffb5dd8) coming up
[00:00:03.318,000] <inf> net_config: Running dhcpv4 client...
[00:00:03.318,000] <inf> siot: SIOT Zephyr Application! esp32_poe/esp32/procpu
[00:00:03.318,000] <wrn> net_http_server: CLIFF: calling eventfd ...
[00:00:03.319,000] <err> net_http_server: socket: 107
[00:00:03.319,000] <err> net_http_server: All services failed (1)
[00:00:03.319,000] <err> net_http_server: Failed to initialize HTTP2 server
[00:00:03.319,000] <dbg> net_http_server: http_server_start: Starting HTTP server
[00:00:05.324,000] <inf> net_dhcpv4: Received: 10.0.0.148
[00:00:05.324,000] <inf> net_config: IPv4 address: 10.0.0.148
[00:00:05.324,000] <inf> net_config: Lease time: 600 seconds
[00:00:05.324,000] <inf> net_config: Subnet: 255.255.255.0
[00:00:05.324,000] <inf> net_config: Router: 10.0.0.1

There are some differences – the sample app is using a static DHCP config, where I’m trying to use DHCP.

The sample app will not build for ESP32 for various reasons, which is the end target for this application.

To be continued …

The HTTP Server is now working in the Simple IoT Zephyr application for STM32H7 and EPS32 platforms. Two major things I needed:

Once it works, it is very simple!

Next task is to get some simple forms working …

While trying to figure out how to set the HTTP response code, I learned that the API has ungone a few changes:

So going from living the 3.7 release to living on main …

Discussion: Discord

living on main I love it

With the Zephyr HTTP server, you often get multiple callbacks when receiving data:

[00:00:20.698,000] <dbg> siot: settings_handler: CLIFF: settings handler status: 0
[00:00:20.698,000] <dbg> siot: settings_handler: settings buffer
                               64 69 64 3d 44 65 76 69  63 65 25 32 30 43 26 69 |did=Devi ce%20C&i
                               70 73 74 61 74 69 63 3d  66 61 6c 73 65 26 69 70 |pstatic= false&ip
                               73 74 61 74 69 63 3d 74  72 75                   |static=t ru
[00:00:20.699,000] <dbg> siot: settings_handler: CLIFF: settings handler status: 1
[00:00:20.699,000] <dbg> siot: settings_handler: settings buffer
                               65 26 69 70 61 64 64 72  3d 31 39 32 2e 31 36 38 |e&ipaddr =192.168
                               2e 31 2e 32 33 26 73 75  62 6e 65 74 2d 6d 61 73 |.1.23&su bnet-mas
                               6b 3d 32 35 35 2e 32 35  35 2e 32 35 35 2e 30 26 |k=255.25 5.255.0&
                               67 61 74 65 77 61 79 3d  31 39 32 2e 31 36 38 2e |gateway= 192.168.
                               31 2e 31                                         |1.1
[00:00:20.699,000] <dbg> siot: settings_handler: settings data
[00:00:20.699,000] <dbg> siot: settings_callback: setting: did:Device C
[00:00:20.699,000] <dbg> siot: settings_callback: setting: ipstatic:false
[00:00:20.699,000] <dbg> siot: settings_callback: setting: ipstatic:true
[00:00:20.699,000] <dbg> siot: settings_callback: setting: ipaddr:192.168.1.23
[00:00:20.700,000] <dbg> siot: settings_callback: setting: subnet-mask:255.255.255.0
[00:00:20.700,000] <dbg> siot: settings_callback: setting: gateway:192.168.1.1

So it is critical to understand this, collect all the data, and only process it when all the data has been received.