Skip to content

Commit

Permalink
Add basic WebSocket implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjaeger committed Jul 22, 2023
1 parent 66e9a20 commit ab2f3c9
Show file tree
Hide file tree
Showing 10 changed files with 386 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ jobs:
run: |
west build -p -b olimex_lora_stm32wl_devkit samples/counter -- -DOVERLAY_CONFIG=lorawan.conf
west build -p -b esp32c3_devkitm samples/counter
west build -p -b esp32c3_devkitm samples/counter -- -DOVERLAY_CONFIG=wifi_websocket.conf
west build -p -b native_posix samples/counter
west build -p -b nucleo_l073rz samples/counter -- -DOVERLAY_CONFIG=serial.conf
west build -p -b nucleo_l073rz samples/counter -- -DOVERLAY_CONFIG=storage_eeprom.conf
west build -p -b native_posix samples/counter -- -DOVERLAY_CONFIG=auth.conf
west build -p -b native_posix samples/counter -- -DOVERLAY_CONFIG=can.conf
west build -p -b native_posix samples/counter -- -DOVERLAY_CONFIG=log_backend.conf
west build -p -b native_posix samples/counter -- -DOVERLAY_CONFIG=native_websocket.conf
- name: Build documentation
working-directory: thingset-zephyr-sdk
Expand Down
1 change: 1 addition & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rsource "src/Kconfig.lorawan"
rsource "src/Kconfig.serial"
rsource "src/Kconfig.shell"
rsource "src/Kconfig.storage"
rsource "src/Kconfig.websocket"
rsource "src/Kconfig.wifi"

menu "General Publication Settings"
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ west build -b olimex_lora_stm32wl_devkit samples/counter -- -DOVERLAY_CONFIG=lor
west build -b native_posix samples/counter -t run -- -DOVERLAY_CONFIG=can.conf
```

## Testing with WebSocket

Start net-setup from Zephyr net-tools:

```
sudo ../tools/net-tools/net-setup.sh
```

Afterwards run the nativ_posix board with websocket support from another shell:

```
west build -b native_posix samples/counter -t run -- -DOVERLAY_CONFIG=native_websocket.conf
```

Check socket connections

```
ss -t -a -n | grep -E 'State|192.0.2.1'
```

## License

This software is released under the [Apache-2.0 License](LICENSE).
12 changes: 7 additions & 5 deletions include/thingset/sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ extern "C" {
#define TS_ID_LORAWAN_DEV_NONCE 0x273

/* Networking group items */
#define TS_ID_NET 0x28
#define TS_ID_NET_WIFI_SSID 0x280
#define TS_ID_NET_WIFI_PSK 0x281
#define TS_ID_NET_IPV4 0x282
#define TS_ID_NET_IPV6 0x283
#define TS_ID_NET 0x28
#define TS_ID_NET_WIFI_SSID 0x280
#define TS_ID_NET_WIFI_PSK 0x281
#define TS_ID_NET_IPV4 0x282
#define TS_ID_NET_IPV6 0x283
#define TS_ID_NET_WEBSOCKET_IPV4 0x284
#define TS_ID_NET_WEBSOCKET_PORT 0x285

/* Device Firmware Upgrade group items */
#define TS_ID_DFU 0x2D
Expand Down
20 changes: 20 additions & 0 deletions include/thingset/websocket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) The ThingSet Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef THINGSET_WEBSOCKET_H_
#define THINGSET_WEBSOCKET_H_

#ifdef __cplusplus
extern "C" {
#endif

int thingset_websocket_send_report(const char *path);

#ifdef __cplusplus
}
#endif

#endif /* THINGSET_WEBSOCKET_H_ */
35 changes: 35 additions & 0 deletions samples/counter/native_websocket.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright (c) The ThingSet Project Contributors
# SPDX-License-Identifier: Apache-2.0

CONFIG_HEAP_MEM_POOL_SIZE=1500

# Networking config
CONFIG_NETWORKING=y
CONFIG_NET_IPV4=y
CONFIG_NET_IPV6=y
CONFIG_NET_TCP=y
CONFIG_NET_SHELL=y
CONFIG_NET_STATISTICS=y

# Sockets
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POLL_MAX=4

# Network address config
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_IPV6_ADDR="2001:db8::1"
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2"
# Address of HTTP server
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2"
CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2"

# HTTP & Websocket
CONFIG_HTTP_CLIENT=y
CONFIG_WEBSOCKET_CLIENT=y

CONFIG_THINGSET_WEBSOCKET=y
CONFIG_THINGSET_WEBSOCKET_SERVER_IPV4="192.0.2.2"
CONFIG_THINGSET_WEBSOCKET_SERVER_PORT=8000
File renamed without changes.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ target_sources_ifdef(CONFIG_THINGSET_SERIAL app PRIVATE serial.c)
target_sources_ifdef(CONFIG_THINGSET_SHELL app PRIVATE shell.c)
target_sources_ifdef(CONFIG_THINGSET_STORAGE_EEPROM app PRIVATE storage_eeprom.c)
target_sources_ifdef(CONFIG_THINGSET_STORAGE_FLASH app PRIVATE storage_flash.c)
target_sources_ifdef(CONFIG_THINGSET_WEBSOCKET app PRIVATE websocket.c)
target_sources_ifdef(CONFIG_THINGSET_WIFI app PRIVATE wifi.c)
40 changes: 40 additions & 0 deletions src/Kconfig.websocket
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) The ThingSet Project Contributors
# SPDX-License-Identifier: Apache-2.0

config THINGSET_WEBSOCKET
depends on WEBSOCKET_CLIENT
bool "WebSocket interface"

if THINGSET_WEBSOCKET

config THINGSET_WEBSOCKET_SERVER_IPV4
string "Default WebSocket server IPv4 address"
help
This default IP address can be changed via ThingSet.

config THINGSET_WEBSOCKET_SERVER_PORT
int "Default WebSocket server port"
default 80
help
This default port can be changed via ThingSet.

config THINGSET_WEBSOCKET_RX_BUF_SIZE
int "ThingSet WebSocket RX buffer size"
range 512 4096
default 1024

config THINGSET_WEBSOCKET_THREAD_STACK_SIZE
int "ThingSet WebSocket thread stack size"
default 4096
help
Stack size of thread for processing ThingSet messages transmitted
via WebSocket.

config THINGSET_WEBSOCKET_THREAD_PRIORITY
int "ThingSet WebSocket thread priority"
default 2
help
Priority of thread for processing ThingSet messages transmitted
via WebSocket.

endif # THINGSET_WEBSOCKET
Loading

0 comments on commit ab2f3c9

Please sign in to comment.