Skip to content

Commit 573d8af

Browse files
jukkarrveerama1
authored andcommitted
samples: net: websocket: Add console sample application
This sample application implements a web service that provides zephyr console over websocket. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent f8e68c4 commit 573d8af

File tree

14 files changed

+954
-0
lines changed

14 files changed

+954
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
2+
project(NONE)
3+
4+
FILE(GLOB app_sources src/*.c)
5+
target_sources(app PRIVATE ${app_sources})
6+
7+
include($ENV{ZEPHYR_BASE}/samples/net/common/common.cmake)
8+
9+
set(gen_dir ${ZEPHYR_BINARY_DIR}/include/generated/)
10+
11+
# List of files that are used to generate .h file that can be included
12+
# into .c file.
13+
foreach(inc_file
14+
echo-apps-cert.der
15+
echo-apps-key.der
16+
)
17+
generate_inc_file_for_target(
18+
app
19+
src/${inc_file}
20+
${gen_dir}/${inc_file}.inc
21+
)
22+
endforeach()
23+
24+
generate_inc_file_for_target(app src/index.html ${gen_dir}/index.html.gz.inc --gzip)
25+
generate_inc_file_for_target(app src/style.css ${gen_dir}/style.css.gz.inc --gzip)
26+
generate_inc_file_for_target(app src/favicon.ico ${gen_dir}/favicon.ico.gz.inc --gzip)
27+
28+
target_link_libraries_ifdef(CONFIG_MBEDTLS app mbedTLS)

samples/net/ws_console/README.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. _websocket-console-sample:
2+
3+
Websocket Console
4+
#################
5+
6+
Overview
7+
********
8+
9+
The websocket-console sample application for Zephyr implements a console
10+
over a websocket. The websocket-console sample application listens for incoming
11+
IPv4 or IPv6 HTTP(S) requests and provides Zephyr console to the browser over
12+
a websocket.
13+
14+
The source code for this sample application can be found at:
15+
:file:`samples/net/ws_console`.
16+
17+
Requirements
18+
************
19+
20+
- :ref:`networking_with_qemu`
21+
22+
Building and Running
23+
********************
24+
25+
There are multiple ways to use this application. One of the most common
26+
usage scenario is to run websocket-console application inside QEMU. This is
27+
described in :ref:`networking_with_qemu`.
28+
29+
Build ws_console sample application like this:
30+
31+
.. zephyr-app-commands::
32+
:zephyr-app: samples/net/ws_console
33+
:board: qemu_x86
34+
:goals: run
35+
:compact:
36+
37+
The default make BOARD configuration for this sample is ``qemu_x86``.
38+
39+
Connect to the console from your browser using these URLs http://[2001:db8::1]
40+
or http://192.0.2.1 as configured in the project's ``prj.conf`` file.

samples/net/ws_console/prj.conf

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Generic IP stack options and features
2+
CONFIG_NETWORKING=y
3+
CONFIG_NET_UDP=n
4+
CONFIG_NET_TCP=y
5+
CONFIG_NET_IPV6=y
6+
CONFIG_NET_IPV4=y
7+
#CONFIG_NET_DHCPV4=y
8+
CONFIG_ENTROPY_GENERATOR=y
9+
CONFIG_TEST_RANDOM_GENERATOR=y
10+
CONFIG_INIT_STACKS=y
11+
CONFIG_NET_MAX_CONTEXTS=8
12+
CONFIG_NET_SHELL=y
13+
14+
# Number of network buffers
15+
CONFIG_NET_PKT_RX_COUNT=32
16+
CONFIG_NET_PKT_TX_COUNT=32
17+
CONFIG_NET_BUF_RX_COUNT=32
18+
CONFIG_NET_BUF_TX_COUNT=32
19+
CONFIG_NET_CONTEXT_NET_PKT_POOL=y
20+
21+
# IPv6 address counts
22+
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
23+
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
24+
25+
# Network application settings
26+
CONFIG_NET_APP=y
27+
CONFIG_NET_APP_SETTINGS=y
28+
CONFIG_NET_APP_NEED_IPV6=y
29+
CONFIG_NET_APP_NEED_IPV4=y
30+
CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
31+
CONFIG_NET_APP_MY_IPV4_ADDR="192.0.2.1"
32+
33+
# HTTP & Websocket options
34+
CONFIG_WEBSOCKET=y
35+
CONFIG_WEBSOCKET_CONSOLE=y
36+
CONFIG_HTTP=y
37+
CONFIG_HTTPS=n
38+
CONFIG_HTTP_SERVER=y
39+
# How many URLs we are serving
40+
CONFIG_HTTP_SERVER_NUM_URLS=5
41+
42+
# base64 support needed by websocket
43+
CONFIG_MBEDTLS=y
44+
CONFIG_MBEDTLS_BUILTIN=y
45+
CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h"
46+
47+
# Logging
48+
CONFIG_NET_LOG=y
49+
CONFIG_SYS_LOG_NET_LEVEL=2
50+
CONFIG_SYS_LOG_SHOW_COLOR=y
51+
CONFIG_NET_STATISTICS=y
52+
CONFIG_PRINTK=y
53+
54+
# Debugging
55+
CONFIG_NET_DEBUG_WEBSOCKET=y
56+
CONFIG_NET_DEBUG_HTTP=n
57+
CONFIG_NET_DEBUG_APP=n
58+
CONFIG_NET_DEBUG_NET_PKT=y
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Generic IP stack options and features
2+
CONFIG_NETWORKING=y
3+
CONFIG_NET_UDP=n
4+
CONFIG_NET_TCP=y
5+
CONFIG_NET_IPV6=y
6+
CONFIG_NET_IPV4=y
7+
#CONFIG_NET_DHCPV4=y
8+
CONFIG_ENTROPY_GENERATOR=y
9+
CONFIG_TEST_RANDOM_GENERATOR=y
10+
CONFIG_INIT_STACKS=y
11+
CONFIG_NET_MAX_CONTEXTS=8
12+
CONFIG_NET_SHELL=y
13+
14+
# Number of network buffers
15+
CONFIG_NET_PKT_RX_COUNT=64
16+
CONFIG_NET_PKT_TX_COUNT=64
17+
CONFIG_NET_BUF_RX_COUNT=64
18+
CONFIG_NET_BUF_TX_COUNT=64
19+
CONFIG_NET_CONTEXT_NET_PKT_POOL=y
20+
21+
# IPv6 address counts
22+
CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3
23+
CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4
24+
25+
# Network application settings
26+
CONFIG_NET_APP=y
27+
CONFIG_NET_APP_SETTINGS=y
28+
CONFIG_NET_APP_NEED_IPV6=y
29+
CONFIG_NET_APP_NEED_IPV4=y
30+
CONFIG_NET_APP_MY_IPV6_ADDR="2001:db8::1"
31+
CONFIG_NET_APP_MY_IPV4_ADDR="192.0.2.1"
32+
33+
# HTTP & Websocket options
34+
CONFIG_WEBSOCKET=y
35+
CONFIG_WEBSOCKET_CONSOLE=y
36+
CONFIG_HTTP=y
37+
CONFIG_HTTPS=y
38+
CONFIG_HTTP_SERVER=y
39+
# How many URLs we are serving
40+
CONFIG_HTTP_SERVER_NUM_URLS=5
41+
42+
# Crypto support
43+
CONFIG_MBEDTLS=y
44+
CONFIG_MBEDTLS_BUILTIN=y
45+
CONFIG_MBEDTLS_CFG_FILE="config-mini-tls1_2.h"
46+
CONFIG_MBEDTLS_ENABLE_HEAP=y
47+
CONFIG_MBEDTLS_HEAP_SIZE=30000
48+
49+
# Logging
50+
CONFIG_NET_LOG=y
51+
CONFIG_SYS_LOG_NET_LEVEL=2
52+
CONFIG_SYS_LOG_SHOW_COLOR=y
53+
CONFIG_NET_STATISTICS=y
54+
CONFIG_PRINTK=y
55+
56+
# Debugging
57+
CONFIG_NET_DEBUG_WEBSOCKET=y
58+
CONFIG_NET_DEBUG_HTTP=n
59+
CONFIG_NET_DEBUG_APP=n
60+
CONFIG_NET_DEBUG_NET_PKT=y

samples/net/ws_console/sample.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sample:
2+
name: Websocket console
3+
tests:
4+
- test:
5+
build_only: true
6+
platform_whitelist: qemu_x86
7+
tags: net websocket
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2017 Intel Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define MAX_DBG_PRINT 64
8+
9+
void start_ws_console(void);
10+
void stop_ws_console(void);
11+
12+
void quit(void);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2017 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef _CONFIG_H_
8+
#define _CONFIG_H_
9+
10+
/* The startup time needs to be longish if DHCP is enabled as setting
11+
* DHCP up takes some time.
12+
*/
13+
#define APP_STARTUP_TIME K_SECONDS(20)
14+
15+
#ifdef CONFIG_NET_APP_SETTINGS
16+
#ifdef CONFIG_NET_IPV6
17+
#define ZEPHYR_ADDR CONFIG_NET_APP_MY_IPV6_ADDR
18+
#else
19+
#define ZEPHYR_ADDR CONFIG_NET_APP_MY_IPV4_ADDR
20+
#endif
21+
#else
22+
#ifdef CONFIG_NET_IPV6
23+
#define ZEPHYR_ADDR "2001:db8::1"
24+
#else
25+
#define ZEPHYR_ADDR "192.0.2.1"
26+
#endif
27+
#endif
28+
29+
#ifndef ZEPHYR_PORT
30+
#define ZEPHYR_PORT 8080
31+
#endif
32+
33+
#endif
767 Bytes
Binary file not shown.
1.19 KB
Binary file not shown.
318 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)