User manual

!
www.rovingnetworks.com Version 1.1 9/20/2012 12
RN-131/171-PICTAIL-UM
Primary Module Communications API Functions
The API function that tells the device to go into command mode is:
err_t module_send_cmd(const char *response, const char *fmt, ...)
This function accepts 2 or more parameters (i.e., a variable length parameter list). The first parameter, response, is the
reply expected from the RN-171 module after it has processed the command. The command is carried in the fmt
parameter. For example, if the function is called as follows:
retValue = err_t module_send_cmd(“CMD”, “$$$”);
The command is $$$ and the expected return is CMD. For a more complex instantiation such as:
retValue = module_send_cmd(CMD_AOK, "set wlan ssid %s", NETWORK_SSID)
The variable parameter list is essential to properly resolve the %s into the value of the NETWORK_SSID macro.
The next API demonstrates how you can combine individual commands inside a single function to carry out a more
complex operation, such as joining a network. The following API function forces the device into command mode, saves the
SSID and passphrase, and reboots the module.
err_t module_network_connect(void);
Internally, it sends a total of 5 commands.:
module_send_cmd("CMD", "$$$")
module_send_cmd(CMD_AOK, "set w s %s", NETWORK_SSID)
module_send_cmd(CMD_AOK, "set w p %s", NETWORK_PASS)
module_send_cmd(NULL, "save")
module_send_cmd(NULL, "join")
This function represents a typical API that sends a sequence of commands to the module to carry out a complex task.
Most applications follow a similar pattern.
RESOURCES & RELATED DOCUMENTS
For more information, refer to the following sources, which are available on the Support page on the Roving Networks
website at http://www.rovingnetworks.com/support.php:
RN-171 Data Sheet
RN-131 Data Sheet
Advanced User Manual
WiFly Training Presentation
Drivers, tools, and utilities