This demonstrates how to update the WiFi modules firmware using the WiConnect host library.

Dependencies:   WiConnect mbed

Files at this revision

API Documentation at this revision

Comitter:
dan_ackme
Date:
Thu Nov 27 09:14:05 2014 +0000
Commit message:
Initial check-in

Changed in this revision

WiConnect.lib Show annotated file Show diff for this revision Revisions of this file
example.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
target_config.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WiConnect.lib	Thu Nov 27 09:14:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ACKme/code/WiConnect/#5ee74d72efe4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example.cpp	Thu Nov 27 09:14:05 2014 +0000
@@ -0,0 +1,145 @@
+/**
+ * @example ota/example.cpp
+ *
+ * This is an example of using the wiconnect API to update
+ * the wifi module's internal firmware to the latest version.
+ *
+ * It works as follows:
+ * 1. Instantiate the WiConnect Library
+ * 2. Initiate Communication with WiFi Module
+ * 3. Set the network credentials
+ * 4. Call the 'updateFirmware' wiconnect API and wait for the update to complete (takes ~60s)
+ * 5. That's it!
+ *
+ *
+ */
+
+
+/******************************************************************************
+ * Example Variables
+ */
+
+// This is the name of your WiFi network
+// Look for this name in your WiFi settings
+// (e.g. your phone's list of WiFi networks in the WiFi settings menu)
+// tip: add double-quotes around SSID to add spaces to name
+#define NETWORK_SSID "\"<YOUR NETWORK NAME HERE>\""
+
+
+// This is the password of your WiFi network
+// Leave as empty string (e.g "") to connect to OPEN network
+#define NETWORK_PASSWORD "\"<YOUR NETWORK PASSWORD HERE>\""
+
+/******************************************************************************
+ * Includes
+ */
+
+// include C library headers
+#include <stdio.h> // needed for printf
+
+// include target specific defines
+#include "target_config.h"
+// include the Wiconnect Host Library API header
+#include "Wiconnect.h"
+
+
+
+/******************************************************************************
+ * Global Defines
+ */
+
+
+// Serial used for printfs to terminal (i.e. NOT used for WiConnect)
+static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
+
+
+/******************************************************************************
+ * Starting point of application
+ */
+int main(int argc, char **argv)
+{
+    WiconnectResult result;
+    
+    consoleSerial.baud(115200); // console terminal to 115200 baud
+
+    //-------------------------------------------------------------------------
+    // STEP 1: Instantiate WiConnect Library
+    //-------------------------------------------------------------------------
+
+    // Setup  wiconnect serial interface configuration
+    // Here we only specify the rx buffer size and not rx buffer pointer, this means
+    // The serial RX buffer will be dynamically allocated
+    SerialConfig serialConfig(WICONNECT_RX_PIN, WICONNECT_TX_PIN, 256, NULL);
+
+    // Instantiate the Wiconnect library
+    // Here we only specify the buffer size and not buffer pointer, this means
+    // The internal buffer will be dynamically allocated
+    Wiconnect wiconnect(serialConfig, 256, NULL, WICONNECT_RESET_PIN);
+
+    //-------------------------------------------------------------------------
+    // STEP 2: Initiate Communication with WiFi Module
+    //-------------------------------------------------------------------------
+
+    printf("Initializing WiConnect Library...\r\n");
+
+    // Initialize communication with WiFi module
+    if(WICONNECT_FAILED(result, wiconnect.init(true)))
+    {
+        // if the error is that the firmware is out-dated, then continue, else stop
+        if(result != WICONNECT_FIRMWARE_OUTDATED)
+        {
+            printf("Failed to initialize communication with WiFi module!\r\n"
+                    "Make sure the wires are connected correctly\r\n");
+            for(;;); // infinite loop
+        }
+    }
+
+
+    //-------------------------------------------------------------------------
+    // STEP 3: Set the network credentials
+    // Note: We manually set the network parameters to ensure SDK backward compatibility
+    //-------------------------------------------------------------------------
+
+    printf("Setting network SSID: %s\r\n", NETWORK_SSID);
+    if(WICONNECT_FAILED(result, wiconnect.setSetting("wlan.ssid", NETWORK_SSID)))
+    {
+        printf("Failed to set wlan.ssid setting\r\n");
+        for(;;); // infinite loop
+    }
+    
+    printf("Setting network password\r\n");
+    if(WICONNECT_FAILED(result, wiconnect.setSetting("wlan.passkey", NETWORK_PASSWORD)))
+    {
+        printf("Failed to set wlan.passkey setting\r\n");
+        for(;;); // infinite loop
+    }
+
+    printf("Saving settings to Non-volatile Memory\r\n");
+    if(WICONNECT_FAILED(result, wiconnect.saveSettings()))
+    {
+        printf("Failed save settings\r\n");
+        for(;;); // infinite loop
+    }
+    
+    //-------------------------------------------------------------------------
+    // STEP 4: Update the module's firmware, this takes about 60s
+    //-------------------------------------------------------------------------
+
+    printf("Updating WiFi module's internal firmware to latest (note this can take up to 60s)\r\n");
+
+    if(wiconnect.updateFirmware() != WICONNECT_SUCCESS)
+    {
+        printf("Failed to update the module's firmware\r\n");
+        for(;;); // infinite loop
+    }
+
+    //-------------------------------------------------------------------------
+    // STEP 5: Done!
+    //-------------------------------------------------------------------------
+
+    wiconnect.getVersion();
+    printf("Version: %s\r\n", wiconnect.getResponseBuffer());
+
+    while(true){} // infinite loop
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 27 09:14:05 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target_config.h	Thu Nov 27 09:14:05 2014 +0000
@@ -0,0 +1,92 @@
+/**
+ * ACKme WiConnect Host Library is licensed under the BSD licence: 
+ * 
+ * Copyright (c)2014 ACKme Networks.
+ * All rights reserved. 
+ * 
+ * Redistribution and use in source and binary forms, with or without modification, 
+ * are permitted provided that the following conditions are met: 
+ * 
+ * 1. Redistributions of source code must retain the above copyright notice, 
+ * this list of conditions and the following disclaimer. 
+ * 2. Redistributions in binary form must reproduce the above copyright notice, 
+ * this list of conditions and the following disclaimer in the documentation 
+ * and/or other materials provided with the distribution. 
+ * 3. The name of the author may not be used to endorse or promote products 
+ * derived from this software without specific prior written permission. 
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED 
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
+ * OF SUCH DAMAGE.
+ */
+#pragma once
+
+
+// The BAUD rate your PC/MAC/Linux terminal uses with the eval board
+#define CONSOLE_BAUD 115200
+
+
+// Uncomment this to enable WiConnect serial interface hardware flow control
+// NOTE: your platform must support the serial flow control api functions
+//#define ENABLE_FLOW_CONTROL
+
+
+#define WICONNECT_INTERNAL_BUFFER_SIZE (4*1024)
+#define WICONNECT_SERIAL_RX_BUFFER_SIZE (4*1024)
+
+#define DEFAULT_CMD_GETCHAR_TIMEOUT 250
+#define DEFAULT_COMMAND_LINE_LENGTH_MAX 128
+#define DEFAULT_COMMAND_MAX_HISTORY 16
+#define DEFAULT_CMD_PROMPT_STR "> "
+#define DEFAULT_COMMAND_MAX_ARGV 16
+
+#define TEST_NONBLOCKING_API false
+#define TEST_BUFFER_LENGTH 4*1024
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Seabass Target Configuration
+#ifdef TARGET_SEABASS
+
+#define WICONNECT_TX_PIN PA_9
+#define WICONNECT_RX_PIN PA_10
+#define WICONNECT_RESET_PIN PB_0
+#define WICONNECT_WAKE_PIN NC
+
+#ifdef ENABLE_FLOW_CONTROL
+#define WICONNECT_CTS_PIN PA_11
+#define WICONNECT_RTS_PIN PA_12
+#else
+#define WICONNECT_CTS_PIN NC
+#define WICONNECT_RTS_PIN NC
+#endif
+
+#endif
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Nucleo F401RE Target Configuration
+#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
+
+#define WICONNECT_TX_PIN PA_9
+#define WICONNECT_RX_PIN PA_10
+#define WICONNECT_RESET_PIN PC_7
+#define WICONNECT_WAKE_PIN NC
+
+#ifdef ENABLE_FLOW_CONTROL
+#define WICONNECT_CTS_PIN PA_11
+#define WICONNECT_RTS_PIN PA_12
+#else
+#define WICONNECT_CTS_PIN NC
+#define WICONNECT_RTS_PIN NC
+#endif
+
+#endif
+