From d8ea3a8bc424ee2b028b4e13d86ac25045f31da0 Mon Sep 17 00:00:00 2001 From: lankamadan Date: Mon, 5 Oct 2015 22:13:47 +0900 Subject: [PATCH] [easy-setup] Updated Arduino Enrollee sample app for taking user input - Modified Arduino sample and the corresponding code to accept input from sample user - Added a new enum to provide the status of the enrollee along with the result - Modified the callback handler to accept enrollee status Change-Id: Ie0e8720c17315c0e022155727cc472f854308ead Signed-off-by: lankamadan Reviewed-on: https://gerrit.iotivity.org/gerrit/3491 Tested-by: jenkins-iotivity --- .../sampleapp/enrollee/arduino/enrollee_wifi.cpp | 0 service/easy-setup/sdk/common/escommon.h | 48 ++++++++++++++++ service/easy-setup/sdk/enrollee/api/easysetup.h | 4 +- .../sdk/enrollee/arduino/wifi/networkHandler.cpp | 2 +- .../sdk/enrollee/arduino/wifi/networkHandler.h | 0 service/easy-setup/sdk/enrollee/src/easysetup.cpp | 67 +++++++++++++++------- .../sdk/enrollee/src/resourceHandler.cpp | 2 +- .../sdk/mediator/src/wifi_provisioning.cpp | 0 8 files changed, 98 insertions(+), 25 deletions(-) mode change 100755 => 100644 service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp mode change 100755 => 100644 service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp mode change 100755 => 100644 service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h mode change 100755 => 100644 service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp diff --git a/service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp b/service/easy-setup/sampleapp/enrollee/arduino/enrollee_wifi.cpp old mode 100755 new mode 100644 diff --git a/service/easy-setup/sdk/common/escommon.h b/service/easy-setup/sdk/common/escommon.h index b1b712f..b07a3c3 100644 --- a/service/easy-setup/sdk/common/escommon.h +++ b/service/easy-setup/sdk/common/escommon.h @@ -60,6 +60,7 @@ static const char * UNICAST_PROV_STATUS_QUERY = "coap://%s:%d%s"; typedef enum { + ES_ERROR = -1, ES_OK = 0, ES_NETWORKFOUND = 1, @@ -72,6 +73,53 @@ typedef enum ES_RECVTRIGGEROFPROVRES, } ESResult; +typedef enum +{ + /** + * Default state of the device + */ + ES_INIT_STATE, + + /** + * Device will move to this state once the on boarding begins + */ + ES_ON_BOARDING_STATE, + + /** + * Device will move to this state after successful on-boarding of the device + */ + ES_ON_BOARDED_STATE, + + /** + * Device will move to this state once the on boarding is done + */ + ES_PROVISIONING_STATE, + + /** + * Easy setup process is successful. + */ + ES_PROVISIONED_STATE, + + /** + * This state is arbitrary one, any time device can come into this state + * Device will move to this state if the ownership transfer initiated by the Application + */ + ES_OWNERSHIP_TRANSFERRING_STATE, + + /** + * This state is arbitrary one, any time device can come into this state + * Device will move to this state if the ownership transfer is completed + */ + ES_OWNERSHIP_TRANSFERRED_STATE, + + /** + * This state is arbitrary one, any time device can come into this state + * Device will move to this state once the Application factory reset the device + */ + ES_FACTORY_RESET_STATE, +}EnrolleeState; + + /** * Provisioning Device Status diff --git a/service/easy-setup/sdk/enrollee/api/easysetup.h b/service/easy-setup/sdk/enrollee/api/easysetup.h index 70b38ad..e3b0adc 100644 --- a/service/easy-setup/sdk/enrollee/api/easysetup.h +++ b/service/easy-setup/sdk/enrollee/api/easysetup.h @@ -27,11 +27,9 @@ #ifndef EASYSETUP_ENROLLEE_H__ #define EASYSETUP_ENROLLEE_H__ -// Do not remove the include below #include "Arduino.h" #include "escommon.h" - #ifdef __cplusplus extern "C" { #endif // __cplusplus @@ -41,7 +39,7 @@ extern "C" { * * @param esResult ESResult provides the current state of the Enrollee Device */ -typedef void (*EventCallback)(ESResult esResult); +typedef void (*EventCallback)(ESResult esResult, EnrolleeState enrolleeState); /** * This function Initializes the EasySetup. This API must be called prior to invoking any other API diff --git a/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp old mode 100755 new mode 100644 index 92d7360..d4b3327 --- a/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp +++ b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp @@ -110,7 +110,7 @@ ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCa if (cb != NULL) { - cb(ES_NETWORKFOUND); + cb(ES_OK); } if (WiFi.status() == WL_CONNECTED) diff --git a/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h b/service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h old mode 100755 new mode 100644 diff --git a/service/easy-setup/sdk/enrollee/src/easysetup.cpp b/service/easy-setup/sdk/enrollee/src/easysetup.cpp index 5fa44fc..9855710 100644 --- a/service/easy-setup/sdk/enrollee/src/easysetup.cpp +++ b/service/easy-setup/sdk/enrollee/src/easysetup.cpp @@ -61,26 +61,35 @@ static EventCallback g_cbForEnrolleeStatus = NULL; // Private internal function prototypes //----------------------------------------------------------------------------- -void EventCallbackInOnboarding(ESResult event); -void EventCallbackInProvisioning(ESResult event); -void EventCallbackAfterProvisioning(ESResult event); +void EventCallbackInOnboarding(ESResult esResult); +void EventCallbackInProvisioning(ESResult esResult); +void EventCallbackAfterProvisioning(ESResult esResult); -void EventCallbackInOnboarding(ESResult event) +void EventCallbackInOnboarding(ESResult esResult) { - if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED) - { - if (g_cbForEnrolleeStatus != NULL) - { - g_cbForEnrolleeStatus(event); + if (g_cbForEnrolleeStatus != NULL){ + OC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Calling the application with esResult = %d", esResult); + if(esResult == ES_OK){ + OC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Calling the application with enrolleestate = %d", + ES_ON_BOARDED_STATE); + g_cbForEnrolleeStatus(esResult, ES_ON_BOARDED_STATE); } + else{ + OC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Calling the application with enrolleestate = %d", + ES_INIT_STATE); + g_cbForEnrolleeStatus(esResult, ES_INIT_STATE); + } + } + else{ + OC_LOG(ERROR, ES_ENROLLEE_TAG, "g_cbForEnrolleeStatus is NULL"); } } -void EventCallbackInProvisioning(ESResult event) +void EventCallbackInProvisioning(ESResult esResult) { ESResult res = ES_OK; - if (event == ES_RECVTRIGGEROFPROVRES) + if (esResult == ES_RECVTRIGGEROFPROVRES) { targetSsid = (char *) malloc(MAXSSIDLEN); targetPass = (char *) malloc(MAXNETCREDLEN); @@ -97,19 +106,37 @@ void EventCallbackInProvisioning(ESResult event) if (g_cbForEnrolleeStatus != NULL) { - g_cbForEnrolleeStatus(res); + if(res == ES_NETWORKCONNECTED){ + OC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Calling the application with enrolleestate = %d", + ES_PROVISIONED_STATE); + g_cbForEnrolleeStatus(ES_OK, ES_PROVISIONED_STATE); + } + else{ + OC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Calling the application with enrolleestate = %d", + ES_PROVISIONING_STATE); + g_cbForEnrolleeStatus(ES_OK, ES_PROVISIONING_STATE); + } + } } } -void EventCallbackAfterProvisioning(ESResult event) +void EventCallbackAfterProvisioning(ESResult esResult) { - if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED) - { - if (g_cbForEnrolleeStatus != NULL) - { - g_cbForEnrolleeStatus(event); + if (g_cbForEnrolleeStatus != NULL){ + if(esResult == ES_OK){ + OC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Calling the application with enrolleestate = %d", + ES_PROVISIONED_STATE); + g_cbForEnrolleeStatus(esResult, ES_PROVISIONED_STATE); } + else{ + OC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Calling the application with enrolleestate = %d", + ES_PROVISIONING_STATE); + g_cbForEnrolleeStatus(esResult, ES_PROVISIONING_STATE); + } + } + else{ + OC_LOG(ERROR, ES_ENROLLEE_TAG, "g_cbForEnrolleeStatus is NULL"); } } @@ -133,12 +160,12 @@ ESResult FindNetworkForOnboarding(OCConnectivityType networkType, if(ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding) != ES_NETWORKCONNECTED) { OC_LOG(ERROR, ES_ENROLLEE_TAG, "ConnectToWiFiNetwork Failed"); - cb(ES_NETWORKNOTCONNECTED); + cb(ES_ERROR, ES_ON_BOARDING_STATE); return ES_ERROR; } else{ OC_LOG(INFO, ES_ENROLLEE_TAG, "ConnectToWiFiNetwork Success"); - cb(ES_NETWORKCONNECTED); + cb(ES_OK, ES_ON_BOARDED_STATE); return ES_OK; } } diff --git a/service/easy-setup/sdk/enrollee/src/resourceHandler.cpp b/service/easy-setup/sdk/enrollee/src/resourceHandler.cpp index aacdbee..6c0fec2 100644 --- a/service/easy-setup/sdk/enrollee/src/resourceHandler.cpp +++ b/service/easy-setup/sdk/enrollee/src/resourceHandler.cpp @@ -58,7 +58,7 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload); OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest); -int g_flag = 0; +static int g_flag = 0; ResourceEventCallback g_cbForResEvent = NULL; diff --git a/service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp b/service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp old mode 100755 new mode 100644 -- 2.7.4