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

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 &quot;\&quot;&lt;YOUR NETWORK PASSWORD HERE&gt;\&quot;&quot;</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">&quot;Initializing WiConnect Library...\r\n&quot;</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">&quot;Failed to initialize communication with WiFi module!\r\n&quot;</span></div>
-<div class="line">                <span class="stringliteral">&quot;Make sure the wires are connected correctly\r\n&quot;</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">&quot;Failed to initialize communication with WiFi module!\r\n&quot;</span></div>
+<div class="line">                    <span class="stringliteral">&quot;Make sure the wires are connected correctly\r\n&quot;</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">&quot;Joining network: %s....\r\n&quot;</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">&quot;Setting network SSID: %s\r\n&quot;</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">&quot;wlan.ssid&quot;</span>, NETWORK_SSID)))</div>
 <div class="line">    {</div>
-<div class="line">        printf(<span class="stringliteral">&quot;Failed to send join command\r\n&quot;</span>);</div>
+<div class="line">        printf(<span class="stringliteral">&quot;Failed to set wlan.ssid setting\r\n&quot;</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">&quot;Setting network password\r\n&quot;</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">&quot;wlan.passkey&quot;</span>, NETWORK_PASSWORD)))</div>
+<div class="line">    {</div>
+<div class="line">        printf(<span class="stringliteral">&quot;Failed to set wlan.passkey setting\r\n&quot;</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">&quot;Saving settings to Non-volatile Memory\r\n&quot;</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">&quot;Failed save settings\r\n&quot;</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&#39;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">&quot;Updating WiFi module&#39;s internal firmware to latest...\r\n&quot;</span>);</div>
+<div class="line">    printf(<span class="stringliteral">&quot;Updating WiFi module&#39;s internal firmware to latest (note this can take up to 60s)\r\n&quot;</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">&quot;Failed to update the module&#39;s firmware\r\n&quot;</span>);</div>
 <div class="line">        <span class="keywordflow">for</span>(;;); <span class="comment">// infinite loop</span></div>