Test serial console demonstrating various API functions of WiConnect library.

Dependencies:   WiConnect mbed

Committer:
dan_ackme
Date:
Mon Aug 11 11:31:32 2014 +0000
Revision:
0:836c9a6383e0
Child:
1:5137ec8f4c45
Initial check-in

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 0:836c9a6383e0 1 /*
dan_ackme 0:836c9a6383e0 2 * Copyright 2014, ACKme Networks
dan_ackme 0:836c9a6383e0 3 * All Rights Reserved.
dan_ackme 0:836c9a6383e0 4 *
dan_ackme 0:836c9a6383e0 5 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
dan_ackme 0:836c9a6383e0 6 * the contents of this file may not be disclosed to third parties, copied
dan_ackme 0:836c9a6383e0 7 * or duplicated in any form, in whole or in part, without the prior
dan_ackme 0:836c9a6383e0 8 * written permission of ACKme Networks.
dan_ackme 0:836c9a6383e0 9 */
dan_ackme 0:836c9a6383e0 10
dan_ackme 0:836c9a6383e0 11
dan_ackme 0:836c9a6383e0 12 #include "tests/Tests.h"
dan_ackme 0:836c9a6383e0 13 #include "Wiconnect.h"
dan_ackme 0:836c9a6383e0 14
dan_ackme 0:836c9a6383e0 15
dan_ackme 0:836c9a6383e0 16 static void webSetupCompleteCallback(WiconnectResult result, void *arg1, void *arg2);
dan_ackme 0:836c9a6383e0 17
dan_ackme 0:836c9a6383e0 18
dan_ackme 0:836c9a6383e0 19 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 20 WiconnectResult networkSetupWebCommand(int argc, char **argv)
dan_ackme 0:836c9a6383e0 21 {
dan_ackme 0:836c9a6383e0 22 WiconnectResult result = WICONNECT_BAD_ARG;
dan_ackme 0:836c9a6383e0 23 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 0:836c9a6383e0 24
dan_ackme 0:836c9a6383e0 25 if(strcmp(argv[0], "status") == 0)
dan_ackme 0:836c9a6383e0 26 {
dan_ackme 0:836c9a6383e0 27 bool isRunning;
dan_ackme 0:836c9a6383e0 28
dan_ackme 0:836c9a6383e0 29 if(!WICONNECT_FAILED(result, wiconnect->isWebSetupRunning(&isRunning)))
dan_ackme 0:836c9a6383e0 30 {
dan_ackme 0:836c9a6383e0 31 LOG_INFO("Web setup is %s", isRunning ? "running" : "stopped");
dan_ackme 0:836c9a6383e0 32 }
dan_ackme 0:836c9a6383e0 33 }
dan_ackme 0:836c9a6383e0 34 else if(strcmp(argv[0], "start") == 0)
dan_ackme 0:836c9a6383e0 35 {
dan_ackme 0:836c9a6383e0 36 const char *ssid = (argc > 1) ? argv[1] : NULL;
dan_ackme 0:836c9a6383e0 37 const char *password = (argc > 2) ? argv[2] : NULL;
dan_ackme 0:836c9a6383e0 38
dan_ackme 0:836c9a6383e0 39 if(!WICONNECT_FAILED(result, wiconnect->startWebSetup(ssid, password, Callback(webSetupCompleteCallback))))
dan_ackme 0:836c9a6383e0 40 {
dan_ackme 0:836c9a6383e0 41 LOG_INFO("Web setup started");
dan_ackme 0:836c9a6383e0 42 }
dan_ackme 0:836c9a6383e0 43 }
dan_ackme 0:836c9a6383e0 44 else if(strcmp(argv[0], "stop") == 0)
dan_ackme 0:836c9a6383e0 45 {
dan_ackme 0:836c9a6383e0 46 if(!WICONNECT_FAILED(result, wiconnect->stopWebSetup()))
dan_ackme 0:836c9a6383e0 47 {
dan_ackme 0:836c9a6383e0 48 LOG_INFO("Web setup stopped");
dan_ackme 0:836c9a6383e0 49 }
dan_ackme 0:836c9a6383e0 50 }
dan_ackme 0:836c9a6383e0 51
dan_ackme 0:836c9a6383e0 52 return result;
dan_ackme 0:836c9a6383e0 53 }
dan_ackme 0:836c9a6383e0 54
dan_ackme 0:836c9a6383e0 55 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 56 static void webSetupCompleteCallback(WiconnectResult result, void *arg1, void *arg2)
dan_ackme 0:836c9a6383e0 57 {
dan_ackme 0:836c9a6383e0 58 if(result == WICONNECT_SUCCESS)
dan_ackme 0:836c9a6383e0 59 {
dan_ackme 0:836c9a6383e0 60 LOG_INFO("Web setup successfully completed");
dan_ackme 0:836c9a6383e0 61 }
dan_ackme 0:836c9a6383e0 62 else
dan_ackme 0:836c9a6383e0 63 {
dan_ackme 0:836c9a6383e0 64 LOG_WICONNECT_ERROR(result, "Web setup finished with errors");
dan_ackme 0:836c9a6383e0 65 }
dan_ackme 0:836c9a6383e0 66 }
dan_ackme 0:836c9a6383e0 67