Wireless Serial Port #
This application uses two Gecko OS devices each running Gecko OS to demonstrate how to create a wireless serial port. A character typed into the serial port of Module 1 appears instantly at the output of the Module 2 serial port (and vice versa).
Features demonstrated #
- Serial Interface Stream Mode
- Use of the wlan and softap wireless interfaces
- TCP client and TCP server
- UDP client and UDP server
Module 1 is configured to start the softap interface and a server on bootup.
Module 2 is configured to use the wlan interface and connect a client to the Module 1 softap server.
The final configuration step places both modules into serial interface stream Mode.
The client/server configuration can use either TCP or UDP protocols.
Wireless Serial Port using TCP #
We start by configuring each of the modules, one as a TCP server and one as a TCP client.
Copy and paste the commands in the left hand column of the following table into a Gecko OS terminal connected to Module 1.
Module 1 TCP Server Configuration Settings #
Gecko OS Commands (Module 1) | Description |
---|---|
|
|
On rebooting, Module 1 automatically starts the softap, starts the TCP server, waits for a connection on port 3000 and enters stream mode. Data sent to the Module 1 UART is transmitted over the softap interface.
Now, copy and paste the commands in the left hand column of the following table into a Gecko OS terminal connected to Module 2.
Module 2 TCP Client Configuration Settings #
Gecko OS Commands (Module 2) | Description |
---|---|
|
|
On rebooting, Module 2 automatically connects to the wlan, connects as a client to the TCP server running on Module 1 and enters stream mode. Data sent to the Module 2 UART is transmitted over the wlan interface.
TCP Wireless Magic! #
At this point, all characters typed into the Module 1 serial port appear immediately on the Module 2 serial port output (and vice versa). Give it a go, it's like a little piece of wireless magic!
Wireless Serial Port using UDP Client/Server Configuration #
The UDP client/server configuration is similar to the TCP configuration, with changes due to the different options available for UDP. We start by configuring each of the modules, one as a UDP server and one as a UDP client.
Copy and paste the commands in the left hand column of the following table into a Gecko OS terminal connected to Module 1.
Module 1 UDP Server Configuration Settings #
Gecko OS Commands (Module 1) | Description |
---|---|
|
|
On rebooting, Module 1 automatically starts the softap, waits for a message on port 8000 and enters stream mode. Data sent to the Module 1 UART is transmitted over the softap interface. However a message from Module 2 is required before Module 1 knows the client address and port.
Now, copy and paste the commands in the left hand column of the following table into a Gecko OS terminal connected to Module 2.
Module 2 UDP Client Configuration Settings #
Gecko OS Commands (Module 2) | Description |
---|---|
|
|
On rebooting, Module 2 automatically connects to the Module 1 softap and enters stream mode. Data sent to the Module 1 UART is transmitted over the wlan interface. On Module 2 sending the first message, Module 1 stores the IP and port of Module 2 for later responses to Module 1.
UDP Wireless Magic! #
Type characters into the client (Module 2) Gecko OS terminal. They appear immediately on the Module 1 Gecko OS terminal.
Now type characters into the server (Module 1) Gecko OS terminal. They appear immediately on the Module 2 Gecko OS terminal.
Note : Because UDP is a connectionless protocol, the client must send the first message. Then the server records the address of the client and can respond. If you type first on the Module 1 Gecko OS terminal, there is no response at the Module 2 Gecko OS terminal because the server has no record of a client.
If this is a problem, you can simply set up both modules with a UDP server configuration. See below.
Wireless Serial Port using UDP Symmetrical Server Configuration #
UDP is a connectionless protocol, so the terms server and client are used loosely. With Gecko OS, the difference is that a module configured as a UDP server has more options, such as a configurable UDP server port, and some server behavior based on expecting a communication from a client.
If you want either module to be capable of receiving the first communication, just set up both as servers.
Module 1 still runs the softap, but Module 2 has a static IP address and DHCP is not required.
Instead of using a client lock, Module 1 is hard coded with the known IP address and port of Module 2.
Module 1 UDP Server Configuration Settings #
Gecko OS Commands (Module 1) | Description |
---|---|
|
|
On rebooting, Module 1 automatically starts the softap, waits for a UDP message on port 8000 and enters stream mode. Data sent to the Module 1 UART is transmitted over the softap interface to the configured remote host and remote port.
Module 2 UDP Server Configuration Settings #
Gecko OS Commands (Module 2) | Description |
---|---|
|
|
On rebooting, Module 2 sets its static IP, joins the WLAN, waits for a UDP message on port 8008 and enters stream mode. Data sent to the Module 2 UART is transmitted over the wlan interface to the configured remote host and remote port.
More UDP Wireless Magic! #
Type characters into the Module 1 Gecko OS terminal. They appear immediately on the Module 2 Gecko OS terminal.
Alternatively, type characters into the Module 2 Gecko OS terminal. They appear immediately on the Module 1 Gecko OS terminal.
You can send the first message from either module.
High Speed Connections #
The above communications take place with the default UART settings of 115200 baud and no flow control. This is appropriate for a demonstration at human typing speeds. It is possible to use a similar system for high speed communications, for example at UART speeds above 1 Megabaud. In this case it is necessary to configure flow control.
See the High Speed UART app note for examples of configuring baud rates and setting flow control.
Supporting Gecko OS Versions #
- Gecko OS 4
Change Log #
Modified | Changes |
---|---|
2019-01-01 | Created |