TCP Server + softAP

This application uses three Gecko OS devices. Module 1 is a TCP server configured to start its softap interface and its TCP server feature on bootup. Module 2 and Module 3 are TCP clients configured to use their wlan interface and TCP client feature to connect to the Module 1 softap and TCP server.

Once module 2 and module 3 are connected, data is sent to module 1 first from module 2, and then from module 3. Module 1 reads the received data.

The stream_list command is used to list open streams, and stream_poll is used on the server to check for data received by clients. Two GPIOs are configured to toggle high when a client connects, and also when data is received and waiting.

In this example, the TCP server is configured to use the softAP interface, but it can also easily be configured to use the wlan client interface.

Module 1 - TCP Server Settings

Gecko OS Commands (Module 1) Description

set softap.auto_start           true
set softap.dhcp_server.enabled  true
set softap.ssid        tcp_server_ap

set tcp.server.auto_interface softap
set tcp.server.auto_start       true
set tcp.server.idle_timeout      300
set tcp.server.connected_gpio     22
set tcp.server.data_gpio          21

save
reboot

<- softap auto starts on reboot
<- DHCP server is enabled
<- Set softAP name
<- TCP server uses softAP interface <- TCP server auto starts on reboot <- Don't disconnect clients quickly <- GPIO indicates client connection <- GPIO indicates data is available <- Save settings to flash <- Reboot the module

Example TCP Session with Module 2

Module 2: Wi-Fi + TCP Client Module 1: softAP + TCP Server

> set wlan.ssid tcp_server_ap
Set OK
> save
Success
> tcp_client 10.10.10.1 3000
[Associating to tcp_server_ap]
[Associated]
[Connecting: 10.10.10.1:3000]
[Connected: 0] 0 > stream_write 0 22 <hello from module 2!> Success














> list
! # Type  Info
# 0 TCPS  10.10.10.1:3000 10.10.10.2:27192
> stream_poll 0
1
> stream_read 0 100
<<hello from module 2!>
> stream_poll 0
0

Example TCP Session adding Module 3

Module 3: Wi-Fi + TCP Client Module 1: softAP + TCP Server

> set wlan.ssid tcp_server_ap
Set OK
> save
Success
> tcp_client 10.10.10.1 3000
[Associating to tcp_server_ap]
[Associated]
[Connecting: 10.10.10.1:3000]
[Connected: 0] 0 > stream_write 0 22 <hello from module 3!> Success














> stream_list
! # Type  Info
# 0 TCPS  10.10.10.1:3000 10.10.10.2:32193
# 1 TCPS  10.10.10.1:3000 10.10.10.3:33312
> stream_poll all
0,0|1,1
> stream_read 1 100
<hello from module 3!>
> stream_poll all
0,0|1,0

Supporting Gecko OS Versions

Change Log

Modified Changes
2019-01-01 Created