WiFly Command Reference Manual 2014-2015 Microchip Technology Inc. DS50002230B Note the following details of the code protection feature on Microchip devices: * Microchip products meet the specification contained in their particular Microchip Data Sheet. * Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the intended manner and under normal conditions. * There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip's Data Sheets. Most likely, the person doing so is engaged in theft of intellectual property. * Microchip is willing to work with the customer who is concerned about the integrity of their code. * Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not mean that we are guaranteeing the product as "unbreakable." Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our products. Attempts to break Microchip's code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act. Information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights unless otherwise stated. Trademarks The Microchip name and logo, the Microchip logo, dsPIC, FlashFlex, flexPWR, JukeBlox, KEELOQ, KEELOQ logo, Kleer, LANCheck, MediaLB, MOST, MOST logo, MPLAB, OptoLyzer, PIC, PICSTART, PIC32 logo, RightTouch, SpyNIC, SST, SST Logo, SuperFlash and UNI/O are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. The Embedded Control Solutions Company and mTouch are registered trademarks of Microchip Technology Incorporated in the U.S.A. Analog-for-the-Digital Age, BodyCom, chipKIT, chipKIT logo, CodeGuard, dsPICDEM, dsPICDEM.net, ECAN, In-Circuit Serial Programming, ICSP, Inter-Chip Connectivity, KleerNet, KleerNet logo, MiWi, motorBench, MPASM, MPF, MPLAB Certified logo, MPLIB, MPLINK, MultiTRAK, NetDetach, Omniscient Code Generation, PICDEM, PICDEM.net, PICkit, PICtail, RightTouch logo, REAL ICE, SQI, Serial Quad I/O, Total Endurance, TSHARC, USBCheck, VariSense, ViewSpan, WiperLock, Wireless DNA, and ZENA are trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. SQTP is a service mark of Microchip Technology Incorporated in the U.S.A. Silicon Storage Technology is a registered trademark of Microchip Technology Inc. in other countries. GestIC is a registered trademark of Microchip Technology Germany II GmbH & Co. KG, a subsidiary of Microchip Technology Inc., in other countries. All other trademarks mentioned herein are property of their respective companies. (c) 2014-2015, Microchip Technology Incorporated, Printed in the U.S.A., All Rights Reserved. ISBN: 978-1-63277-737-9 QUALITY MANAGEMENT SYSTEM CERTIFIED BY DNV == ISO/TS 16949 == DS50002230B-page 2 Microchip received ISO/TS-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in Chandler and Tempe, Arizona; Gresham, Oregon and design centers in California and India. The Company's quality system processes and procedures are for its PIC(R) MCUs and dsPIC(R) DSCs, KEELOQ(R) code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory and analog products. In addition, Microchip's quality system for the design and manufacture of development systems is ISO 9001:2000 certified. 2014-2015 Microchip Technology Inc. WiFly COMMAND REFERENCE MANUAL Table of Contents Chapter 1. Introduction 1.1 Overview ...................................................................................................... 11 1.2 Features ....................................................................................................... 12 1.3 Supported Access Points ............................................................................. 12 Chapter 2. Getting Started 2.1 Prerequisites ................................................................................................ 13 2.2 Firmware Version Check .............................................................................. 13 2.3 Common Tasks ............................................................................................ 14 Chapter 3. Features and Settings 3.1 Factory Reset ............................................................................................... 21 3.2 Associating to An Access Point .................................................................... 27 3.3 Making A Connection To the RN Module ..................................................... 38 3.4 Connecting the RN Module to a Remote Device .......................................... 38 3.5 Sending Data To a Remote Host ................................................................. 40 3.6 Using the HTML Client Feature .................................................................... 46 3.7 FTP Client Features ..................................................................................... 51 3.8 Putting the RN Module to Sleep and Waking It ............................................ 53 3.9 GPIO Functions ............................................................................................ 56 3.10 Setting Debug Print Levels ......................................................................... 59 3.11 Using the Real-Time Clock Function .......................................................... 61 3.12 Time Stamping Packets ............................................................................. 62 3.13 Soft Access Point (Soft AP) Mode .............................................................. 63 3.14 Upgrading Firmware ................................................................................... 67 3.15 Analog Sensor Capability ........................................................................... 74 Chapter 4. Command Reference 4.1 Command Syntax ......................................................................................... 77 4.2 Command Organization ............................................................................... 78 4.3 Set Commands ............................................................................................. 79 4.4 Get Commands .......................................................................................... 132 4.5 Status Commands ...................................................................................... 135 4.6 Action Commands ...................................................................................... 138 4.7 File I/O Commands .................................................................................... 144 2014-2015 Microchip Technology Inc. DS50002230B-page 3 WiFly Command Reference Manual NOTES: DS50002230B-page 4 2014-2015 Microchip Technology Inc. WiFly COMMAND REFERENCE MANUAL Preface NOTICE TO CUSTOMERS All documentation becomes dated, and this manual is no exception. Microchip tools and documentation are constantly evolving to meet customer needs, so some actual dialogs and/ or tool descriptions may differ from those in this document. Please refer to our web site (www.microchip.com) to obtain the latest documentation available. Documents are identified with a "DS" number. This number is located on the bottom of each page, in front of the page number. The numbering convention for the DS number is "DSXXXXXXXXA", where "XXXXXXXX" is the document number and "A" is the revision level of the document. For the most up-to-date information on development tools, see the MPLAB(R) X IDE on-line help. Select the Help menu, and then Topics to open a list of available on-line help files. INTRODUCTION This preface contains general information that will be useful to know before using the WiFly application to access RN modules. Topics discussed in this preface include: * * * * * * * Document Layout Conventions Used in this Guide Recommended Reading The Microchip Web Site Development Systems Customer Change Notification Service Customer Support Document Revision History DOCUMENT LAYOUT This user's guide provides information for configuring RN modules using the WiFly application, including a command reference, advanced features, and applications. The document is organized as follows: * Chapter 1. "Introduction" - This chapter introduces the RN modules and provides a brief overview of their features. * Chapter 2. "Getting Started" - This chapter provides information that is useful when getting started with an RN module. * Chapter 3. "Features and Settings" - This chapter describes features and settings, including techniques to put the RN module to sleep, wake up, and methods to open a TCP connection when awake. * Chapter 4. "Command Reference" - This chapter provides information on the commands used to configure RN modules and gives examples. 2014-2015 Microchip Technology Inc. DS50002230B-page 5 WiFly Command Reference Manual CONVENTIONS USED IN THIS GUIDE This manual uses the following documentation conventions: DOCUMENTATION CONVENTIONS Description Italic characters Initial caps Examples Referenced books MPLAB IDE User's Guide Emphasized text ...is the only compiler... A window the Output window A dialog the Settings dialog A menu selection select Enable Programmer Quotes A field name in a window or dialog "Save project before build" Underlined, italic text with right angle bracket A menu path File > Save Bold characters A dialog button Click OK A tab Click the Power tab Text in angle brackets < > A key on the keyboard Press , Plain Courier New Sample source code #define START Filenames autoexec.bat File paths c:\mcc18\h Keywords _asm, _endasm, static Command-line options -Opa+, -Opa- Bit values 0, 1 Constants 0xFF, `A' Italic Courier New A variable argument file.o, where file can be any valid filename Square brackets [ ] Optional arguments mcc18 [options] file [options] Curly brackets and pipe character: { | } Choice of mutually exclusive arguments; an OR selection errorlevel {0|1} Ellipses... Replaces repeated text var_name [, var_name...] Represents code supplied by user void main (void) { ... } Notes DS50002230B-page 6 Represents A Note presents information that we want to re-emphasize, either to help you avoid a common pitfall or to make you aware of operating differences between some device family members. A Note can be in a box, or when used in a table or figure, it is located at the bottom of the table or figure. Note: This is a standard note box. CAUTION This is a caution note. Note 1: This is a note used in a table. 2014-2015 Microchip Technology Inc. Preface RECOMMENDED READING This user's guide describes how to use the WiFly application to configure an RN module. The RN module-specific data sheets contain current information on the RN module specifications. Additional Microchip documents are available and are recommended as supplemental reference resources. To obtain any of these documents, visit the Microchip web site at www.microchip.com. RN131 Module Data Sheet (DS70005085), RN171 Module Data Sheet (DS70005084), and RN1723 Module Data Sheet (DS70005224) Consult these documents for detailed information on the RN131, RN171, and RN1723 modules. Reference information found in this data sheet includes: * Device pinout and packaging details * Device electrical specifications * List of features included on the RN module RN131/RN171/RN1723 Evaluation Kits User's Guide (DS50002183) This user's guide describes the RN evaluation boards that are used for demonstrating the capabilities of the RN131, RN171, and RN1723 modules. These RN evaluation boards have the flexibility to connect directly to a PC or laptops through a standard USB interface or to embedded controllers through the serial UART interface. Reference information in this user's guide includes: * Overview of the evaluation kit hardware and evaluation board features and components * Hardware and module configuration * Sensor interfaces and push button functions * Evaluation board schematics PICDEMTM PIC18 Explorer Demonstration Board User's Guide (DS51721) This document describes how to use the PICDEM PIC18 Explorer Demonstration Board as a development tool to emulate and debug firmware on a target board. Reference information found in this user's guide includes: * Functionality and features * Hardware features * Development board schematics Explorer 16 Development Board User's Guide (DS50001589) This document describes how to use the Explorer 16 Development Board as a development tool to emulate and debug firmware on a target board. Reference information found in this user's guide includes: * Functionality and features * Hardware features * Development board schematics 2014-2015 Microchip Technology Inc. DS50002230B-page 7 WiFly Command Reference Manual THE MICROCHIP WEB SITE Microchip provides online support via our web site at www.microchip.com. This web site is used as a means to make files and information easily available to customers. Accessible by using your favorite Internet browser, the web site contains the following information: * Product Support - Data sheets and errata, application notes and sample programs, design resources, user's guides and hardware support documents, latest software releases and archived software * General Technical Support - Frequently Asked Questions (FAQs), technical support requests, online discussion groups, Microchip consultant program member listing * Business of Microchip - Product selector and ordering guides, latest Microchip press releases, listing of seminars and events, listings of Microchip sales offices, distributors and factory representatives DEVELOPMENT SYSTEMS CUSTOMER CHANGE NOTIFICATION SERVICE Microchip's customer notification service helps keep customers current on Microchip products. Subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. To register, access the Microchip web site at www.microchip.com, click on Customer Change Notification and follow the registration instructions. The Development Systems product group categories are: * Compilers - The latest information on Microchip C compilers and other language tools * Emulators - The latest information on the Microchip in-circuit emulator, MPLAB(R) REAL ICETM in-circuit emulator * In-Circuit Debuggers - The latest information on the Microchip in-circuit debugger, MPLAB ICD 3 * MPLAB X IDE - The latest information on Microchip MPLAB X IDE, the Windows(R) Integrated Development Environment for development systems tools * Programmers - The latest information on Microchip programmers including the PICkitTM 3 development programmer CUSTOMER SUPPORT Users of Microchip products can receive assistance through several channels: * * * * Distributor or Representative Local Sales Office Field Application Engineer (FAE) Technical Support Customers should contact their distributor, representative or field application engineer (FAE) for support. Local sales offices are also available to help customers. A listing of sales offices and locations is included in the back of this document. Technical support is available through the web site at: http://support.microchip.com DS50002230B-page 8 2014-2015 Microchip Technology Inc. Preface DOCUMENT REVISION HISTORY Revision A (January 2014) This is the initial released version of the document. Revision B (September 2015) This revision includes the following updates: * Information specific to the RN1723 module was added throughout the document * The content was reorganized, which includes text and formatting updates that were incorporated throughout the document 2014-2015 Microchip Technology Inc. DS50002230B-page 9 WiFly Command Reference Manual NOTES: DS50002230B-page 10 2014-2015 Microchip Technology Inc. WiFly COMMAND REFERENCE MANUAL Chapter 1. Introduction This reference manual provides information on the commands and features for Microchip products that utilize the WiFly radio module command set. The WiFly radio module is a complete, stand-alone embedded wireless LAN access device. The device has an on-board TCP/IP stack and applications, and in the simplest hardware configuration, requires only four pins: Power, TX, RX, and Ground. Once the initial configuration has been performed, the device automatically accesses a Wi-Fi(R) network and sends/receives serial data. Topics covered include: * Overview * Features * Supported Access Points 1.1 OVERVIEW This document is applicable to the stand-alone RN131, RN171, and RN1723 modules, as well as Microchip products based on these modules. For example, the RN171XV device incorporates the RN171 module; therefore, all RN171 hardware features apply to the RN171XV. Although there are some differences, the RN131, RN171, and RN1723 modules support the same ASCII command set. Table 1-1 compares the RN module features. TABLE 1-1: COMPARING THE RN131, RN171, AND RN1723 MODULES Feature RN131 RN171 and RN1723 Output power (PMAX) 18 dBm (fixed) 12 dBm (programmable) Lowest power 18 dBm 0 dBm (< 100 mA TX current) On-board antenna Yes No Accurate sleep timer Yes (32 kHz) No (+/- 10% error) GPIO pins available 10, GPIO4-13 (GPIO1-3 are not avail- 14, GPIO1-14 able for use) Refer to "Recommended Reading" for information on accessing the RN131, RN171, and RN1723 Data Sheets for information on their hardware differences and for detailed hardware specifications. 2014-2015 Microchip Technology Inc. DS50002230B-page 11 WiFly Command Reference Manual 1.2 FEATURES General: * Fully qualified and Wi-Fi certified 2.4 GHz IEEE 802.11 b/g transceiver * FCC, CE, IC certified, and RoHS compliant Ultra-low Power: * * * * Intelligent, built-in power management with programmable wake-up Accepts 3.3V power supply or 2 to 3V battery when using boost regulators RN131: 4 A sleep, 35 mA RX, 210m TX at 18 dBm (TX power is not configurable) RN171 and RN1723: 4 A sleep, 35 mA RX, 185 mA TX at 12 dBm (TX power is configurable) Antenna Options: * RN131: On-board ceramic chip antenna and U.FL connector for external antenna * RN171 and RN1723: RF pad Hardware: * 8-Megabit Flash memory and 128 Kbyte RAM, 2 Kbyte ROM, 2 Kbyte batterybacked memory * General purpose digital I/O pins: - RN131: 10 GPIO pins - RN171 and RN1723: 14 GPIO pins * Eight analog inputs (14 bits, 1.2V) * Real-time clock for wake-up and time stamping/data logging; automatic sleep and automatic wake-up modes Network support: * * * * * * * 1.3 Supports Soft AP mode and Infrastructure networking modes Push button WPS mode for easy network configuration On-board TCP/IP stack Over the air firmware upgrade (FTP) Secure Wi-Fi authentication via WEP, WPA-PSK (TKIP), and WPA2-PSK (AES) Configuration over UART or wireless interfaces using simple ASCII commands Built-in networking applications: DHCP client, DNS client, ARP, ICMP ping, FTP client, Telnet, HTTP, UDP, and TCP SUPPORTED ACCESS POINTS The RN module should work with any standard Access Point (AP). Microchip has tested the RN modules with Access Points from the following manufacturers: * * * * * * * * * * * * DS50002230B-page 12 Airlink101(R) Apple(R) ASUS Belkin Buffalo Networks Inc. Cisco D-Link(R) Dynex(R) Linksys NETGEAR SMC(R) Networks TP-LINK 2014-2015 Microchip Technology Inc. WiFly COMMAND REFERENCE MANUAL Chapter 2. Getting Started This chapter provides information for the purpose of getting started with using an RN module. All of the commands discussed in this chapter are described in detail in Chapter 4. "Command Reference". Topics in this chapter include: * Prerequisites * Firmware Version Check * Common Tasks 2.1 PREREQUISITES Prior to using an RN module for the first time, readers should be familiar with the information in the "RN131/RN171/RN1723 Evaluation Kits User's Guide" (DS50002183), which is available from the Microchip website (www.microchip.com). Refer to "Recommended Reading" for information on additional resources. 2.2 FIRMWARE VERSION CHECK The set of available commands and features for a particular RN module depend greatly on the installed file system contents. Each RN module is loaded with firmware prior to leaving the factory. Consult the Microchip website for firmware information by visiting: http://www.microchip.com/wifi. The RN module has a file system for storing firmware, as well as configuration files. To view the firmware version, use the ls command. The file size is displayed in sectors and the active boot image is identified in the final message. The WiFly firmware version returned by the ls command is shown in bold type in Example 2-1. EXAMPLE 2-1: FL# 2 5 8 10 12 25 26 28 SIZ 88328 74432 46836 66677 51053 512 7268 1060 2014-2015 Microchip Technology Inc. DETERMINING THE FIRMWARE VERSION FLAGS 3 wifly-FZX-100-r1634i 3 web_app-FZX-112 3 wps_app-FZX-131 3 eap_app-FZX-105 0 web_config.html 0 link.html 0 logo.png 10 config DS50002230B-page 13 WiFly Command Reference Manual 2.3 COMMON TASKS This section provides information on the common tasks users may perform when using an RN module, which includes the following topics: * * * * * * Configuring the RN Module Performing a Factory Reset Provisioning Onto and Associating With a Wi-Fi Network Sending Data Creating a Soft Access Point Module Sleep and Wake-up 2.3.1 Configuring the RN Module The RN module has two modes of operation: Data mode and Command mode. In Data mode, the RN module can accept incoming connections or initiate outgoing connections. To configure parameters and/or view the current configuration, the RN module must be placed into Command mode. 2.3.1.1 ENTERING COMMAND MODE By default, the RN module is in Data mode after power-up. Sending the escape sequence of three dollar signs, $$$, causes the RN module to enter Command mode. The three dollar sign ($) characters must be sent in succession with no additional characters before or after. A carriage return () or line feed must not be sent after entering $$$ to enter Command mode. After entering the sequence, the RN module replies with CMD to indicate it is in Command mode. Once in Command mode, the RN module can be configured using simple ASCII commands, with each command ending with a carriage return . Most valid commands return AOK, with the exception of the RN1723, which returns OK; invalid commands return a ERR description. To exit Command mode, send an exit command by typing exit following by a . The RN module responds with EXIT, indicating that it has exited Command mode and has entered Data mode. Note: 2.3.1.2 There is a 250 ms time buffer before and after the $$$ escape sequence. If characters are sent before or after the escape sequence within this 250 ms interval, the RN module treats them as data and passes them over the TCP or UDP socket, and the RN module will not enter Command mode. PARAMETERS Various parameters can be viewed, such as the SSID, channel, IP address, serial port, and other settings, which can be configured in Command mode. 2.3.1.3 SENDING COMMANDS Commands must be sent to the RN module through the UART or remotely via Telnet (Telnet can only be used with the RN131 and RN171). When using the UART interface, the communications settings should match the RN module's stored settings. The default settings are 9,600 baud, 8 bits, No parity, 1 Stop bit, and Hardware Flow Control disabled. Command mode can be entered locally over the UART interface at any time regardless of an active TCP connection. Note: DS50002230B-page 14 Depending on the operating system, Microchip suggests using one of the following terminal emulator applications: Tera Term (Windows) or CoolTerm (Mac). 2014-2015 Microchip Technology Inc. Getting Started 2.3.1.4 AUTOMATIC ACCESS POINT ASSOCIATION When the RN module powers up, it attempts to automatically associate with the Access Point stored in its configuration settings if the auto-join feature is enabled. In firmware version 4.0 and later, the auto-join feature is disabled by default. Enable it using the ASCII command set wlan join 1. The auto-associate feature can be disabled (default behavior) using the set wlan join 0 command. This command prevents the RN module from attempting to associate with a network that does not exist. 2.3.2 Performing a Factory Reset The factory RESET command initializes all of the WiFly module parameters to their factory default values. The default parameters only take effect after the RN module has been rebooted. Refer to 3.1.1 "Default Parameters After Factory Reset" for more information. To perform a factory reset, first issue the factory RESET command and then reboot the RN module, as follows: factory RESET reboot 2.3.3 // restores default parameter values // restart module; default parameters take effect Provisioning Onto and Associating With a Wi-Fi Network Before being allowed to communicate on a Wi-Fi network, an RN module must first be provisioned, associated to an Access Point in the network, and have a valid IP address. There a three common ways to provision and associate an RN module onto a Wi-Fi Network: * Association using Command mode (via a USB-UART connection) This is the most commonly used method, which is described in the next section. * Association through WPS * Association through a web interface Note: For information on associating using WPS or a web interface, consult the "RN131/RN171/RN1723 Evaluation Kits User's Guide" (DS50002183), which is available from the Microchip website (www.microchip.com). 2014-2015 Microchip Technology Inc. DS50002230B-page 15 WiFly Command Reference Manual 2.3.3.1 ASSOCIATION USING COMMAND MODE To associate using Command mode, perform the following steps: 1. Connect the RN evaluation board to the host (computer) using the USB connection. The green LED should begin blinking. 2. Open the terminal emulator application on the host. 3. Configure the serial port: a) Locate the COM port that is assigned to the USB cable connected to the RN evaluation kit. b) In the Terminal Emulator, select the COM port and open the Serial Port Setup dialog and make the following selections: * Baud rate: 9600 * Data bits: 8 * Parity: None * Stop bits: 1 * Flow control: None 4. Enter Command mode by sequentially typing $$$ with no other characters before or after (by default, the RN module is in Data mode). 5. In the terminal emulator, type scan and press to actively scan for available networks. 6. To associate with the desired AP or network, enter the following commands in the terminal emulator. DS50002230B-page 16 set wlan ssid // Sets the RN module to automatically // associate with the specified network // upon boot-up. set wlan pass // Provides the password to connect to // the specified network set wlan join 1 // // // // // save // Save the settings to a file named // config (default) reboot // Force a reboot Sets the policy for automatically associating with Access Points. In this case, the `1' refers to associating with an AP that matches the stored SSID 2014-2015 Microchip Technology Inc. Getting Started 2.3.4 Sending Data After the RN module has associated with a network and a valid IP address has been obtained, data can be sent between two RN modules or from an RN module to a server. Two methods to transfer data are available: TCP and UDP. TCP is the most common method, which is described in this section. Refer to the "RN131/RN171/RN1723 Evaluation Kits User's Guide" (DS50002183) for information on transferring data through UDP. Perform the following steps to transfer data using TCP: 1. Configure two RN modules to associate with an AP, as described in 2.3.3 "Provisioning Onto and Associating With a Wi-Fi Network". 2. Obtain the IP address assigned to each RN module using the get ip command, as shown in the below example. In this example, the IP addresses assigned are 192.168.1.108 and 192.168.1.109. 3. On one of the RN modules, open a socket using the following commands: set ip proto 0x2 // Sets the IP protocol. The parameter // 0x2 is a bit-mapped register, which // sets the protocol to TCP. set ip host 192.168.1.109 // Sets the IP address of the remote host set ip remote 2000 // Sets the port number of the remote host open // Opens a TCP connection The terminal emulators on the local host and remote host respond with *OPEN**HELLO* to indicate the connection was opened successfully. Typing into one terminal emulator will display the result on the other terminal emulator. Remote Host Local Host 4. Use the close command to close the socket and disconnect TCP. 2014-2015 Microchip Technology Inc. DS50002230B-page 17 WiFly Command Reference Manual 2.3.5 Creating a Soft Access Point In Soft Access Point (Soft AP) mode, the RN module provides the following capabilities: * Creates a Soft AP network to which client devices, such as smartphones and tablets can join * Runs a DHCP server and issues IP addresses to a maximum of seven clients * Supports security * Supports routing between clients (only when security is not enabled) There are two methods, Hardware and Software, to enable Soft AP mode on an RN module. Enabling Soft AP mode in hardware is done by holding the GPIO9 pin high (at 3.3V), and then resetting the RN module by cycling the power. The RN module will boot-up in Soft AP mode. To enable Soft AP mode in software, the apmode command is used. Once an RN module is in Soft AP mode, any client device can associate with the network the RN module is broadcasting. 2.3.5.1 CUSTOMIZED SOFT AP MODE NETWORK SETTINGS The following commands illustrate customized network settings that can be used after enabling Soft AP mode: set wlan join 7 // // // // Creates a Soft AP network using stored configuration values. The AP is created upon power-up, reboot, or waking from sleep. set apmode ssid // Set the network broadcast SSID set apmode passphrase // Set the AP mode passphrase set ip address
// Specify the IP address save // Save the settings reboot // Reboot the RN module in Soft AP mode Refer to 3.13 "Soft Access Point (Soft AP) Mode" for detailed information on both methods. DS50002230B-page 18 2014-2015 Microchip Technology Inc. Getting Started 2.3.6 Module Sleep and Wake-up There are three methods by which an RN module can be placed into Sleep mode. * The first method is by using the sleep command through the UART interface * The second method is to use the sleep timer through the internal RTC interface. In this method, the RN module sleeps for the number of seconds specified in the set sys wake command. * The third method is to drive the GPIO8 pin high. In this method, the RN module sleeps as soon as the GPIO8 pin is set high. To enable this feature, use the set sys trigger 0x20 command. 2.3.6.1 USING TIMERS FOR SLEEP AND WAKE-UP WiFly-based RN modules have a set of timers that can be used to both put the RN module to sleep and to wake-up the RN module. While the RN module is sleeping, it consumes only 4 A of current. During the time the RN module is awake, it can be made to perform any operation the application requires. The following set of commands illustrate one method of periodically putting the RN module to sleep for a period of time, and then waking up the RN module: set wlan ssid my_net // Sets the SSID to connect to after // waking up set wlan passphrase my_pass // Set the connection passphrase set sys sleep 30 // Set the RN module to sleep after being // awake for 30 seconds set sys wake 90 // Wakes the RN module after being in // sleep for 90 seconds save // Save the settings reboot // Reboot the RN module Refer to 3.8 "Putting the RN Module to Sleep and Waking It" for more information. 2014-2015 Microchip Technology Inc. DS50002230B-page 19 WiFly Command Reference Manual NOTES: DS50002230B-page 20 2014-2015 Microchip Technology Inc. WiFly COMMAND REFERENCE MANUAL Chapter 3. Features and Settings This chapter describes the RN module's features and settings, including techniques for placing the RN module into sleep mode and waking up the RN module, as well as methods to open a TCP connection when the RN module is awake. In addition, the UART flow control, alternative GPIO functions, and the real-time clock are described. The following topics are discussed: * * * * * * * * * * * * * * * 3.1 Factory Reset Associating to An Access Point Making A Connection To the RN Module Connecting the RN Module to a Remote Device Sending Data To a Remote Host Using the HTML Client Feature FTP Client Features Putting the RN Module to Sleep and Waking It GPIO Functions Setting Debug Print Levels Using the Real-Time Clock Function Time Stamping Packets Soft Access Point (Soft AP) Mode Upgrading Firmware Analog Sensor Capability FACTORY RESET Performing a factory reset on an RN module initializes all of the RN module parameters to their factory default state. This is accomplished by first issuing the factory RESET command, immediately followed by the reboot command. Internal to the RN module, the factory RESET command loads all of the default parameter settings into RAM, and then writes these settings into a standard configuration file that the RN module maintains. When the RN module is subsequently rebooted, the settings that were saved in the configuration file take effect. Microchip recommends that before any major operational modes changes are made to an RN module, that a factory RESET and a reboot command be executed. One such example is switching the RN module from operating as a Soft AP to that of a HMTL client. In this instance, the procedure would be to first factory Reset and reboot the RN module, set it up as a HTML client, save the configuration, and then reboot the RN module a second time. 3.1.1 "Default Parameters After Factory Reset" lists all of the default WiFly settings for an RN module. 2014-2015 Microchip Technology Inc. DS50002230B-page 21 WiFly Command Reference Manual 3.1.1 Default Parameters After Factory Reset TABLE 3-1: SOFT AP MODE PARAMETERS Parameter Default Value Comment Beacon 102 Time in milliseconds. For Soft AP mode only. Probe 5 Number of seconds for beacons before declaring Soft AP is lost. For Soft AP mode only. Reboot 0 For Soft AP mode only. TABLE 3-2: BROADCAST PARAMETERS Parameter Default Value IP address Port 255.255.255.255 55555 Interval Backup address 7 0.0.0.0 Backup port 0 TABLE 3-3: Comment -- -- Time in seconds. -- -- COMM PARAMETERS Parameter Default Value Comment Close string *OPEN* -- Open string Remote string *CLOS* *HELLO* -- -- Flush size Match character 1420 0 -- -- Flush timer Idle timer 10 0 CMD char $ TABLE 3-4: Parameter IP address Name Backup Lease TABLE 3-5: Parameter Server address File Time in milliseconds. -- -- DNS PARAMETERS Default Value 0.0.0.0 dns1 rn.microchip.com 8640 Comment -- -- -- For Soft AP mode only. FTP PARAMETERS Default Value Comment 0.0.0.0 wifly-GSX-.img wifly-EZX.img wifly-FZX.img wifly3-.mif -- Firmware for RN131 modules. Firmware for RN171 modules. Firmware for RN1723 modules. Firmware and applications for RN131 modules. Firmware and applications for RN171/RN1723 modules. -- -- -- -- -- wifly7-.mif User Password Dir Timeout FTP_mode DS50002230B-page 22 roving Pass123 public 200 0x0 2014-2015 Microchip Technology Inc. Features and Settings TABLE 3-6: IP PARAMETERS Parameter Default Value DHCP ON Comment `1' equals enabled. IP address 0.0.0.0 -- Net mask 255.255.255.0 -- Local port 2000 -- Gateway 0.0.0.0 -- Host 0.0.0.0 -- Remote port 2000 -- Protocol 2 MTU 1524 -- Flags 0x7 -- TCP mode 0x7 -- Backup 0.0.0.0 -- TABLE 3-7: TCP server and client. OPTIONAL PARAMETERS Parameter Default Value Device ID Comment WiFly-GSX -- Join timer/WPA timer 1000 -- Replacement char $ Format 0x00 Password "" Signal 0 -- Average 5 -- TABLE 3-8: 0x24 -- No password enforced. SYSTEM PARAMETERS Parameter Default Value Comment Sleep timer 0 Wake timer 0 Trigger 0x1 Auto connect 0 IOfunc 0x0 No alternate functions. 0x20F0 For RN131 modules. 0x21F0 For RN171 and RN1723 modules. IOmask -- -- SENS0 pin wakes up the device. -- IOvalue 0x0 Print level 0x1 Print enabled Debug Register 0x0 Unused parameter for future development. Leave at default value. LaunchString web_app TABLE 3-9: -- -- TIME SERVER PARAMETERS Parameter Default Value Comment Enable 0 Disabled. Server address 64.90.182.55 Fixed to Port 123 - SNTP protocol. Zone 7 Pacific time zone (USA). 2014-2015 Microchip Technology Inc. DS50002230B-page 23 WiFly Command Reference Manual TABLE 3-10: UART PARAMETERS Parameter Baudrate Default Value Comment 9600 -- Flow 0 Mode 0 -- Cmd_GPIO 0 -- TABLE 3-11: Disabled. WLAN PARAMETERS Parameter Default Value Comment SSID roving1 Channel 0 Automatic scan. External antenna 0 Off - use on-board chip antenna. For RN131 modules only. Join mode 1 Automatically scan and join based on SSID. 0 Automatic scan and join is disabled. Authentication mode OPEN -- -- Mask 0x1FFF All channels. Rate 12 24 Megabit. Linkmon 0 -- Passphrase rubygirl -- TX Power 0 3.1.2 Implies 12 dBm. For RN171 modules only. String Variable Sizes Table 3-12 provides the string variable sizes for the following parameters: TABLE 3-12: STRING VARIABLE SIZES Parameter Type FTP wlan DS50002230B-page 24 Parameter Value (Bytes) file 32 user 16 pass 16 dir 32 ssid 32 phrase 64 DNS DNS host name 64 DNA back-up host name 64 comm open 32 close 32 remote 64 deviceid 32 2014-2015 Microchip Technology Inc. Features and Settings 3.1.3 Restoring Default Configuration Settings 3.1.3.1 RESTORING THROUGH SOFTWARE AND HARDWARE The default factory configuration settings can be restored in software and hardware. * Software - In Command mode, use the factory RESET command to restore the default settings. This command automatically loads the default settings and executes a save command. Next, send the reboot command so that the RN module reboots with the default configuration. * Hardware - Set the GPIO9 pin high on power-up to enable the factory reset function. Then, toggle GPIO9 five times, which restores the configuration to the factory reset. The GPIO9 pin is sampled at approximately 1 Hz; therefore, if a CPU is used to generate the signal, ensure that GPIO9 transitions (high-to-low or low-to-high) for a period of at least one second. 3.1.3.2 Note: USER CONFIGURATION FILE The user configuration file can be specified based on firmware version, as follows: * RN131 and RN171 modules with firmware version 2.45 and later * RN1723 modules with firmware version 1.0 or later A user configuration file can be specified and then used to restore a custom set of factory reset settings. For example, if the configuration file named user is found on the RN module's file system, the RN module reads it as the factory default instead of using the factory hardcoded defaults. If no user configuration file is present, the RN module uses the hardcoded factory defaults. The user configuration file is created using the save user command, which saves the current configuration settings into a file named user. Even if a user configuration file exists, enabling and toggling the GPIO9 pin seven times overrides the user settings and restores the RN module to the factory hardcoded defaults. This bypass mechanism allows the factory defaults to be restored in the event that an invalid parameter was saved in the user-defined configuration file. Issuing the factory RESET command while in Command mode restores the RN module to a factory default state. Note: 3.1.4 The RN module must be rebooted or Reset for the new settings to take effect. Boot-up Timing Values Table 3-13 shows the boot-up timing values. TABLE 3-13: BOOT-UP TIMING VALUES Function Description Time (ms) Power-up Power-up time from reset high or from the time of power-up to when boot code is loaded from Flash to RAM. 70 Initialization Initialize ECOS. 50 Ready Load configuration and Initialize application. 30 2014-2015 Microchip Technology Inc. DS50002230B-page 25 WiFly Command Reference Manual TABLE 3-13: Function Join Description Time (ms) Associate using channel = 0 (full channel scan, mask = 0x1FFF). 80 Associate using channel = 0 (primary channel scan, mask = 0x421) 15 Associate using channel = X (fixed channel) 5-20 Authentication Authenticate using WPA1 or WPA2 (highly dependent on access point response) 50-250 Acquire IP DS50002230B-page 26 BOOT-UP TIMING VALUES DHCP obtain IP address (highly dependent on DHCP server response time) Soft AP Dependent 2014-2015 Microchip Technology Inc. Features and Settings 3.2 ASSOCIATING TO AN ACCESS POINT Configuring the RN module to make connections involves associating with an Access Point and opening a connection. Before the RN module can be configured over the Wi-Fi link, the RN module must be associated with a network and the network settings must be programmed. Therefore, the best method is to configure the RN module is by using the UART. This section describes how to configure the RN module over the UART using the RS-232 connector or an evaluation board. For this mode, open a terminal emulator on the COM port associated with the RN module. The default baud rate is 9,600, 8 bits, and No parity. 3.2.1 Associate With an Access Point From within the terminal window, place the RN module into Command mode by typing $$$. The RN module responds with CMD, indicating that it is in Command mode. Type show net to display the current network settings, as shown in Figure 3-1. FIGURE 3-1: DISPLAY CURRENT NETWORK SETTINGS CMD show net SSid=TheLoft Chan=6 Assoc=OK DHCP=OK Time=FAIL Links=1 <2.03> Find all available networks with the scan command, as shown in Figure 3-2. FIGURE 3-2: FIND AVAILABLE NETWORKS CMD scan <2.03> SCAN:Found 6 Num SSID 1 roving1 2 NETGEAR 3 07FX12018434 4 TheLoft 5 airlink-11 6 sensor Ch 01 01 06 06 11 11 RSSI Sec -64 Open -58 Open -73 WEP -51 WPA2PSK -53 WPAv1 -52 Open MAC Address Suites 00:1c:df:4f:45:9e 104 00:22:3f:6b:95:42 104 00:18:3a:7e:71:d7 1104 00:0c:41:82:54:19 AESM-AES 00:18:02:70:7e:e8 TKIPM-TKIP 00:1c:df:cc:aa:d8 100 4 0 0 1100 3100 1 0 ac To connect to an open network, use the join command to associate with the access point. The scan list in Figure 3-2 shows that roving1 is an open access point. Type join roving1 (or join # 1) to associate with the network, as shown in Figure 3-3. 2014-2015 Microchip Technology Inc. DS50002230B-page 27 WiFly Command Reference Manual FIGURE 3-3: JOIN THE NETWORK <2.03> join roving1 Auto-Assoc roving1 chan=1 mode=OPEN SCAN OK <2.03> Associated! DHCP in 1ms: Renew: 86400 s IF is UP DHCP=ON IP=10.20.20.62:2000 NM=255.255.255.0 GW=10.20.20.20 HOST=0.0.0.0:2000 PROTO=2 MTU=1460 bind=-10 listen FAIL If the access point is secure, the passphrase must be set prior to issuing the join command. The RN module attempts to inquire and determine the access point's security protocol which means the authentication mode does not need to be set. To set the WPA passphrase use the set wlan passphrase command. For WEP, set the key using the set wlan key command. Once the RN module has joined the network successfully, it stores the access point's SSID. The SSID and the passphrase can be saved to the configuration file so that the RN module can associate with the access point each time it boots. 3.2.2 Wi-Fi Protected Setup (WPS) Wi-Fi Protected Setup (WPS) protocol created by the Wi-FI Alliance is a standard for easy and secure establishment of a wireless home network. The goal of the WPS protocol is to simplify the process of configuring security on wireless networks. The protocol is meant to allow home users who know little of wireless security and may be intimidated by the available security options to configure Wi-Fi Protected Access, which is supported by most Wi-Fi certified devices that are available for purchase today. The most common mode of WPS is the Push Button (PBC) mode, in which the user simply pushes a button on both the access point and the wireless client (e.g., the RN module), as shown in Figure 3-4. FIGURE 3-4: DS50002230B-page 28 PUSH BUTTON WPS 2014-2015 Microchip Technology Inc. Features and Settings Depending on the firmware version, the RN module supports the WPS feature. Note: Use the ls command to confirm whether the RN module supports the application, as shown in Figure 3-5. FIGURE 3-5: 2014-2015 Microchip Technology Inc. CONFIRMING WPS APPLICATION INSTALLATION DS50002230B-page 29 WiFly Command Reference Manual 3.2.2.1 LAUNCHING A WPS APPLICATION There are two ways to run a WPS function: * Using the run wps command in the console * Using GPIO9 To run a WPS function using the factory reset (GPIO9) mode: 1. Enable the WPS function on GPIO9 using the set sys launch wps_app command. WPS on GPIO9 is disabled by default to avoid accidentally running the WPS function. 2. The WPS application is started when GPIO9 asserted. When the WPS application launches, it negotiates the SSID and passphrase with the Soft AP and reboots the RN module to associate with the WPS-enabled access point. Note: Depending on the firmware version, if the GPIO9 pin is high, the RN module boots in Soft AP mode. Care must be taken to drive GPIO9 low before the RN module reboots. A good indicator is the red LED on the RN171 evaluation board. When this LED flashes, indicating the RN module is scanning for a WPS-enabled access point, the GPIO9 pin should be driven low. By default, during the WPS process, the RN module prints messages on the UART as it scans channels, detects access points, and tries to complete WPS. These messages are disabled using the set sys print 0 command. DS50002230B-page 30 2014-2015 Microchip Technology Inc. Features and Settings 3.2.3 Note: Configuration Web Server Depending on the firmware version, the Web Server application is available for use in configuring the RN module, as follows: * RN131 and RN171 modules with firmware version 4.0 and later * RN1723 modules with firmware version 1.0 or later This section describes how to use the RN module's configuration Web server to associate an RN module to an access point. RN modules can operate in one of two modes: Infrastructure and Soft AP. * Infrastructure mode In this mode, the RN module can join a network created by an access point. * Soft AP mode In this mode, the RN module behaves as an access point with limited functionality. A key challenge when using any embedded device in Infrastructure mode is to provision it so that it can associate with a Soft AP. This process requires storing the Soft AP's settings, such as the SSID and passphrase, in the embedded device. Embedded Wi-Fi modules can be configured or provisioned to join an infrastructure network in several ways: * * * * Sending ASCII commands to the RN module over a UART Sending ASCII commands remotely while the RN module is in Soft AP mode Using Wi-Fi Protected Setup (WPS) Sending commands to the RN module remotely using a web interface 3.2.3.1 USING THE CONFIGURATION WEB SERVER Configuring the embedded RN module to associate with an Soft AP in Infrastructure mode involves the following process: 1. Start the RN module's configuration Web Server. 2. Connect the client device (i.e., PC, smartphone, tablet, etc.) to the RN module's Soft AP network. 3. Access the RN module's configuration web page from the client device's web browser. 4. Save the settings (SSID and passphrase) in the web browser and exit. 2014-2015 Microchip Technology Inc. DS50002230B-page 31 WiFly Command Reference Manual 3.2.3.1.1 Start the Configuration Web Server The Web Server can be enabled in one of two ways: hardware or software. When the configuration Web Server is started, it creates a Soft AP network with the settings shown in Table 3-14. TABLE 3-14: SOFT AP NETWORK SETTINGS Setting Soft AP Mode Default SSID * WiFly-GSX-XX (RN131 module) * WiFly-EXZ-XX (RN171) * WiFly-FXZ-XX (RN1723) Where `XX' is the last byte of the RN module's MAC address. Channel 1 DHCP server Enabled IP address 192.168.1.1 Netmask 255.255.255.0 Gateway 192.168.1.1 Note: 3.2.3.1.2 The Soft AP network's SSID uses the RN module's device ID parameter. If the device ID parameter is changed using the set opt device_id command, the RN module uses this new device ID as the Soft AP network's SSID. The device ID parameter is not set to a default if a factory reset is performed. Starting the Configuration Web Server in Hardware The Web Server can be started through hardware using GPIO9. To use GPIO9, specify that the web application should launch using the command set sys launch_string web_app (default configuration). With the launch string set, drive the GPIO9 pin high any time after power-up to start the Web Server. The RN module creates a Soft AP network with the parameters previously described in Table 3-14. Note 1: 2: 3.2.3.1.3 Do not drive GPIO9 high upon power-up. Doing so starts Soft AP mode and does not launch the Web Server. When using an evaluation kit, GPIO9 is accessible using a jumper or push button. Starting the Configuration Web Server in Software If GPIO9 is not accessible using a push button or a jumper, an embedded microcontroller can start the configuration Web Server mode in software using the command run web_app. This command runs the configuration Web Server application and creates a Soft AP network to which devices can join and configure the RN module from a web browser. DS50002230B-page 32 2014-2015 Microchip Technology Inc. Features and Settings 3.2.3.2 STATUS LEDS IN CONFIGURATION WEB SERVER MODE The status LEDs provide a visual indication of the RN module's state while using the configuration Web Server feature, as shown in Table 3-15. TABLE 3-15: STATUS LEDS Event LED Launch Soft AP mode Blink alternately Yellow, blue Off Client associated with the Soft Green AP network Yellow Web browser launched on the Blue client Green Yellow 3.2.3.3 Action Red, green Solid on Blinks fast (twice per second) Solid on Solid on Blinks fast (twice per second) USING THE WEB SERVER TO CONFIGURE THE RN MODULE This section describes how to use the Web Server to configure the RN module with the SSID and passphrase of the Soft AP. The example uses the Internet Explorer web browser running on a Windows 7 personal computer; however, the same concepts apply to any device with a Wi-Fi interface, such as an iPhone, Android smartphone, tablet, or PCs, running a web browser such as Chrome, Firefox, or Safari. To configure the RN module using a web browser, perform the following steps: 1. Associate a PC to the RN module's Soft AP network, as shown in Figure 3-6. FIGURE 3-6: MODULE'S NETWORK NAME 2. Launch a web browser. 2014-2015 Microchip Technology Inc. DS50002230B-page 33 WiFly Command Reference Manual 3. Type http://config to go to the home page of the Web Server running on the RN module. The page has two tabs displayed by default, as shown in Figure 3-7: * Network Configuration This tab is used to set the Soft AP's SSID and passphrase. * Information This tab displays the following information about the RN module: - RN module's MAC address - Module type (RN131 or RN171/RN1723) - List of files on the file system - Battery strength FIGURE 3-7: DS50002230B-page 34 NETWORK CONFIGURATION TAB 2014-2015 Microchip Technology Inc. Features and Settings 4. Select the Network Configuration tab, as shown in Figure 3-7. The RN module's network settings (SSID and passphrase) are configured using this tab. Configure these settings as follows: a) Enter the network's SSID in the Access Point SSID field. Alternatively, click Refresh List. The RN module scans for networks and displays a list of found networks. Select your network from the Available Access Points list or enter it in the Access Point SSID box. Clicking an SSID displays a drop-down menu with more information about that network, such as channel, RSSI, security mode (WEP, WPA, WPA2), capabilities, WAP configurations, WPS configuration, and the Soft AP's MAC address (also called BSSID). If the desired access point is not in the list, click Refresh List to scan again. Note: If the wireless network is hidden (i.e., not broadcasting an SSID), it does not display in the scan output. In this case, the SSID must be manually entered. b) Enter the Soft AP's security passphrase in the Passphrase field. c) (Optional) The RN module uses DHCP by default. To assign the RN module a static IP, turn off the Check to enable DHCP option and enter the static IP, subnet mask, and gateway. d) Once the network settings have been configured, click Save Configuration to save the settings to the RN module. 5. Exit the Web Server by clicking Exit Web Configuration App. The RN module reboots in Infrastructure mode and joins the wireless network. 2014-2015 Microchip Technology Inc. DS50002230B-page 35 WiFly Command Reference Manual 3.2.3.4 USING THE ADVANCED TABS Turning on the Display Advanced Tabs option (bottom right corner of the application window) opens the Terminal and Module Configuration tabs. 3.2.3.4.1 Terminal Tab Click the Terminal tab (see Figure 3-8). In this tab, ASCII commands can be issued to configure any of the RN module's parameters. The Web Server includes a Help utility that guides the user through the RN module configuration. To use this feature, type help in the terminal. FIGURE 3-8: DS50002230B-page 36 TERMINAL TAB 2014-2015 Microchip Technology Inc. Features and Settings 3.2.3.4.2 Module Configuration Tab Click the RN module Configuration tab (see Figure 3-9). In this tab, the RN module's frequently used parameters such as device ID, UART baud rate, and flow control are configured. Other parameters can be configured using ASCII commands in the Terminal tab. FIGURE 3-9: MODULE CONFIGURATION TAB 3.2.3.5 WEB SERVER TIMERS The application includes two timers to ensure that the Web Server runs smoothly: * Idle timer * Browser disconnect timer 3.2.3.5.1 Idle Timer The idle timer ensures that the client associated with the RN module's Soft AP network is not lost or unresponsive. If there is no interaction between the configuration Web Server and the client's web browser for five minutes (default value), the RN module reboots to the boot image. To restart the configuration Web Server, it must be started in software or hardware as described in 3.2.3.1.1 "Start the Configuration Web Server". The time-out defaults to five minutes (300 seconds) and is configurable via the following command: set comm idle 3.2.3.5.2 Browser Disconnect Timer This timer is used to recover from an unexpected situation in which the configuration Web Server on the RN module becomes unresponsive to the requests sent out by the web browser. The web browser periodically sends requests to the configuration Web Server. If the RN module does not receive a request within 60 seconds, it assumes that the configuration Web Server has become unresponsive and it reboots itself into configuration Web Server mode. Then, the device must be reassociated with the RN module's Soft AP network and the web page must be refreshed. 2014-2015 Microchip Technology Inc. DS50002230B-page 37 WiFly Command Reference Manual 3.3 MAKING A CONNECTION TO THE RN MODULE To connect to the RN module from a remote device, open an IP socket and connect to the RN module's IP address. Telnet can be used to test the connection by typing open
in a Telnet window. After the connection is open, characters can be typed in the UART window and viewed in the Telnet window or vise versa. EXAMPLE 3-1: OPEN A CONNECTION open 10.20.20.62 2000 // Open the Host (see Figure 3-3) To make a connection from the RN module the server application's IP address and port number must be known. A COM port redirector is a simple program that can be used to test this functionality. This software opens an IP port and transfers all data it receives to a specified COM port on a user's personal computer. A free COM port redirector program for Windows is available from Pira at: http://www.pira.cz/eng/piracom.htm. In the COM port redirector program, note the IP address of the personal computer by typing the ipconfig command in the Microsoft Command Window. From the terminal emulator, place the RN module into Command mode, and then type the open
command. The server reports that the connection is open and characters can be typed into the UART window and viewed on the server window or vice versa. 3.4 CONNECTING THE RN MODULE TO A REMOTE DEVICE Some applications require the RN module to connect to a remote server, send data, and then disconnect automatically upon power-up (or wake-up). The RN module can be configured to perform this functionality automatically. Set the network SSID and security, and set auto-join to `1'. When the RN module wakes up or is powered on, the auto-connect timer causes the RN 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 five seconds, the connection is closed, and the sleep timer places the RN module in Deep Sleep mode. The wake timer begins the cycle again one minute later. EXAMPLE 3-2: AUTOMATIC CONNECTION set ip host
set set set set set set DS50002230B-page 38 // // ip remote_port // // sys autoconn 1 // com idle 5 // // sys sleep 2 // // sys wake 60 // uart mode 2 // // // // Set up the IP address of the remote machine's IP address Set up the IP port of the remote machine Automatically connect when ready Disconnect after 5 seconds with no data activity Sleep 2 seconds after the connection is closed Wake up after 1 minute of sleep Use UART data trigger mode, which causes the RN module to make a TCP/HTTP connection upon incoming UART data 2014-2015 Microchip Technology Inc. Features and Settings 3.4.1 Controlling Connections using GPIO5 and GPIO6 The GPIO5 pin can be used to control the TCP connection. After configuring the pin with the set sys iofunc command, the RN module attempts to connect to the stored IP address and port when GPIO5 goes high and disconnects when GPIO5 goes low. Similarly, the connection status can be monitored by reading the GPIO6 pin. When it goes high, the connection is open, and when it goes low, the connection is closed. Use the command set sys iofunc command to enable GPIO6. EXAMPLE 3-3: USE GPIO5 AND GPIO6 TO CONTROL CONNECTIONS set sys iofunc 0x20 set sys iofunc 0x40 3.4.2 // Enable GPIO5 // Enable GPIO6 Using DNS Settings The RN module contains a built-in DNS client. If the IP address of the Host is not specified (i.e., it is set to 0.0.0.0), the RN module uses the DNS protocol. When the Host name is set using the set dns name command, the RN module automatically attempts to resolve the Host address. When the address is resolved, the RN module automatically connects. Use the lookup command to manually look up a Host's IP address, where is the host name. EXAMPLE 3-4: USE DNS set dns name my_server // Set the DNS Host name to my_server 3.4.3 Using the Back-up IP Address/Connect Function The RN module contains a feature for auto-retry and redundancy. If the host's first IP address connection fails, the RN module uses the back-up IP (if set). If this fails (or is not set), the RN module uses the first DNS name. If this fails (or is not set), the RN module uses the back-up DNS name (if set). EXAMPLE 3-5: SET THE BACK-UP IP ADDRESS set ip backup
EXAMPLE 3-6: SET THE BACK-UP DNS NAME set dns backup 2014-2015 Microchip Technology Inc. // Set the back-up IP address // Set the back-up Host name DS50002230B-page 39 WiFly Command Reference Manual 3.5 SENDING DATA TO A REMOTE HOST 3.5.1 Controlling Connections with GPIO Pins In embedded applications it is useful to monitor and control the status of the TCP/IP connection. To monitor and control the RN module's connection status, enable the alternate function of GPIO4-GPIO6. Using the alternate function for these GPIO pins, the RN module connects to the stored remote Host IP address and port when GPIO5 is driven high, and disconnects when driven low. The TCP/IP connection status can be monitored by reading GPIO6; it is high when connected, and low when not connected. To configure the RN module to connect using GPIO5 and GPIO6, use the following commands: set ip host
set ip remote set sys iofunc 0x70 save reboot // // // // // Set the IP address of the remote host Set the IP port of the remote host Set alternate function for GPIO4-GPIO6 Store configuration Reboot the RN module After executing these commands, run the application or other software on the remote Host that opens and listens on the specified port. Then, connect GPIO5 to the embedded processor or other control signal. When GPIO5 is driven high, the RN module attempts to connect. When GPIO5 is driven low, the connection is closed. WARNING Do not drive the GPIO pin with more than 3.3V DC or permanent damage to the RN module will occur. If the connection to the remote Host is successful, GPIO6 goes high. If the COMM OPEN and REMOTE strings are set, the UART displays *OPEN* and the remote Host displays *HELLO*. Figure 3-10 shows the process of controlling connections with the GPIO pins. FIGURE 3-10: CONTROLLING CONNECTIONS WITH THE GPIO PINS (PEHGGHG 0LFURSURFHVVRU 7KLVVLJQDOLQVWUXFWVWKHPLFURSURFHVVRUWKDWLWLV2. WRRSHQD7&3FRQQHFWLRQ (YHQWWKHPLFURSURFHVVRUZDQWVWRRSHQD7&3 FRQQHFWLRQWRWKHVWRUHGUHPRWH+RVW 7KLVVLJQDOLQVWUXFWVWKHPLFURSURFHVVRUWKDWWKH7&3 FRQQHFWLRQLVRSHQDQGLWFDQEHJLQVHQGLQJUHFHLYLQJ GDWDRYHUWKH7&3OLQN7RFORVHWKHFRQHQFWLRQWKH PLFURSURFHVVRUGULYHVWKH*3,2SLQORZ DS50002230B-page 40 *3,2SLQ +LJKE\510RGXOH *3,2SLQ +LJKE\0LFURSURFHVVRU *3,2SLQ +LJKE\510RGXOH 51 0RGXOH (YHQW7KH51PRGXOHLVDVVRFLDWHGZLWKDQDFFHVV SRLQWDQGKDVDYDOLG,3DGGUHVV 7KH51PRGXOHLVLQVWUXFWHGWRRSHQD7&3,3FRQQHFWLRQ WRWKHVWRUHGUHPRWHKRVW (YHQW7KH51PRGXOHVXFFHVVIXOO\RSHQVWKH7&3 FRQQHFWLRQWRWKHVWRUHGUHPRWH+RVW 2014-2015 Microchip Technology Inc. Features and Settings 3.5.2 System and Auto-Connect Timers The RN module uses a Real-Time Clock (RTC) to generate timers. The RTC is active even when the RN module is asleep, allowing the RN module to be put to sleep and woken based on timer intervals. The RN module has the following timers: * Sleep timer This timer is used to put the RN module to sleep. It is a 32-bit number, which corresponds to a maximum 1.19 million waking hours. The sleep timer is set with the set sys sleep command, where is a decimal number representing seconds. * Wake timer This timer is used to wake the RN module. It is a 22-bit number, which corresponds to a maximum sleep time of 1,165 hours. The wake timer is set with the set sys wake command, where is a decimal number representing seconds. * Auto-connect timer This timer is used to automatically open a TCP connection. * Idle timer This timer is used to automatically close a TCP connection. The sleep and wake timers are responsible for putting the RN module to sleep and waking up the RN module. If the sleep timer is enabled, the RN module automatically goes into Deep Sleep Low-Power mode once the timer counts down to zero. The sleep timer is disabled if the RN module has an IP connection or is in Command mode. For example, to wake the RN module, join a network, and have the RN module available to accept TCP connections for 30 seconds every two minutes, the timers would be set, as shown in Example 3-7. EXAMPLE 3-7: set wlan ssid my_net set wlan passphrase my_pass set sys sleep 30 set sys wake 90 save reboot // // // // // // // // Set the Host name Set the passphrase Module sleeps after being awake for 30 seconds Module wakes after sleeping for 90 seconds Save the settings Reboot the RN module Figure 3-11 shows the transitions between the sleep and awake state based on the sleep and wake timer settings in the previous example. FIGURE 3-11: SLEEP AND AWAKE STATE TRANSITIONS Awake State Sleep State Sleep Timer 30 s 2014-2015 Microchip Technology Inc. Wake Timer 90 s Sleep Timer 30 s DS50002230B-page 41 WiFly Command Reference Manual 3.5.3 Using TCP To Send Data After the RN module wakes, a TCP connection to a remote host can be opened in a number of ways, as described in Table 3-16. The remote Host is set using the following commands: set ip host
// Sets the IP address of the Host OR set dns name // Sets the URL of the Host set ip remote // // // // // save reboot TABLE 3-16: Sets the port number on which the host is listening Save the settings in the config file Reboot the RN module so that the settings take effect METHODS OF CONNECTING TO A REMOTE HOST Method Type Description Auto connect Internal RTC timer Connect to the Host at specific time intervals based upon the set sys autoconn command setting. Open UART In Command mode, issue the open command. Connect on UART data UART mode 2 This mode is designed for the HTML client feature. Use the set uart mode 2 command to connect the to Host automatically when UART data is received. GPIO5 Alternative GPIO functions Set the alternative functions for GPIO4, GPIO5, and GPIO6, as described in Section 3.13.2.6 "Alternative GPIO4/GPIO5/GPIO6 Functions". Set GPIO5 high to trigger a TCP connection, and low to disconnect. 3.5.3.1 TCP CONNECTION TIMERS The TCP connection timers control when the RN module opens or closes a socket. 3.5.3.1.1 Opening a TCP Connection In TCP Client mode, the auto-connect timer controls the establishment of a socket connection. When set, the device periodically attempts to establish a connection when the timer expires. The set sys autoconn command causes the RN module to connect to the Host periodically. The timer determines how often to connect to the stored remote host. If set to `1', the RN module makes one attempt to auto-connect upon power-up. If set to `2' or higher, auto-connect reopens the connection after the connection is closed. The default value of `0' disables the timer. Note: DS50002230B-page 42 The remote Host's IP address and port number must be specified in the RN module's configuration file for the auto-connect timer to work. 2014-2015 Microchip Technology Inc. Features and Settings 3.5.3.1.2 Closing the TCP Connection The RN module supports a disconnect timer in both TCP Client and Server mode (default mode). This timer can be used to close a TCP connection automatically after a specified number of seconds of no transmit or receive data. To set the disconnect timer, use the set comm idle command, where is the number of seconds. The default comm idle timer value is `0', which means the RN module never disconnects when idle. For example, to close the TCP connection after 5 seconds of inactivity, use the set comm idle 5 command. 3.5.4 Using UDP To Send Data UDP is a connectionless protocol where there is no initial handshaking between the hosts to set up the UDP connection, and the receiver does not send an acknowledgment when it receives UDP packets. Therefore, UDP is an unreliable protocol because there is no guarantee that the data will be delivered correctly. However, because it is connectionless, UDP is suited for applications that cannot tolerate too much latency, but can tolerate some errors in the data, such as video transmission. To use UDP with the RN module, the UDP protocol must be enabled using the set ip proto 1 command. The remote host's IP address and the local and remote port number to be used for UDP communications must also be specified. Example 3-8 and Example 3-9 show the commands to enable UDP data transfer. EXAMPLE 3-8: ASSOCIATE WITH A NETWORK set wlan ssid set wlan phrase EXAMPLE 3-9: set set set set ip ip ip ip Note: SET UP THE PROTOCOL AND PORT NUMBER proto 1 host
remote local save reboot // Set the network name // Set the passphrase for WPA & WPA2 modes // // // // // // // Enable UDP as the protocol Set the IP address of the remote Host Set the remote port on which the Host listens Set the port number on which the RN module listens Save the settings in the config file Reboot the RN module Attempting to send data by typing characters on the keyboard or if the microcontroller is not sending data fast enough, the RN module sends out packets with fewer data bytes. To avoid this issue, set the flush timer to a higher value. By default, it is set to 10 ms. Forwarding can be disabled based on the flush timer (set comm time 0) or set it to a higher value (set comm time 2000). Because UDP is a connectionless protocol, data begins flowing as soon as the RN module is rebooted. Unlike TCP, it is not necessary to send a set comm open command to establish the connection. The RN module acts like a data pipe where the UART data is sent over the Wi-Fi link via the UDP protocol (in this case) and the data coming from the Wi-Fi link (via UDP protocol in this case) is sent to the UART. 2014-2015 Microchip Technology Inc. DS50002230B-page 43 WiFly Command Reference Manual 3.5.4.1 UDP AUTO-PAIRING With the UDP auto-pairing feature, the RN module temporarily stores the Host IP address of the first remote device that sends a UDP packet to the RN module. This Host IP address is stored in the RN module's RAM, which is cleared when the RN module sleeps or power cycles. This feature allows the RN module to echo to any client that sends a UDP packet. EXAMPLE 3-10: TURN ON AUTO PAIRING set ip host 0.0.0.0 set ip flags 0x40 3.5.4.2 // Set the IP Host to 0.0.0.0 // Set the IP flags to 0x40 UDP RETRY This feature adds a level of reliability to the UDP protocol without adding the complete overhead of the TCP protocol. When enabled, the RN module waits for a response on every UDP packet that is sent (any UDP packet coming back in). If the RN module does not receive the response packet by approximately 250 ms, the same UDP packet is sent out. This process continues until either a UDP response is seen or a new UDP packet is sent from the RN module and is acknowledged. Refer to "set ip flags " for information on the bit to set to enable this feature. 3.5.4.3 UDP BROADCAST The RN module can be set up to generate UDP broadcast packets automatically, which is useful for the following reasons: * Some access points disconnect devices that are idle. UDP broadcast informs the access point that the RN module is alive and wants to stay associated. * Applications can use this feature to automatically discover and configure the RN module. If an application is listening for the UDP broadcast, a number of useful parameters are present in the package that can be used for auto-discovery. For example, the RN module's IP address and port number are part of the packet, thus an application can connect to the RN module and remotely configure it. * The associated access point's MAC address, channel, and RSSI value are also available in this packet, enabling a simple location and tracking function. By default, the RN module sends out a UDP broadcast to 255.255.255.255 on port 55555 at a programmable interval. The broadcast address, port, and interval are set using the set broadcast commands. Note: DS50002230B-page 44 The RN module's sensor data out can be sent via UDP broadcast. The analog-to-digital converter is 14 bits on a 400 mV signal, which translates to about 24 microvolts (0x61A80 in hex). Using the show q command in Command mode, the RN module displays the raw readings. However, for HTTP web posting and UDP broadcast packets, the RN module shifts the reading by four bits (which is a divide by 16) resulting in a 16-bit number. Therefore, to obtain the actual voltage sampled, the 16-bit number must be shifted left by four bits to get the number of microvolts. If the value in millivolts is known (and high accuracy is not needed), right shift by another six bits, which is the same as dividing by approximately 1K. 2014-2015 Microchip Technology Inc. Features and Settings The packet is 110 bytes of data, as shown in Figure 3-12. FIGURE 3-12: UDP BROADCAST PACKET BYTE FORMAT Position 0 - 5 6 7 8 - 9 10 - 13 14 - 15 16 - 17 18 - 31 32 - 59 60 - 91 92 - 93 94 - 110 Access Point's MAC Address (6 Cytes) Channel (1 Cyte) RSSI (1 Cyte) Local TCP Port (2 Cytes) RTC Value, MSB to LSB (4 Cytes) Battery Voltage PGQJOin mV, e.g., 2755 (2 Cytes) GPIO Pin Value (2 Cytes) ASCII Time (1 Cytes) Version String with Date Code (2 Bytes)Programmable Device ID Set with VHWRSWLRQGHYLFHLGVWULQJ! (32 Cytes) #PPU5JNFJONT CZUFT Sensor 0 - 7 Voltage Readings Enabled with VHWRSWIRUPDWPDVN! (16 Bytes) Note: 3.5.4.4 To add sensor data to the UDP broadcast message, the sensors must be enabled using the sensor mask. The set q sensor 0xff command enables all sensors. UDP SLEEP AND CONNECTION TIMERS In UDP Only Protocol mode (set with the set ip proto 1 command), the auto-connect timer is used as an auto-sleep timer. When the RN module begins to transmit the first UDP data packet, this timer begins counting down. When it reaches zero, the RN module sleeps. The UDP auto-sleep timer can be set using two commands: set sys autosleep and set comm timer. The timer interval is a product of the auto-sleep value and the communication flush timer (in ms). The timer is decremented every "product" millisecond. For example, for a UDP sleep timer of 40 ms, use the following commands: set sys autosleep 4 set comm timer 10 // Set auto-sleep value to 4 // Set comm timer to 10 ms (default value) The resulting UDP sleep timer is four times 10 ms or 40 ms. To achieve the same effect, set autosleep = 2 and comm timer = 20. Note: It is recommended to use a minimum value of 2 (when the default flush time is 10 ms) to ensure that the UDP packet is transmitted. For larger packets, the value should be increased. 2014-2015 Microchip Technology Inc. DS50002230B-page 45 WiFly Command Reference Manual 3.6 USING THE HTML CLIENT FEATURE The RN module has a built-in HTML client. When enabled, the RN module can get or post data to a Web Server. For example, the HTML client can be used to post serial and/or sensor data to the host Web Server. This feature makes it possible to provide Wi-Fi capabilities to applications such as GPS units, remote sensors, and weather stations, among others. 3.6.1 Retrieve Web Server Data In this example, data is retrieved from the Web Server with the format: http://www.webserver.com/ob.php?obvar=WEATHER To perform this function, use the following settings: set set set set ip proto 18 dns name www.webserver.com ip address 0 ip remote 80 set com remote 0 // // // // // // // // Enable the HTML client Set the Web Server name Turn on DNS Set the Web Server port, 80 is standard Turn off the REMOTE string so that it does not interfere with the post To make the connection, use the open command or use open www.webserver.com 80. The user's microprocessor writes the following string to the UART: GET /ob.php?obvar=WEATHER \n\n Where the \n is the line feed character (decimal 10 or hex 0xA). Two line feeds are required for the Web Server to know that the page is complete. Note: 3.6.2 Some Web Servers require a carriage return and a line feed to indicate the page is complete. In this case, use \r\n at the end of the string instead of \n\n. Built-In HTML Client Modes The RN module can be set up to post data to and get data from a Web Server automatically without an external host CPU. These advanced web features are enabled using the set opt format command, where represents a bit-mapped register. Refer to "set opt format " for the bit function descriptions. Table 3-17 describes the wake reason values. TABLE 3-17: WAKE REASON VALUES Value Wake Reason 0 Undefined 1 Power on or hardware reset (battery install or power-up) 2 Sleep (wake when the sleep timer is expired) 3 Sensor 4 Undefined 5 Undefined 6 Software reboot 7 Watchdog EXAMPLE 3-11: HTML CLIENT MODES set option format 1 set option format 7 set option format 11 DS50002230B-page 46 // Automatically send HTML data header // Append sensor data in ASCII hex format // Append all key value pairs to the sensor data 2014-2015 Microchip Technology Inc. Features and Settings 3.6.3 Connect to a Web Server Automatically The RN module can be configured to post data to a Web Server automatically using the set sys auto command, where is a decimal number representing seconds. For example, the RN module can be configured to connect to the Web Server every 10 seconds with the set sys auto 10 command. When HTTP mode is set, the RN module automatically appends two line feeds (\n\n) to the end of the packet. Note: If the HTML header contains spaces, the dollar sign ( $ ) character must be used to indicate spaces in the string (a space is the command delimiter). When the RN module's command parser sees the $, it converts it to a space character. As shown in the example, use the following commands to configure the RN module to connect to a Web Server every 30 seconds. EXAMPLE 3-12: CONNECT TO WEB SERVER EVERY 30 SECONDS set com remote GET$/ob.php?obvar=WEATHER // Set up the HTML string set sys auto 30 // Auto-connect every 30 seconds. set option format 1 // Send header automatically when the // connection is open set ip proto 18 // Turn on HTTP mode = 0x10 + TCP mode = 0x2 3.6.4 Connect to a Web Server Automatically when UART Data Is Received The RN module supports a mode in which it can connect to the Web Server when it receives UART data. Note: When attempting to send data by typing characters on the keyboard or if the microcontroller is not sending data fast enough, the RN module sends out small packets of data (it sends out many packets of small MTU size). To avoid this issue, set the flush timer to a higher value, such as set comm time 5000. By default, it is set to 10 ms. EXAMPLE 3-13: CONNECT TO WEB SERVER WHEN UART DATA IS RECEIVED set ip proto 18 set dns name www.webserver.com set ip host 0 set ip remote 80 set com remote GET$/userprog.php?DATA= set uart mode 2 // // // // // // // // // Turn on HTTP mode = 0x10 and TCP mode = 0x2 Set the Web Server name Turn on DNS Set the Web server port, 80 is standard Sample server application Automatically connect using data trigger mode When the serial UART data comes in after issuing the commands shown in Example 3-13, the RN module automatically connects to the Web Server, and sends: GET /userprog.php?DATA= \n\n 2014-2015 Microchip Technology Inc. DS50002230B-page 47 WiFly Command Reference Manual 3.6.5 Post Binary Data Web Servers expect ASCII data. If the user data is binary, the RN module can convert the data to ASCII format before sending it to the Web Server. EXAMPLE 3-14: CONVERT DATA FROM BINARY TO ASCII set ip proto 18 set dns name www.webserver.com set ip host 0 set ip remote 80 set com remote GET$/userprog.php?DATA= set option format 1 // // // // // // // // // Turn on HTTP mode = 0x10 and TCP mode = 0x2 Set the Web server name Turn on DNS Set the Web server port, 80 is standard Sample server application Convert binary data to ASCII hex format If the incoming UART data is six bytes of binary data with hex values 0x01, 0xAB, 0x03, 0xFF, 0x05, and 0x06, the RN module sends this string to the Web Server: GET /userprog.php?DATA=01AB03FF0506\n\n 3.6.6 Post Sensor Data Automatically The RN module can send the value of the GPIO and sensor pins to the Web Server automatically. The data arrives as 18 bytes of ASCII hex data in the format: <2 bytes GPIO>. Note: The analog-to-digital converter is 14 bits on a 400 mV signal 400, which translates to about 24 microvolts (0x61A80 in hex). When the show q command is used in Command mode, the RN module displays the raw readings. However, for HTTP web posting and UDP broadcast packets, the RN module shifts the reading by four bits (which is a divide by 16) resulting in a 16-bit number. Therefore, to obtain the actual voltage sampled, the 16-bit number must be shifted left by four bits to get the number of microvolts. If the value in millivolts is known and high accuracy is not needed, right shift the number by another six bits, which is the same as dividing by approximately 1K. EXAMPLE 3-15: POST SENSOR DATA TO WEB SERVER set ip proto 18 set dns name www.webserver.com set ip host 0 set ip remote 80 set com remote GET$/userprog.php?DATA= set q sensor 0xff set sys auto 30 set option format 7 // // // // // // // // // // // // // Turn on HTTP mode = 0x10 and TCP mode = 0x2 Set the Web server name Turn on DNS Set the Web server port, 80 is standard Sample server application Module samples all eight sensor channels Connect every 30 seconds Send the header plus the sampled binary data converted to ASCII format The resulting string sent to the server is: GET /userprog.php?DATA=0F3000001111222233334444555566667777\n\n The data format for this example is: DS50002230B-page 48 2 Bytes GPIO Channel 0 1 2 3 4 5 6 7 0F30 0000 1111 2222 3333 4444 5555 6666 7777 2014-2015 Microchip Technology Inc. Features and Settings 3.6.7 HTML Client Example: Posting Sensor Data Automatically In this example, the RN module connects to the Web Server at the URL, www.rovingnetworks.com/server.php?value=, and posts the sensor data to the Web Server every 60 seconds. Set the network connections as previously described, and set the following additional parameters. set ip proto 18 // Turn on HTTP mode = 0x10 // and TCP mode = 0x2 set dns name www.rovingnetworks.com // Set the Web Server name set ip host 0 // Turn on DNS set ip remote 80 // Set the Web server port, // 80 is standard set com remote GET$/server3.php?value= // Set up the server // application string set sys auto 10 // Automatically connect every 10 seconds set option format 7 // Send the header and sampled binary // data converted to ASCII set q sensor 0xFF // Set the sensor mask to sample all channels save // Save the configuration to the config file reboot // Reboot so that the settings take effect After issuing these commands, the Web Server returns a 200 OK message, as shown in Figure 3-13. FIGURE 3-13: 2014-2015 Microchip Technology Inc. SERVER RESPONSE DS50002230B-page 49 WiFly Command Reference Manual 3.6.8 HTML Client Example: Posting UART Data to a Web Server The RN module can post serial UART data in ASCII or binary format automatically. In this example, when the serial UART data comes in, the RN module connects and sends data to the Web Server in the following format: GET /server.php?value= \n\n Use the following commands to set the parameters: set ip proto 18 // Turn on HTTP mode = 0x10 // and TCP mode = 0x2 set dns name www.rovingnetworks.com // Set the Web Server name set ip host 0 // Turn on DNS set ip remote 80 // Set the Web Server port, // 80 is standard set com remote GET$/server3.php?value= // Set up the server // application string set sys auto 10 // Automatically connect every // 10 seconds set option format 1 // Send a HTML header set uart mode 2 // Connect automatically using data trigger mode save // Save the configuration to the config file reboot // Reboot so that the settings take effect With these settings enabled, the RN module connects to the Web Server every time it receives data on the RX line. Serial data is sent to the host Web Server according to the flush timer and the flush size. Note: The sampled sensor data cannot be appended to the UART data. Enabling option format 7 with set uart mode 2 results in erroneous data. DS50002230B-page 50 2014-2015 Microchip Technology Inc. Features and Settings 3.7 FTP CLIENT FEATURES In addition to downloading firmware via FTP, the RN module can "get" and "put" files to an FTP server. 3.7.1 Connect to an FTP Server By default, the RN module is configured to download the latest firmware from the Microchip FTP server. To configure the RN module to connect to another FTP server, the parameters must be adjusted, as described in Example 3-16. EXAMPLE 3-16: CONNECT TO AN FTP SERVER set ftp address
set ftp dir set ftp user set ftp pass save reboot Note: 3.7.2 // // // // // // // // Set the IP address of the FTP server. The default is 208.109.78.34. Set the directory of the FTP server. The default is public. Set the user name Set the password Save the settings Reboot the RN module This example assumes that the FTP server is already set up and configured correctly and that the RN module is already configured to associate with a wireless network. Creating Files on the FTP Server Once the RN module is configured to connect to the FTP server, it can create files on the FTP server. To create a file, use the ftp put command, where is up to 64 bytes in length. This command creates a file on the FTP server with the name specified in and prints the open string on the UART. By default, the open string is *OPEN*. After *OPEN* appears on the UART, data can be written to the file. There are two options to close the file: * Send the close string, which is *CLOS* by default, or * Use the FTP close timer with the command set ftp timer . Once writing to the file is complete, this timer begins counting down and closes the file when the timer reaches zero. The timer is one-eighth of . For example, to set a five second timer, the command would be: set ftp timer 40. The open and close stings are configurable using the following commands: * set comm open * set comm close EXAMPLE 3-17: PUT FILE ON FTP SERVER ftp put demo.txt set ftp timer 40 2014-2015 Microchip Technology Inc. // Set the open string // Set the close string // Upload the file demo.txt // Close the connection 5 seconds after the // file uploads DS50002230B-page 51 WiFly Command Reference Manual 3.7.3 Retrieving Files from the FTP Server The RN module can retrieve files from the FTP server. The retrieved file is not stored in the RN module's Flash memory. Instead, the RN module acts as a transporter and passes the file over the UART interface as the file is being transferred. To retrieve a file from the FTP server, issue the ftp get command. The RN module prints the open string on the UART and the file begins transferring from the FTP server to the RN module. When the file transfer is complete, the RN module prints the close string indicating the file was transferred and the FTP connection was closed. EXAMPLE 3-18: RETRIEVE FILE FROM FTP SERVER ftp get demo.txt // Download the file demo.txt from the FTP server DS50002230B-page 52 2014-2015 Microchip Technology Inc. Features and Settings 3.8 PUTTING THE RN MODULE TO SLEEP AND WAKING IT Table 3-18 describes the methods for putting the RN module to sleep. TABLE 3-18: METHODS FOR PUTTING THE RN MODULE TO SLEEP Method Interface Description Sleep Command UART Enter into Command mode using $$$ and issue the sleep command. Sleep Timer Internal RTC The RN module sleeps based on the set sys sleep command setting. Drive GPIO8 high GPIO8 The RN module sleeps as soon as GPIO8 is held high (4 s latency). To enable this feature, use the set sys trigger 0x20 command setting. Table 3-19 describes the methods for waking the RN module. TABLE 3-19: METHODS FOR WAKING THE RN MODULE Method Interface Description Sensor Input (1.2V DC only) Sensor pins Wake the RN module using sensor pins 0-3 (1.2V DC ONLY). Use the set sys trigger command to enable the sensors. RX pin (3.3V DC only) RX pin via sensor 0 The RX pin on the RN134 and the RN174 evaluation boards is tied to sensor pin 0 via a resistor divider network. Use the set sys trigger 1 command to wake the RN module when it receives RX data. Note: With this method, the RN module may drop the first UART data byte. A better method is to wake the RN module using the CTS pin. CTS pin (3.3V DC only) CTS pin via sensor 1 The CTS pin on the RN134 and the RN174 evaluation boards is tied to sensor pin 1 via a resistor divider network. Use the set sys trigger 2 command to wake the RN module using the CTS pin. Wake Timer Internal RTC The wake timer wakes the RN module based on the set sys wake command setting. Force Awake FORCE AWAKE pin An input pulse of at least 31 s (3.3V) wakes the RN module. 3.8.1 Determining When the RN Module is Ready to Accept Data When the RN module wakes up from sleep, it takes time (in milliseconds) to initialize the internal hardware. During this time, any data that is sent to the RN module over the UART is not processed. Signals that indicate the RN module is ready to accept data can be monitored, as described in Table 3-20. TABLE 3-20: Method SIGNALS INDICATING THE RN MODULE CAN ACCEPT DATA Interface Description RTS Transition RTS pin When the RN module wakes up, the RTS pin goes high. Once the RN module is ready, the RTS pin is driven low. This pin can be monitored with a microcontroller. Monitor GPIO4 Alternative GPIO functions Set the alternative functions for GPIO4, GPIO5, and GPIO6 (see Section 3.13.2.6 "Alternative GPIO4/GPIO5/GPIO6 Functions"). When the RN module wakes up and connects to an access point, GPIO4 goes high, indicating the RN module is ready to receive data over the UART. A microcontroller can monitor GPIO4. Sensor Power Sensor power pin The RN module can be configured to output VBAT, or 3.3V or 1.2V on the sensor power pin when it wakes from sleep, indicating it is ready to accept data. 2014-2015 Microchip Technology Inc. DS50002230B-page 53 WiFly Command Reference Manual 3.8.2 Wake On Sensor Input Four sensor input pins (SENSE0 through SENSE3) wake the RN module from sleep. These pins have a small current source that is activated in Sleep mode. This source is approximately 100 nA, and causes the input to float up to approximately 1.2V DC. If, for example, SENSE1 is enabled, pulling the SENSE1 pin to ground wakes the RN module. To enable the sensors to wake the RN module, use the command set sys trigger , where is a bit-mapped setting of each sensor. For example, to wake the RN module using sensor pin 2, use the command set sys trig 4. Setting the trigger value to `0' disables all sensor pins. Table 3-21 describes the values to wake the RN module using individual sensor inputs. TABLE 3-21: SENSOR INPUT VALUES Wake on Sensor Input Value Command 0 1 set sys trigger 1 1 2 set sys trigger 2 2 4 set sys trigger 4 3 8 set sys trigger 8 WARNING The voltage on any sensor input CANNOT exceed 1.2V DC or the RN module will be permanently damaged. The sensor inputs are rated 1.2V DC, maximum. A resistor divider must be used when driving a sensor pin from the other 3V pins such as RX. Use a resistor divider network with a minimum of 24K in series and 10K to ground from the UART RX or CTS pin. An open-drain FET is an appropriate device to tie to the sensor pin as the threshold is approximately 500 mV. Additional pull-ups up to 1.2V DC can be used if the circuit has an impedance (due to leakage current) of less than 5 M (500 mv/100 nA). Leave unused sensor pins disconnected. 3.8.3 Wake on UART Activity When the RN module is in Sleep mode, the UART is disabled. However, the RN module can wake on UART activity by connecting the sensor pins to the RX data or CTS pin (using the appropriate divider resistors as described in Section 3.8.2 "Wake On Sensor Input"). The RN134 and the RN174 evaluation boards have a built-in resistor divider connecting SENSE0 and SENSE1 to RXD and CTS, respectively. This setup allows wake on RX and CTS using a 3.3V signal. WARNING Do not apply 3.3V directly to SENSE0 and SENSE1; the voltage on any sensor input CANNOT exceed 1.2V DC or the RN module will be permanently damaged. To enable wake on RXD, use the command set sys trig 1. The first byte (or possibly multiple bytes) sent to the RN module will likely be lost; therefore, care must be taken to send a preamble byte to wake the RN module before sending valid data bytes. Alternatively, use the CTS input to wake the RN module and wait until it is ready to accept data. To enable this setting, use the command set sys trig 2. DS50002230B-page 54 2014-2015 Microchip Technology Inc. Features and Settings 3.8.3.1 UART RECEIVER AND RTS/CTS HARDWARE FLOW CONTROL The UART receive buffer is approximately 1,500 bytes. At lower baud rates (less than 115K), the system can send data over TCP/IP without flow control. Depending on the frequency and quantity of the data being sent, the comm parameters optimize Wi-Fi performance by specifying when the system sends IP packets. To minimize latency and TCP/IP overhead, use the flush size or match character to send data in a single IP packet. In most cases, set the flush timer to a large number to avoid fragmentation. For high throughput, increase the UART baud rate, set the flush size to 1,460, and set the flush timer to a large value so that full IP packets are sent. Control packet forwarding can be controlled in the following ways: * set comm match sets the value of the packet terminator. Each time the RN module sees the match character it sends an IP packet. For example, set comm match 0xD forwards a packet when the RN module sees a 0xD hex character. * set comm size sets the flush size, where is the number of bytes received before forwarding. The maximum is 1,460 bytes, which is the size of a single Ethernet frame. * set comm time sets the flush timer, which is used to flush any partial data sitting in the RX buffer if no additional data is received for ms. For example, the set comm time 1000 command causes the RN module to wait for 1 second after no data was sent. If the RN module will be sending more than a few hundred thousand bytes in a single transaction, hardware flow control should be enabled. The hardware must actively monitor the CTS pin. Flow control is not enabled by default and is set with the set uart flow 1 command. It is possible to operate higher baud rates (i.e., greater than 115K) without flow control if the packets are uniform and an application protocol is used to ensure that the packet data is delivered on the remote side before the next packet is sent. However, given the uncertainty of packet delays in a TCP/IP network and the effects of interference and retries inherent in wireless networks, flow control is typically required whenever large, contiguous quantities of data are being written to the UART to ensure no data is lost. 2014-2015 Microchip Technology Inc. DS50002230B-page 55 WiFly Command Reference Manual 3.9 GPIO FUNCTIONS This section provides information on GPIO functions. 3.9.1 Setting GPIO Direction, Alternate Functions, and Disabling LEDs The GPIO pin direction and function are controlled using these two commands: set sys mask set sys iofunc 3.9.1.1 CONTROL GPIO DIRECTION WITH SET SYS MASK The GPIO pin direction can be controlled with the GPIO mask using the set sys mask command, where is entered as a hex number. The hex number represents a bitmask that controls each pin, where 1 = output and 0 = input. For example: set sys mask 0x0 set sys mask 0xc0 // Sets all pins as inputs // Set only GPIO6 and GPIO7 To set only one bit in the mask, it is necessary to read, mask, and set the value. Otherwise, any previous GPIO settings will be overwritten. The default mask for the RN131 module is 0x20F0, which sets GPIO13, GPIO7, GPIO6, GPIO5, and GPIO4 as outputs. The default mask for the RN171/RN1723 module is 0x21F0, which corresponds to the following settings: * GPIO0-GPIO3 are used internally on the RN module * GPIO4-GPIO6 are LEDs * GPIO9 is reserved as the factory reset/Soft AP mode (read at power-up) and otherwise general purpose input detect pin * GPIO10-GPIO11 are the UART RX and TX pins; TX does not need to be masked as an output * GPIO12 is CTS (input), if used * GPIO13 is RTS (output), if used Note: To set the GPIO pins as inputs or outputs instantly, use the set sys mask 0xABCD 1 command, which does not require a reboot. The RN134 evaluation board's LEDs are connected to GPIO4-GPIO6. To disable the LEDs, enable the alternative functions of the LEDs (use the set sys iofunc 0x7 command). Note: It is possible to turn OFF the yellow, red, or green LEDs. However, the blue LED on the RN134 evaluation board serves as the power indicator and cannot be turned OFF. The blue LED on the RN174 evaluation board is connected to GPIO7, which is output by default. The board does not drive this LED because the default power-up state of GPIO7 is low. The get sys command shows the setting of the GPIO mask, as shown in Example 3-19. EXAMPLE 3-19: GPIO MASK SETTING <2.21> get sys SleepTmr=...... IoFunc=0x0 IoMask=0x21f0 DS50002230B-page 56 2014-2015 Microchip Technology Inc. Features and Settings Figure 3-14 shows the bits corresponding to the GPIO pins and Table 3-22 shows the GPIO pin usage, their default state, and functionality. FIGURE 3-14: GPIO PIN BITMASK 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 GPIO14 GPIO0 GPIO13 UART RTS GPIO1 GPIO12 UART CTS GPIO2 GPIO11 UART RX GPIO3 GPIO10 UART TX GPIO4 GPIO9 GPIO8 GPIO5 GPIO6 GPIO7 TABLE 3-22: GPIO PIN USAGE, DEFAULT STATE, AND FUNCTIONALITY Bit Signal Name RN131 Default State RN171/RN1723 Default State 0 GPIO0 N/A N/A 1 GPIO1 N/A Input 2 GPIO2 N/A Input 3 GPIO3 N/A Input 4 5 6 GPIO4 GPIO5 GPIO6 Output Output Output Output Output Output 7 8 GPIO7 GPIO8 Output Input Output Output 9 10 11 12 14 Note 1: 2: Not used by RN modules, but can be used as a sensor input. Not used by RN modules, but can be used as a sensor input. Not used by RN modules, but can be used as a sensor input. Not used by RN modules, but can be used as a sensor input. Green LED Yellow LED Red LED Blue LED(1) This pin can be used to place the RN module into sleep mode. Soft AP/Multi-purpose GPIO(2) UART TX UART RX Throttles the transmitter if hardware flow control is enabled. Driving this pin low enables transmitter; driving this pin high disables it. GPIO13 Output Output This pin goes high on power-up and goes low when the system is ready. If hardware flow control is enabled, this pin toggles to high to indicate the RX buffer is full. GPIO14 N/A Input Not used by RN modules, but can be used as a sensor input. On the RN174 evaluation board, the blue LED is connected to GPIO7. The blue LED is not connected to GPIO7 on the RN134 evaluation board. It is not possible to power off the blue LED on the RN134 evaluation board because it is connected directly to power. The GPIO9 pin can be used for factory Reset, Soft AP mode, or Web Config mode. GPIO9 GPIO10 GPIO11 GPIO12 13 Default Function Input Output Input Input 2014-2015 Microchip Technology Inc. Input Output Input Input DS50002230B-page 57 WiFly Command Reference Manual 3.9.1.2 SETTING THE ALTERNATE GPIO FUNCTIONS The default functionality of GPIO4, GPIO5, and GPIO6 is to control the LEDs. The default can be overridden to allow user programmable I/O or alternate I/O functionality by using the set sys iofunc command, where is entered as a hex number. The hex value represents a bitmask that controls each bit in the and represents a particular GPIO pin. If a bit is `0', the corresponding GPIO pin is driven/read by the firmware per the default function. The I/O function is encoded, as shown in Table 3-23. TABLE 3-23: GPIO PIN ALTERNATE FUNCTION BITMASK Bit(1) Signal Name Direction Function 0 GPIO4 Output Disable the LED function so the I/O can be used as a GPIO pin. 1 GPIO5 Output Disable the LED function so the I/O can be used as a GPIO pin. 2 GPIO6 Output Disable the LED function so the I/O can be used as a GPIO pin. 3 Unused -- -- 4 GPIO4 Output 5 GPIO5 Input Set this pin high to trigger a TCP connection and low to disconnect. 6 GPIO6 Output This pin goes high when the RN module is connected over TCP and low when disconnected. This pin goes high after the RN module has associated/authenticated and has an IP address. Note 1: Bits 0-3 are mutually exclusive with bits 4-6 (i.e., 0x77 is an illegal value). If the LEDs are disabled using bits 0, 1, and 2, the show i command can be used to read these GPIO pins. For example, the show i command might return Port=30. To use the alternate LEDs functions, use the following commands: set sys iofunc 0x70 save reboot // Enable alternate function for GPIO4-GPIO6 // Store configuration // Reboot the RN module Example 3-20 shows how to control the LEDs on the evaluation boards. EXAMPLE 3-20: Green LED: TOGGLE RED AND GREEN LEDS set sys iofunc 0x01 set sys output 0x10 // Mask GPIO4 from WiFly functionality // Toggle the state of GPIO4 Red LED: set sys iofunc 0x04 set sys output 0x40 // Mask GPIO6 from WiFly functionality // Toggle the state of GPIO6 Green and Red LEDs: set sys iofunc 0x05 set sys output 0x50 DS50002230B-page 58 // Mask GPIO4 and GPIO6 from WiFly // functionality // Toggle the state of GPIO 4 and GPIO6 2014-2015 Microchip Technology Inc. Features and Settings 3.10 SETTING DEBUG PRINT LEVELS The print functions can be enabled to assist with debugging the operation and status of the RN module. The set sys printlvl command controls these additional print functions, where is a bit-mapped register that controls which printout messages are sent to the UART. See "set sys printlvl " for more information. 3.10.1 Scan Output Format The scan output format shown in the following example can be enabled using the set sys printlvl 0x4000 command. Index Channel RSSI Security WPA Capabilities Mode Configuration WPS Mode MAC Address SSID Where: Field Value Index 2 character, decimal Channel 2 character, decimal RSSI 2 character, decimal (negative number) Security mode 2 bytes (see Table 3-24) Capabilities Bit-mapped 4 hex bytes (see Table 3-25) WPA Configuration Bit-mapped 2 hex bytes (see Table 3-26) WPS Mode Bit-mapped 2 hex bytes (see Table 3-24) MAC address Address SSID Up to 32 characters Note: The string END is added at the end of the scan data. Table 3-24 shows the security modes. TABLE 3-24: SECURITY MODES Number Description 0 OPEN 1 WEP (64 or 128) 2 WPA1 3 MIXED 4 WPA2 5 Enterprise WEP 6 Enterprise WPA1 7 Enterprise WPA mixed 8 Enterprise WPA2 9 Enterprise NO security Table 3-25 describes the capabilities bit mask values. TABLE 3-25: CAPABILITIES BIT MASK VALUES Bit Mask Value Description 0004 Short slot time 0100 ESS (Infrastructure mode) 1000 Privacy (secure with WEP or WPA) 2000 Short preamble 2014-2015 Microchip Technology Inc. DS50002230B-page 59 WiFly Command Reference Manual Table 3-26 describes the WPA bit mask values. TABLE 3-26: WPA BIT MASK VALUES Bit Mask Value Description 04 WPA_UNICAST_TKIP 08 WPA_UNICAST_AES_CCMP 10 WPA_BROADCAST_TKIP 20 WPA_BROADCAST_AES_CCMP Table 3-27 describes the WPS bit mask values. TABLE 3-27: WPS BIT MASK VALUES Bit Mask Value 3.10.2 Description 02 WPS_PushButton_ACTIVE 40 WPS_SUPPORTED 80 WPS_PushButton_SUPPORTED UART Heartbeat Messages The RN module can output UART heartbeat messages. The bit-mapped message is output periodically while the RN module is in Data mode and not connected to a remote Host. Messages are not output while in Command mode. The heartbeat message encodes the RN module's state for the embedded microprocessor. Based on the heartbeat message, the microprocessor can choose to change the configuration by going into Command mode. To enable the UART heartbeat messages, use the set sys printlvl 0x10 command. The output of this mode is: *8b30*8b30*8b30.... Note: For Soft AP mode, the UART heartbeat message reflects the number of client devices associated with the RN module. In this case, the number 8 in the output is incremented according to the number of devices currently associated to the Soft AP network. For example: *81xx indicates no associated client devices, *91xx indicates one associated client device, and *a1xx indicates two associated client devices, etc. Table 3-28 shows the output bit format. TABLE 3-28: OUTPUT BIT FORMAT Bit 15...14 Function Fixed 13...12 DS50002230B-page 60 7...6 5 4 Reserved Channel Reserved Authentication Association 2 = Soft Unused AP mode Value 11...8 0-13 Unused 1 = OK 1 = OK 3...0 TCP status 0 = Idle 1 = Connected 3 = No IP 4 = Connecting 5 = Challenge for password 2014-2015 Microchip Technology Inc. Features and Settings 3.11 USING THE REAL-TIME CLOCK FUNCTION The RN module's real-time clock keeps track of the number of seconds since the RN module was powered on and the actual time when the RN module synchronized with the SNTP time server. By default, the RN module keeps track of up-time but does not synchronize with the time server because this synchronization requires the RN module to be associated with a network that can access the SNTP server. The real-time clock reads the time in seconds since 1970, which corresponds to the UNIX time. The RTC value in seconds can be set using the set time rtc command. The default SNTP server is: ADDR=129.6.15.28:123 ZONE=7 (GMT -7) Use the show time command to see the current time and up-time, as follows: <2.23> show t Time=08:43:10 UpTime=10 s To set the time, use the time command: <2. 23> show t Time NOT SET UpTime=8 s <2. 23> time <2. 23> show t Time=08:51:31 UpTime=15 s Note: The RN module must be associated with a network for the RN module to contact the SNTP server. The RN module can also be configured to get the time whenever it powers up using the set time enable 1 command. If time enable is set to a value greater than `1', the RN module pulls the time continuously every minutes. To configure the RN module to get time upon power-up, see the following example: <2. 23> set time enable 1 AOK <2. 23> get time ENA=1 ADDR=129.6.15.28:123 ZONE=7 To view a complete listing of the time variable, use the following command: <2. 23> show t t Time=09:02:10 UpTime=653 s RTC=1293567548 Restarts=1 Wake=6 RAW=2345ab Note: The RAW value is the 64-bit hex RAW value of the RTC, which counts at 32,768 Hz. 2014-2015 Microchip Technology Inc. DS50002230B-page 61 WiFly Command Reference Manual 3.12 TIME STAMPING PACKETS The time stamping feature can be used to append 8 bytes to a TCP or UDP packet automatically. The set ip flags 0x87 command enables the time stamp and keeps other default settings). The time stamp bits from MSB to LSB are as follows: User's TCP or 63...56 UDP packet data 55...48 47...40 39...32 31...24 23...16 15...8 7...0 The eight bytes represents the 64-bit raw value of the real-time clock register. The data is appended before calculating the TCP checksum so that the data passes through the TCP stack correctly. This register counts at 32,768 Hz. If the timeserver function is enabled, the RTC should accurately reflect the real time. This register also counts when the RN module is in Sleep mode. DS50002230B-page 62 2014-2015 Microchip Technology Inc. Features and Settings 3.13 SOFT ACCESS POINT (SOFT AP) MODE Note: Depending on the firmware version, Soft AP mode is available for use by RN modules, as follows: * RN131 and RN171 modules with firmware version 2.45 and later * RN1723 modules with firmware version 1.0 or later RN modules support several methods for accessing Wi-Fi networks. In addition to Infrastructure mode, RN modules support Soft Access Point (Soft AP) mode. In Soft AP mode: * The RN module creates a Soft AP network to which Android devices (smartphones and tablets) can join * The RN module runs a DHCP server and issues IP addresses to seven clients * The RN module supports security * The RN module supports routing between clients The following sections describe how to use Soft AP mode with an RN module, including configuring the RN module to act as an access point, enabling Soft AP mode in hardware and software, and sending data to the RN module from a remote Host. 3.13.1 Enabling Soft AP mode There are two methods for enabling Soft AP mode: hardware and software. These methods are described in the following sections. 3.13.1.1 ENABLE SOFT AP MODE IN HARDWARE To enable Soft AP mode in hardware, hold the GPIO9 pin high at 3.3V, and then reset (i.e., power cycle) the RN module. The RN module will then boot-up in Soft AP mode with the DHCP server enabled. Table 3-29 shows the default Soft AP mode settings. TABLE 3-29: DEFAULT SOFT AP MODE SETTINGS Setting Soft AP Mode Default SSID WiFly-XXX-yy, where `XXX' is: * GSX (RN131 module) * EZX (RN171 module) * FZX (RN1723 module) and `yy' is the LSB byte of the RN module's MAC address Channel 1 DHCP server Enabled IP address 192.168.1.1 Netmask 255.255.255.0 Gateway 192.168.1.1 When the RN module boots up in Soft AP mode, other Wi-Fi enabled devices, such as PCs, iPhones, iPads, and Android tablets, should be able to see the RN module when they scan for access points. Note: Microchip recommends setting the RN module as the gateway when creating a point-to-point network between devices (Wi-Fi network only). 2014-2015 Microchip Technology Inc. DS50002230B-page 63 WiFly Command Reference Manual 3.13.1.2 ENABLE SOFT AP MODE IN SOFTWARE Soft AP mode can be enabled in software using the set wlan join 7 command. Network settings such as the SSID, channel, and IP address can be customized in software to create a custom Soft AP mode. For example, the following commands create a custom Soft AP mode in software: set wlan join 7 // Enable Soft AP mode set wlan channel // Specify the channel to create network set apmode ssid // Set up network broadcast SSID (BSSID) set apmode passphrase // Set the Soft AP mode passphrase set ip dhcp 4 // Enable DHCP server set ip address
// Specify the IP address set ip net
// Specify the subnet mask set ip gateway
// Specify the gateway save // Store settings reboot // Reboot the RN module in Soft AP mode After rebooting, the RN module is in Soft AP mode with the custom settings (SSID, channel, IP address, netmask, and gateway). A quick method of creating a Soft AP network is to use the apmode command, where is the broadcast SSID and is the channel on which the Soft AP network is created. The and parameters are optional. If no parameters are specified, the RN module: * Uses the string stored with the set opt device_id command and appends -xy, where `xy' is the last byte of the RN module's MAC address as the SSID * Creates the Soft AP network on channel 1 Note: This command does not survive power cycling. After a power cycle, the RN module behaves according to the wireless join policy determined by the set wlan join command. Example apmode MyNetwork 11 3.13.2 // Creates a Soft AP network on channel 11 // with the SSID MyNetwork Using Soft AP Mode This section describes how to use Soft AP mode, including connecting to the RN module, checking for the last device connected over TCP, viewing associated devices, enabling the link monitor, and routing data between clients. 3.13.2.1 CONNECT TO THE RN MODULE Once the RN module boots up in Soft AP mode, any client device can associate with the network the RN module is broadcasting. Once associated, the RN module's DHCP server assigns an IP address to the client device. The default lease time is 1 day (i.e., 86,400 seconds). The lease time can be configured using the set dhcp lease command, where is the time in seconds. To view a list of devices associated with the RN module, use the show lease command. The command output is in the following format with commas delimiting the fields: IP address assigned DS50002230B-page 64 Client MAC address Remaining lease time (in seconds) Host name 2014-2015 Microchip Technology Inc. Features and Settings Example 3-21 shows output from the show lease command. EXAMPLE 3-21: SHOW LEASE COMMAND OUTPUT <2.42> show lease 1.2.3.10,f0:cb:a1:2b:63:59,153,* 1.2.3.11,00:00:00:00:00:00,0, 1.2.3.12,00:00:00:00:00:00,0, 1.2.3.13,00:00:00:00:00:00,0, 1.2.3.14,00:00:00:00:00:00,0, 1.2.3.15,00:00:00:00:00:00,0, 1.2.3.16,00:00:00:00:00:00,0, <2.42> Note: In Soft AP mode, the RN module can assign a DHCP lease to seven clients. However, not all clients report the Host name. In this case, the RN module reports the Host name as an asterisk (*). Once a client is associated to the network, it can open a TCP connection to the RN module. After successfully opening a TCP connection, the client receives a *HELLO* message. The RN module prints *OPEN* on the UART, indicating an open TCP connection. 3.13.2.2 CHECK FOR THE LAST CONNECTED DEVICE OVER TCP In some cases, it is beneficial to know the IP address of the last device that connected to the RN module over TCP or the last device to which the RN module connected over TCP. To find this address, use the show z command. Please note that this command does not survive a power cycle or reboot. Upon power-up, if no device is connected over TCP, the show z command returns 0.0.0.0. 3.13.2.3 VIEW ASSOCIATED DEVICES To see a list of devices associated with the RN module, use the show associated command. The command output is in the following format with commas delimiting the fields: Connection number Host MAC address Received byte count Transmitted byte count Seconds since last packet received Example 3-22 shows output from the show associated command. EXAMPLE 3-22: SHOW ASSOCIATE COMMAND OUTPUT <2.42> show associated 1,f0:cb:a1:2b:63:59,36868,0,7 2,00:24:8c:31:e5:27,76168,0,2 3,98:4b:4a:6b:e0:0f,1992,0,0 <2.42> The "Seconds since last packet received" output can be used to check for stale connections. 2014-2015 Microchip Technology Inc. DS50002230B-page 65 WiFly Command Reference Manual 3.13.2.4 ENABLE THE LINK MONITOR Soft AP mode supports a link monitor feature to detect whether or not individual client devices are active and in range of the RN module. The link monitor is a timer (in seconds) that checks to see if any packets are received from an associated device. If the timer expires, the access point module deauthenticates the client(s). This feature is useful for aging out clients that do not send any traffic over Wi-Fi. The link monitor is enabled using the set wlan fmon command, where is a decimal number representing the number of seconds of client inactivity (i.e., no data received from the client device). This command sets the Soft AP mode link monitor time-out threshold for each associated client device. When this timer expires, the RN module deauthenticates that particular client. Setting this timer to a lower value, such as 10 seconds, may result in frequent deauthentications for client devices if they do not send data before the timer expires. To disable the link monitor timer, set to zero (0). The default is 3600. Example set wlan fmon 1000 3.13.2.5 // Set the fmon timer to 1,000 seconds ROUTE DATA BETWEEN CLIENTS Soft AP mode supports routing between clients. Clients can ping each other via Soft AP mode and can also send data to each other over TCP and UDP. Note: 3.13.2.6 Routing data between clients is not supported when WPA2-PSK encryption is enabled. ALTERNATIVE GPIO4/GPIO5/GPIO6 FUNCTIONS GPIO4, GPIO5, and GPIO6 have alternative functions in Soft AP mode, as described in 3.13.2 "Using Soft AP Mode". The alternative functions are enabled using the following command: set sys iofunc 0x70 // Enables alternative functions The link monitor feature must be enabled to turn on the alternative functions in Soft AP mode only. Table 3-30 shows the GPIO alternative functions. TABLE 3-30: GPIO DS50002230B-page 66 ALTERNATIVE GPIO FUNCTIONS Description GPIO4 High when the first client associates; low when all clients leave the network. GPIO5 The RN module can drive GPIO5 high to open a TCP connection to a stored host. When the RN module drives GPIO5 low, it closes the TCP connection. GPIO6 The RN module drives GPIO6 high when a TCP connection is open and low when a TCP connection is closed. 2014-2015 Microchip Technology Inc. Features and Settings 3.14 UPGRADING FIRMWARE 3.14.1 Upgrading Firmware Via FTP The RN module has a file system for storing firmware and configuration files. Use the ls command to view files. The file size is displayed in sectors and the active boot image is identified in the final message. For example: FL# SIZ FLAGS 11 18 3 29 1 10 190 Free, Boot=11, Backup=0 WiFly_GSX-2.21 config It is possible to store multiple firmware images and configuration files in the file system of the RN module. Note: The RN module's Flash file system only is used to store firmware and configuration files. The file system cannot be used to store data files. The RN module contains a built-in FTP client for downloading files and updating the firmware. The client uses passive mode FTP, which allows operation through firewalls and the Internet. To connect to Microchip to obtain the latest released firmware, use the settings shown in Table 3-31. TABLE 3-31: FTP SETTINGS Setting Description FTP server rn.microchip.com (set FTP server using the set dns backup command) FTP username roving FTP password Pass123 FTP filename Refer to the following sections for the filename used in different versions of firmware. FTP directory ./public (this parameter cannot be modified) Note: 3.14.1.1 Note: Before using FTP to upgrade the firmware, the RN module must first be associated with an access point that is connected to the Internet. UPGRADING WITH MULTIPLE IMAGE FORMAT (MIF) FILES Upgrading using the MIF file description, is only available for the following RN modules: * RN131 and RN171 modules with firmware version 4.0 and later * RN1723 modules with firmware 1.0 or later The MIF (.mif) files contain the firmware image (.img) and associated applications and files to support all of the features of the installed firmware. RN modules that support the MIF file format can unpack the .mif file and install the applications and files into the RN module's Flash memory. Download the .mif file using one of the following commands: * ftp update wifly3-400.mif * ftp update wifly7-400.mif * ftp update wifly7-100.mif 2014-2015 Microchip Technology Inc. (RN131 module) (RN171 module) (RN1723 module) DS50002230B-page 67 WiFly Command Reference Manual After downloading the .mif file, the RN module unpacks it and automatically reboots into the new boot image with all of the associated files installed into the RN module's Flash memory. Table 3-32 describes these files. TABLE 3-32: FIRMWARE AND ASSOCIATED APPLICATIONS File Name Description Comments wifly_EZX-2.45 wifly-EZX-307 wifly-EZX-400 wifly-FZX-100 Firmware image files (.img) Filenames beginning in wifly are typically firmware images. wps_app-EZX-131 eap_app-EZX-101 web_app-EZX-105 web_app-FZX-112 Application files These application files are used for specific module features. web_config.html link.html HTML files These files are used for the configuration Web Server feature. logo.png Logo file Logo displayed on web pages. Used for the configuration Web Server feature. config Configuration file The config file stores the RN module's boot-up parameters. The firmware image, applications, and associated files in the Flash memory can be verified using the ls command, as shown in Example 3-23. EXAMPLE 3-23: ls COMMAND EXAMPLE OUTPUT <3.07> ls FL# SIZ FLAGS 2 83576 3 WiFly_EZX-2.45 23 -1 10 config 25 85512 3 wifly-EZX-307 26 46624 3 wps_app-EZX-131 27 66248 3 eap_app-EZX-101 28 74280 3 web_app-EZX-105 29 37014 0 web_config.html 30 512 0 link.html 31 1609 0 logo.png 149 Free, Boot=25, Backup=2 <3.07> DS50002230B-page 68 2014-2015 Microchip Technology Inc. Features and Settings 3.14.1.2 Note: UPGRADING FIRMWARE TO VERSION 4.0 Upgrading firmware to version 4.0 is only applicable to the RN131 and RN171 modules. To update the firmware from a version prior to 4.0, follow this process: 1. Update the firmware .img file to version 4.xx using one of the following commands: * ftp update wifly3-400.img (RN131 module) * ftp update wifly7-400.img (RN171 module) 2. Remove the old configuration using the following command: del config 3. Reboot the RN module to boot into the new image. NOTICE It is mandatory that the RN module be reset to the factory default settings at this point using the factory RESET and reboot commands. 4. Download the .mif file using one of the following commands: * ftp update wifly3-400.mif (RN131 module) * ftp update wifly7-400.mif (RN171 module) After the RN module downloads the .mif file, the RN module automatically reboots into the boot image with all of the associated files installed into the RN module's Flash memory. Refer back to Table 3-32 for a description of these files. The firmware image, applications, and associated files in Flash memory can be verified using the ls command (see Example 3-23). 3.14.1.3 Note: UPGRADING FIRMWARE PRIOR TO VERSION 4.0 Upgrading firmware to a version prior to 4.0 is only applicable to the RN131 and RN171 modules. To update the firmware to a version prior to 4.0 (e.g., from version 2.45 to 3.07), issue the command ftp update , where is an optional file name (use the optional name to bypass the default firmware file name). The RN module retrieves the file and switches the boot image to the new file, resulting in the following messages: <2.20> ftp update <2.20> FTP connecting to 208.109.78.34 FTP file=30 ...................................................................... FTP OK. CAUTION After the RN module reboots with the new firmware, it is recommended to reset the RN module to the factory default parameters using the factory RESET command. Failure to do so may result in some variables being initialized with random values. 2014-2015 Microchip Technology Inc. DS50002230B-page 69 WiFly Command Reference Manual The previous firmware becomes the back-up image. The following example shows the file system after a successful update: FL# SIZ FLAGS 11 18 3 29 1 10 30 18 3 208 Free, Boot=30, Backup=11 WiFly_GSX-2.20 config WiFly_GSX-2.21 After downloading, the firmware checks the image and compares it to the stored values in the file before committing the image to Flash and updating the boot record. If the checksum fails, the RN module displays UPDATE FAILED=x and deletes the image. Note: It is necessary to reboot or power cycle the RN module to use the new firmware. To boot with different firmware, use the command boot image , which sets the current boot image as . For example, issue the following command to boot the previous image using the previous example: <2.20> boot image 11 Set Boot Image 11, =OK Note: 3.14.1.4 Note: After changing the boot pointer to the new image, the RN module must be rebooted to boot up with the new image. Once the RN module boots up with the new image, perform a factory reset on the RN module to initialize all the parameters to the factory default settings. Then, the parameters can be reinitialized as required. OPTIONAL FTP UPDATE COMMAND PARAMETERS The optional FTP update command parameters apply to: * RN131 and RN171 modules with firmware version 4.40 and later * RN1723 modules with firmware 1.0 or later The optional FTP update command parameter options are: ftp