1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ZephyrRTOS: HTTP Server over Wi-Fi 構築 (ESPr Developer C5)

1
Last updated at Posted at 2026-05-10

概要

ESPr Developer C5における、HTTP Server over Wi-Fi の構築手順

ボード

以下を参照。
https://qiita.com/hayashi-tqm-dev/items/e9a713eb05310ab7ffb0#%E3%83%9C%E3%83%BC%E3%83%89

ZephyrRTOS version

以下を参照。
https://qiita.com/hayashi-tqm-dev/items/e9a713eb05310ab7ffb0#zephyrrtos-version

Patch (prj.conf)

prj.confでボードのWi-Fi機能を有効化し、Credentialを事前に設定しておく。

CONFIG_NET_CONFIG_MY_IPV4_ADDR
CONFIG_WIFI_CREDENTIALS_STATIC_SSID
CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD

は宅内Wi-Fiルータのものを想定。

diff --git a/samples/net/sockets/http_server/prj.conf b/samples/net/sockets/http_server/prj.conf
index 7553cb799a2..de978ef92ff 100644
--- a/samples/net/sockets/http_server/prj.conf
+++ b/samples/net/sockets/http_server/prj.conf
@@ -52,7 +52,7 @@ CONFIG_NET_MAX_CONN=32
 CONFIG_NET_CONFIG_SETTINGS=y
 CONFIG_NET_CONFIG_NEED_IPV4=y
 CONFIG_NET_CONFIG_NEED_IPV6=y
-CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1"
+CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.168.2.18"
 CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
 CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
 CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1"
@@ -72,3 +72,15 @@ CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=n
 CONFIG_NET_HTTP_LOG_LEVEL_DBG=n
 CONFIG_NET_IPV6_LOG_LEVEL_DBG=n
 CONFIG_NET_IPV6_ND_LOG_LEVEL_DBG=n
+
+# Wi-Fi config
+CONFIG_WIFI=y
+CONFIG_WIFI_CREDENTIALS=y
+CONFIG_WIFI_CREDENTIALS_STATIC=y
+CONFIG_WIFI_CREDENTIALS_STATIC_SSID="ROUTER SSID"
+CONFIG_WIFI_CREDENTIALS_STATIC_PASSWORD="ROUTER PASSWORD"
+CONFIG_WIFI_CREDENTIALS_STATIC_TYPE_PSK=y
+
+# For debugging Wi-Fi
+CONFIG_NET_L2_WIFI_SHELL=y
+

Patch (main.c)

宅内のWi-Fiルータに自動で接続させるために、net_mgmt() を叩くコードを追加しておく。

diff --git a/samples/net/sockets/http_server/src/main.c b/samples/net/sockets/http_server/src/main.c
index efe9f8bd4fc..53dae310c08 100644
--- a/samples/net/sockets/http_server/src/main.c
+++ b/samples/net/sockets/http_server/src/main.c
@@ -21,6 +21,11 @@
 #include <zephyr/sys/util_macro.h>
 #include <zephyr/net/net_config.h>
 
+#ifdef CONFIG_WIFI_CREDENTIALS_STATIC_SSID
+#include <zephyr/net/wifi_mgmt.h>
+#include <zephyr/net/net_if.h>
+#endif
+
 #if CONFIG_USB_DEVICE_STACK_NEXT
 #include <sample_usbd.h>
 #endif
@@ -384,5 +389,11 @@ int main(void)
 
 	setup_tls();
 	http_server_start();
+
+#ifdef CONFIG_WIFI_CREDENTIALS_STATIC_SSID
+	struct net_if *iface = net_if_get_default();
+	net_mgmt(NET_REQUEST_WIFI_CONNECT_STORED, iface, NULL, 0);
+#endif
+
 	return 0;
 }

ソースコードはここにコミットしておいた。
https://github.com/zephyrproject-rtos/zephyr/commit/d889693c264eef29f342148137c86c58a9a694b5

ビルド

普通にビルドする

$ west build -b esp32c5_devkitc/esp32c5/hpcore samples/net/sockets/http_server

動作確認

普通に書き込む

$ west flash

/dev/ttyACM* に接続し、uart shellがプロンプトされることを確認し少し待っていると...
宅内Wi-Fiルータに接続された:nerd:

uart:~$ 
I (net80211): net80211 rom version: 78a72e9d5
I (wifi_init): rx ba win: 6
*** Booting Zephyr OS build v4.4.0-1781-g718dfc7d4445 ***
[00:00:00.038,000] <inf> net_config: Initializing network
[00:00:00.038,000] <inf> net_config: Waiting interface 1 (0x40817578) to be up...
[00:00:30.050,000] <inf> net_config: IPv4 address: 192.168.2.18
[00:00:30.057,000] <err> net_config: Timeout while waiting network interface
[00:00:30.057,000] <err> net_config: Network initialization failed (-115)
[00:00:30.674,000] <wrn> net_if: iface 1 pkt 0x408365ac send failure status -5
[00:00:30.695,000] <inf> net_wifi_mgmt: Connection requested
[00:00:30.782,000] <inf> net_config: IPv6 address: fe80::3edc:75ff:fe82:f4e4
[00:00:30.782,000] <inf> net_config: IPv6 address: fe80::3edc:75ff:fe82:f4e4
Connected
[00:00:57.885,000] <dbg> net_http_server_sample: uptime_handler: Uptime handler status 1
[00:00:57.895,000] <dbg> net_http_server_sample: uptime_handler: Uptime handler status 2

HTTP Serverへのアクセス

ブラウザで http://192.168.2.18/ にアクセスすると、以下のようなWebページが表示され、html+javascriptの配信と、websocketによる通信が行われている!
LEDのボタンがあるので、サーバサイドで、Lチカを動かすサンプルなのかな?

Screenshot from 2026-05-10 21-42-01.png

感想

DIYスマートホームへの第一歩

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?