WiSnap User Manual 4.41 05282015-ML
Page 42
With the WiSnap module in command mode, type
open
<addr> <port>
. The server will report the connection is open and you
can type characters into the UART window and see them on the server window or vice versa.
12.3 Setting up Automatic Connections
Some applications require the module to connect to a remote server, send data, and then disconnect automatically upon
power up (or wakeup). You can configure the module to perform this functionality automatically.
Set the network SSID and security, and
set
autojoin
to 1. When the module wakes up or is powered on, the auto-connect timer
causes the module to attempt a connection to the stored remote IP address and port. The sleep timer does not decrement
while this connection is open and the idle timer does not decrement while data is flowing. When data stops for 5 seconds the
connection is closed; the sleep timer puts the module in deep sleep. The wake timer begins the cycle again one minute later.
NOTE:
You can also use ad hoc mode (
autojoin
4); however, there will be a delay connecting to the ad hoc network
from the remote computer. Therefore, make the sleep timer large enough to allow the network to get set up and the
auto-connect to establish a TCP connection.
Example: Automatic Connection
-
set ip host
<address>
-
set up the remote machine’s IP address
-
set ip remote_port
<value>
-
set up the remote machine’s IP port
-
set sys autoconn 1 -
automatically connect when ready
-
set com idle 5 -
disconnect after 5 seconds with no data activity
-
set sys sleep 2 -
sleep 2 seconds after connection is closed
-
set sys wake 60 -
wake up after 1 minute of sleep
-
set uart mode 2 -
use UART data trigger mode, which causes the module to make a TCP/HTTP connection
upon incoming UART data (supported in firmware version 2.19 and higher)
12.4 Controlling Connections using PIO5 and PIO6
You can use GPIO5 to control the TCP connection. After you configure the pin with the
set sys iofunc
command, the module
attempts to connect to the stored IP address and port when GPIO5 goes high and disconnects when GPIO5 goes low.
Similarly, you can monitor the connection status by reading GPIO6. When it goes high, the connection is open; when it goes
low, the connection is closed. Use the command
set sys iofunc
command to enable GPIO6.
Example: Use GPIO6 & GPIO6 to Control Connections
-
set sys iofunc 0x20 -
enable GPIO5
-
set sys iofunc 0x40 –
enable GPIO6
12.5 Using DNS settings
The module contains a built-in DNS client. If you do not specify the host’s IP address, (i.e., it is set to 0.0.0.0), the module uses
DNS protocol. When you set the host name using the
set dns name
<string>
command, the module automatically attempts to
resolve the host address. When the address is resolved, the module connects automatically.
Example: Use DNS