Simple example demonstrating WiConnect host library web setup feature.

Dependencies:   WiConnect mbed

Files at this revision

API Documentation at this revision

Comitter:
dan_ackme
Date:
Wed Aug 13 10:18:30 2014 +0000
Child:
1:44eae7ea80c7
Commit message:
initial check-in

Changed in this revision

Wiconnect.lib Show annotated file Show diff for this revision Revisions of this file
main.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	Wed Aug 13 10:18:30 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ACKme/code/Wiconnect/#d3cd02b201e1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 13 10:18:30 2014 +0000
@@ -0,0 +1,154 @@
+/**
+ * @example web_setup/example.cpp
+ *
+ * This is an example of using the web setup network API to
+ * configure the module network credentials remotely.
+ *
+ * It works as follows:
+ * 1. Instantiate the WiConnect Library
+ * 2. Initiate Communication with WiFi Module
+ * 3. Start WebSetup with specified parameters
+ * 4. Wait for web setup webpage to complete
+ * 5. That's it!
+ *
+ *
+ */
+
+
+/******************************************************************************
+ * Example Variables
+ */
+
+// This is the name of the WebSetup 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 WEB_SETUP_SSID "\"WiConnect WebSetup Example\""
+
+// This is the password for the WebSetup network
+// Leave as empty string (e.g "") to create OPEN network
+#define WEB_SETUP_PASSWORD "password"
+
+
+
+
+/******************************************************************************
+ * 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"
+
+
+
+/******************************************************************************
+ * Local Functions
+ */
+static void webSetupCompleteCallback(WiconnectResult result, void *arg1, void *arg2);
+
+
+/******************************************************************************
+ * Global Defines
+ */
+
+
+// Serial used for printfs to terminal (i.e. NOT used for WiConnect)
+static Serial consoleSerial(STDIO_UART_TX, STDIO_UART_RX);
+
+// Buffer used internally by WiConnect library, note that this is optional
+static uint8_t wiconnectInternalBuffer[256];
+
+// Flag that indicate websetup has completed
+static volatile bool webSetupCompleteFlag = false;
+
+
+/******************************************************************************
+ * Starting point of application
+ */
+int main(int argc, char **argv)
+{
+    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 specify the buffer size AND buffer pointer, this means we're using static allocation
+    Wiconnect wiconnect(serialConfig, sizeof(wiconnectInternalBuffer), wiconnectInternalBuffer, WICONNECT_RESET_PIN);
+
+
+    //-------------------------------------------------------------------------
+    // STEP 2: Initiate Communication with WiFi Module
+    //-------------------------------------------------------------------------
+
+    printf("Initializing WiConnect Library...\r\n");
+
+    // Initialize communication with WiFi module
+    if(wiconnect.init(true) != WICONNECT_SUCCESS)
+    {
+        printf("Failed to initialize communication with WiFi module!\r\n"
+                "Make sure the wires are connected correctly\r\n");
+        for(;;); // infinite loop
+    }
+
+
+    //-------------------------------------------------------------------------
+    // STEP 3: Start WebSetup with specified parameters
+    //-------------------------------------------------------------------------
+
+    printf("Starting Websetup...\r\n");
+
+    // Start web setup
+    if(wiconnect.startWebSetup(WEB_SETUP_SSID, WEB_SETUP_PASSWORD, Callback(webSetupCompleteCallback)) != WICONNECT_SUCCESS)
+    {
+        printf("Failed to start web setup\r\n");
+        for(;;); // infinite loop
+    }
+
+    //-------------------------------------------------------------------------
+    // STEP 4: Wait for web setup webpage to complete
+    //-------------------------------------------------------------------------
+
+    printf("Web setup has started.\r\n\r\n");
+    printf("1. Using your phone (or PC, Mac, Linux, etc.)\r\n   connect to the WiFi network: %s\r\n", WEB_SETUP_SSID);
+    printf("2. The password is: %s\r\n", WEB_SETUP_PASSWORD);
+    printf("3. Once connected, open your browser and enter the URL: http://setup.com\r\n");
+    printf("4. This will bringup a setup page, enter your router's credentials.\r\n");
+    printf("5. Click the 'Save & Exit' button at the bottom of the webpage\r\n\r\n");
+
+    while(!webSetupCompleteFlag)
+    {
+        // do nothing while we wait
+        // When the user exits web setup from the webpage
+        // webSetupCompleteCallback() will execute and set webSetupCompleteFlag TRUE
+    }
+
+    //-------------------------------------------------------------------------
+    // STEP 5: Done!
+    //-------------------------------------------------------------------------
+
+    printf("Web setup example has completed!\r\n");
+
+    for(;;); // infinite loop
+
+    return 0;
+}
+
+
+// this function is called when web setup completes
+// it is called in the background
+static void webSetupCompleteCallback(WiconnectResult result, void *arg1, void *arg2)
+{
+    webSetupCompleteFlag = true;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Aug 13 10:18:30 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target_config.h	Wed Aug 13 10:18:30 2014 +0000
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2014, ACKme Networks
+ * All Rights Reserved.
+ *
+ * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
+ * the contents of this file may not be disclosed to third parties, copied
+ * or duplicated in any form, in whole or in part, without the prior
+ * written permission of ACKme Networks.
+ */
+
+#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
+#ifdef TARGET_NUCLEO_F401RE
+
+#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