Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
Diff: doc/mbed/html/ota_2example_8cpp-example.html
- Revision:
- 39:a963f69cb2de
- Parent:
- 34:2616445d0823
--- a/doc/mbed/html/ota_2example_8cpp-example.html Thu Nov 27 10:27:18 2014 +0000 +++ b/doc/mbed/html/ota_2example_8cpp-example.html Mon Feb 23 20:30:18 2015 -0800 @@ -106,7 +106,7 @@ <p>It works as follows:</p><ol type="1"> <li>Instantiate the WiConnect Library</li> <li>Initiate Communication with WiFi Module</li> -<li>Join a network using the specified parameters</li> +<li>Set the network credentials</li> <li>Call the 'updateFirmware' wiconnect API and wait for the update to complete (takes ~60s)</li> <li>That's it!</li> </ol> @@ -127,8 +127,6 @@ <div class="line"><span class="preprocessor">#define NETWORK_PASSWORD "\"<YOUR NETWORK PASSWORD HERE>\""</span></div> <div class="line"></div> <div class="line"></div> -<div class="line"></div> -<div class="line"></div> <div class="line"><span class="comment">/******************************************************************************</span></div> <div class="line"><span class="comment"> * Includes</span></div> <div class="line"><span class="comment"> */</span></div> @@ -152,13 +150,13 @@ <div class="line"><span class="keyword">static</span> Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);</div> <div class="line"></div> <div class="line"></div> -<div class="line"></div> -<div class="line"></div> <div class="line"><span class="comment">/******************************************************************************</span></div> <div class="line"><span class="comment"> * Starting point of application</span></div> <div class="line"><span class="comment"> */</span></div> <div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div> <div class="line">{</div> +<div class="line"> <a name="a0"></a><a class="code" href="group__api__core__types.html#ga325637ed501728bd6c8c7a7982b9ce05">WiconnectResult</a> result;</div> +<div class="line"> </div> <div class="line"> consoleSerial.baud(115200); <span class="comment">// console terminal to 115200 baud</span></div> <div class="line"></div> <div class="line"> <span class="comment">//-------------------------------------------------------------------------</span></div> @@ -175,7 +173,6 @@ <div class="line"> <span class="comment">// The internal buffer will be dynamically allocated</span></div> <div class="line"> Wiconnect wiconnect(serialConfig, 256, NULL, WICONNECT_RESET_PIN);</div> <div class="line"></div> -<div class="line"></div> <div class="line"> <span class="comment">//-------------------------------------------------------------------------</span></div> <div class="line"> <span class="comment">// STEP 2: Initiate Communication with WiFi Module</span></div> <div class="line"> <span class="comment">//-------------------------------------------------------------------------</span></div> @@ -183,33 +180,51 @@ <div class="line"> printf(<span class="stringliteral">"Initializing WiConnect Library...\r\n"</span>);</div> <div class="line"></div> <div class="line"> <span class="comment">// Initialize communication with WiFi module</span></div> -<div class="line"> <span class="keywordflow">if</span>(wiconnect.init(<span class="keyword">true</span>) != <a name="a0"></a><a class="code" href="group__api__core__types.html#gga325637ed501728bd6c8c7a7982b9ce05af0a2ad8af174aee6b52813d8528328e7">WICONNECT_SUCCESS</a>)</div> +<div class="line"> <span class="keywordflow">if</span>(<a name="a1"></a><a class="code" href="group__api__core__macro.html#gab27aa3ef76302b5221766abfd4f47e64">WICONNECT_FAILED</a>(result, wiconnect.init(<span class="keyword">true</span>)))</div> <div class="line"> {</div> -<div class="line"> printf(<span class="stringliteral">"Failed to initialize communication with WiFi module!\r\n"</span></div> -<div class="line"> <span class="stringliteral">"Make sure the wires are connected correctly\r\n"</span>);</div> -<div class="line"> <span class="keywordflow">for</span>(;;); <span class="comment">// infinite loop</span></div> +<div class="line"> <span class="comment">// if the error is that the firmware is out-dated, then continue, else stop</span></div> +<div class="line"> <span class="keywordflow">if</span>(result != <a name="a2"></a><a class="code" href="group__api__core__types.html#gga325637ed501728bd6c8c7a7982b9ce05a62defbdafd472461054dd6bb888c9a1e">WICONNECT_FIRMWARE_OUTDATED</a>)</div> +<div class="line"> {</div> +<div class="line"> printf(<span class="stringliteral">"Failed to initialize communication with WiFi module!\r\n"</span></div> +<div class="line"> <span class="stringliteral">"Make sure the wires are connected correctly\r\n"</span>);</div> +<div class="line"> <span class="keywordflow">for</span>(;;); <span class="comment">// infinite loop</span></div> +<div class="line"> }</div> <div class="line"> }</div> <div class="line"></div> <div class="line"></div> <div class="line"> <span class="comment">//-------------------------------------------------------------------------</span></div> -<div class="line"> <span class="comment">// STEP 3: Join a network using the specified parameters</span></div> +<div class="line"> <span class="comment">// STEP 3: Set the network credentials</span></div> +<div class="line"> <span class="comment">// Note: We manually set the network parameters to ensure SDK backward compatibility</span></div> <div class="line"> <span class="comment">//-------------------------------------------------------------------------</span></div> <div class="line"></div> -<div class="line"> printf(<span class="stringliteral">"Joining network: %s....\r\n"</span>, NETWORK_SSID);</div> -<div class="line"></div> -<div class="line"> <span class="keywordflow">if</span>(wiconnect.join(NETWORK_SSID, NETWORK_PASSWORD) != <a class="code" href="group__api__core__types.html#gga325637ed501728bd6c8c7a7982b9ce05af0a2ad8af174aee6b52813d8528328e7">WICONNECT_SUCCESS</a>)</div> +<div class="line"> printf(<span class="stringliteral">"Setting network SSID: %s\r\n"</span>, NETWORK_SSID);</div> +<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group__api__core__macro.html#gab27aa3ef76302b5221766abfd4f47e64">WICONNECT_FAILED</a>(result, wiconnect.setSetting(<span class="stringliteral">"wlan.ssid"</span>, NETWORK_SSID)))</div> <div class="line"> {</div> -<div class="line"> printf(<span class="stringliteral">"Failed to send join command\r\n"</span>);</div> +<div class="line"> printf(<span class="stringliteral">"Failed to set wlan.ssid setting\r\n"</span>);</div> +<div class="line"> <span class="keywordflow">for</span>(;;); <span class="comment">// infinite loop</span></div> +<div class="line"> }</div> +<div class="line"> </div> +<div class="line"> printf(<span class="stringliteral">"Setting network password\r\n"</span>);</div> +<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group__api__core__macro.html#gab27aa3ef76302b5221766abfd4f47e64">WICONNECT_FAILED</a>(result, wiconnect.setSetting(<span class="stringliteral">"wlan.passkey"</span>, NETWORK_PASSWORD)))</div> +<div class="line"> {</div> +<div class="line"> printf(<span class="stringliteral">"Failed to set wlan.passkey setting\r\n"</span>);</div> <div class="line"> <span class="keywordflow">for</span>(;;); <span class="comment">// infinite loop</span></div> <div class="line"> }</div> <div class="line"></div> +<div class="line"> printf(<span class="stringliteral">"Saving settings to Non-volatile Memory\r\n"</span>);</div> +<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group__api__core__macro.html#gab27aa3ef76302b5221766abfd4f47e64">WICONNECT_FAILED</a>(result, wiconnect.saveSettings()))</div> +<div class="line"> {</div> +<div class="line"> printf(<span class="stringliteral">"Failed save settings\r\n"</span>);</div> +<div class="line"> <span class="keywordflow">for</span>(;;); <span class="comment">// infinite loop</span></div> +<div class="line"> }</div> +<div class="line"> </div> <div class="line"> <span class="comment">//-------------------------------------------------------------------------</span></div> <div class="line"> <span class="comment">// STEP 4: Update the module's firmware, this takes about 60s</span></div> <div class="line"> <span class="comment">//-------------------------------------------------------------------------</span></div> <div class="line"></div> -<div class="line"> printf(<span class="stringliteral">"Updating WiFi module's internal firmware to latest...\r\n"</span>);</div> +<div class="line"> printf(<span class="stringliteral">"Updating WiFi module's internal firmware to latest (note this can take up to 60s)\r\n"</span>);</div> <div class="line"></div> -<div class="line"> <span class="keywordflow">if</span>(wiconnect.updateFirmware() != <a class="code" href="group__api__core__types.html#gga325637ed501728bd6c8c7a7982b9ce05af0a2ad8af174aee6b52813d8528328e7">WICONNECT_SUCCESS</a>)</div> +<div class="line"> <span class="keywordflow">if</span>(wiconnect.updateFirmware() != <a name="a3"></a><a class="code" href="group__api__core__types.html#gga325637ed501728bd6c8c7a7982b9ce05af0a2ad8af174aee6b52813d8528328e7">WICONNECT_SUCCESS</a>)</div> <div class="line"> {</div> <div class="line"> printf(<span class="stringliteral">"Failed to update the module's firmware\r\n"</span>);</div> <div class="line"> <span class="keywordflow">for</span>(;;); <span class="comment">// infinite loop</span></div>