Commit d8ea3a8b authored by lankamadan's avatar lankamadan Committed by Madan Lanka

[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: default avatarlankamadan <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3491Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
parent 9edcb388
File mode changed from 100755 to 100644
......@@ -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
......
......@@ -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
......
......@@ -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)
......
File mode changed from 100755 to 100644
......@@ -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;
}
}
......
......@@ -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;
......
File mode changed from 100755 to 100644
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment