[easy-setup] Updated Arduino Enrollee sample app for taking user input
authorlankamadan <lanka.madan@samsung.com>
Mon, 5 Oct 2015 13:13:47 +0000 (22:13 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 6 Oct 2015 14:27:37 +0000 (14:27 +0000)
- 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 <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3623
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
service/easy-setup/sdk/common/escommon.h
service/easy-setup/sdk/enrollee/api/easysetup.h
service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.cpp [changed mode: 0755->0644]
service/easy-setup/sdk/enrollee/arduino/wifi/networkHandler.h [changed mode: 0755->0644]
service/easy-setup/sdk/enrollee/src/easysetup.cpp
service/easy-setup/sdk/enrollee/src/resourceHandler.cpp
service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp [changed mode: 0755->0644]

index b1b712f..b07a3c3 100644 (file)
@@ -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
index 70b38ad..e3b0adc 100644 (file)
 #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
old mode 100755 (executable)
new mode 100644 (file)
index 92d7360..d4b3327
@@ -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)
index 5fa44fc..9855710 100644 (file)
@@ -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;
         }
     }
index aacdbee..6c0fec2 100644 (file)
@@ -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;