Commit 484244c7 authored by lankamadan's avatar lankamadan Committed by Madan Lanka

Updated the Arduino APIs and updated sample app

- Arduino EasySetup APIs are updated
- ES_RESULT is changed to ESResult
- Updated sample application

Change-Id: I29c3d024ea42c1c4edf6a3586e604bfe9f18b1aa
Signed-off-by: default avatarlankamadan <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2446Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
parent 964ab276
......@@ -22,7 +22,6 @@
#include "Arduino.h"
#include "logger.h"
#include "ocstack.h"
#include <string.h>
#ifdef ARDUINOWIFI
......@@ -50,7 +49,7 @@ PROGMEM const char TAG[] = "ThinServer";
char ssid[] = "hub2.4G";
char passwd[] = "11112222";
void EventCallbackInApp(ES_RESULT eventFlag)
void EventCallbackInApp(ESResult eventFlag)
{
Serial.println("callback!!! in app");
}
......@@ -81,23 +80,17 @@ void setup()
OC_LOG_INIT();
OC_LOG(DEBUG, TAG, PCF("OCServer is starting..."));
FindNetworkForOnboarding(ES_WIFI, ssid, passwd, EventCallbackInApp);
// Initialize the OC Stack in Server mode
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
if(InitEasySetup(ES_WIFI, ssid, passwd, EventCallbackInApp) != ES_OK)
{
OC_LOG(ERROR, TAG, PCF("OCStack init error"));
OC_LOG(ERROR, TAG, "EasySetup Init Failed");
return;
}
InitializeProvisioning(EventCallbackInApp);
/* if (OCStartPresence(0) != OC_STACK_OK)
if(InitProvisioning(EventCallbackInApp)!= ES_OK)
{
OC_LOG(ERROR, TAG, PCF("Start Presence init error"));
OC_LOG(ERROR, TAG, "Init Provisioning Failed");
return;
}
*/
}
// The loop function is called in an endless loop
......
......@@ -70,7 +70,7 @@ typedef enum
ES_RECVREQOFNETRES,
ES_RECVUPDATEOFPROVRES,
ES_RECVTRIGGEROFPROVRES,
} ES_RESULT;
} ESResult;
/**
......
......@@ -34,7 +34,7 @@ static const char ARDUINO_WIFI_SHIELD_UDP_FW_VER[] = "1.1.0";
IPAddress myIP;
ES_RESULT ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback cb)
{
char *fwVersion;
int status = WL_IDLE_STATUS;
......
......@@ -40,7 +40,7 @@
#define MAXNUMTYPE 5
#define MAXADDRLEN 15
typedef void (*NetworkEventCallback)(ES_RESULT);
typedef void (*NetworkEventCallback)(ESResult);
enum NetworkType
{
......@@ -59,7 +59,7 @@ typedef struct NETWORKINFO
byte mac[6];
} NetworkInfo;
ES_RESULT ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback);
ESResult ConnectToWiFiNetwork(const char *ssid, const char *pass, NetworkEventCallback);
int getCurrentNetworkInfo(NetworkType targetType, NetworkInfo *info);
#endif
......@@ -29,15 +29,10 @@
#include "networkHandler.h"
#include "resourceHandler.h"
typedef void (*EventCallback)(ES_RESULT);
typedef void (*EventCallback)(ESResult);
OCStackResult Init();
ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,
EventCallback cb);
ESResult InitProvisioning(EventCallback cb);
ESResult TerminateEasySetup();
ES_RESULT FindNetworkForOnboarding(NetworkType networkType, EventCallback);
ES_RESULT FindNetworkForOnboarding(NetworkType networkType, const char *name, const char *pass,
EventCallback);
//OCStackResult FindNetworkForOnboarding(NetworkType networkType, char *name);
//OCStackResult FindNetworkForOnboarding(NetworkType networkType, char *name, char *pass);
ES_RESULT InitializeProvisioning(EventCallback);
......@@ -32,7 +32,7 @@
#ifndef ES_RESOURCE_HANDLER_H_
#define ES_RESOURCE_HANDLER_H_
typedef void (*ResourceEventCallback)(ES_RESULT);
typedef void (*ResourceEventCallback)(ESResult);
/* Structure to represent a Light resource */
typedef struct PROVRESOURCE
......
......@@ -19,10 +19,7 @@
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#include "easysetup.h"
/// WiFi network info and credentials
char defaultSsid[] = "EasyConnect";
char defaultPass[] = "EasyConnect";
#include "ocstack.h"
int g_eventflag = 0;
int g_cnt = 0;
......@@ -32,11 +29,11 @@ char *targetPass;
EventCallback g_cbForProvisioning = NULL;
EventCallback g_cbForOnboarding = NULL;
void EventCallbackInOnboarding(ES_RESULT event);
void EventCallbackInProvisioning(ES_RESULT event);
void EventCallbackAfterProvisioning(ES_RESULT event);
void EventCallbackInOnboarding(ESResult event);
void EventCallbackInProvisioning(ESResult event);
void EventCallbackAfterProvisioning(ESResult event);
void EventCallbackInOnboarding(ES_RESULT event)
void EventCallbackInOnboarding(ESResult event)
{
if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
{
......@@ -47,15 +44,21 @@ void EventCallbackInOnboarding(ES_RESULT event)
}
}
void EventCallbackInProvisioning(ES_RESULT event)
void EventCallbackInProvisioning(ESResult event)
{
ES_RESULT res = ES_OK;
ESResult res = ES_OK;
if (event == ES_RECVTRIGGEROFPROVRES)
{
targetSsid = (char *) malloc(MAXSSIDLEN);
targetPass = (char *) malloc(MAXNETCREDLEN);
if(TerminateEasySetup() != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "Terminating stack failed");
return;
}
GetTargetNetworkInfoFromProvResource(targetSsid, targetPass);
res = ConnectToWiFiNetwork(targetSsid, targetPass, EventCallbackAfterProvisioning);
......@@ -67,7 +70,7 @@ void EventCallbackInProvisioning(ES_RESULT event)
}
}
void EventCallbackAfterProvisioning(ES_RESULT event)
void EventCallbackAfterProvisioning(ESResult event)
{
if (event == ES_NETWORKFOUND || event == ES_NETWORKCONNECTED)
{
......@@ -78,8 +81,16 @@ void EventCallbackAfterProvisioning(ES_RESULT event)
}
}
ES_RESULT FindNetworkForOnboarding(NetworkType networkType, EventCallback cb)
ESResult FindNetworkForOnboarding(NetworkType networkType,
const char *ssid,
const char *passwd,
EventCallback cb)
{
if (!ssid || !passwd)
{
return ES_ERROR;
}
if (networkType == ES_WIFI)
{
if (g_cbForOnboarding == NULL)
......@@ -87,30 +98,48 @@ ES_RESULT FindNetworkForOnboarding(NetworkType networkType, EventCallback cb)
g_cbForOnboarding = cb;
}
return ConnectToWiFiNetwork(defaultSsid, defaultPass, EventCallbackInOnboarding);
return ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding);
}
}
ES_RESULT FindNetworkForOnboarding(NetworkType networkType, const char *ssid, const char *passwd,
EventCallback cb)
ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *passwd,
EventCallback cb)
{
if (!ssid || !passwd)
if(FindNetworkForOnboarding(networkType, ssid, passwd, cb) != ES_OK)
{
OC_LOG(ERROR, TAG, "OnBoarding Failed");
return ES_ERROR;
}
if (networkType == ES_WIFI)
// Initialize the OC Stack in Server mode
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
{
if (g_cbForOnboarding == NULL)
{
g_cbForOnboarding = cb;
}
OC_LOG(INFO, TAG, PCF("OCStack init error"));
return ES_ERROR;
}
else
{
OC_LOG(ERROR, TAG, PCF("OCStack init success"));
return ES_OK;
}
}
return ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding);
ESResult TerminateEasySetup()
{
if(OCStop() != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, PCF("OCStack stop failed"));
return ES_ERROR;
}
else
{
OC_LOG(ERROR, TAG, PCF("OCStack stop success"));
return ES_OK;
}
}
ES_RESULT InitializeProvisioning(EventCallback cb)
ESResult InitProvisioning(EventCallback cb)
{
if (cb == NULL)
{
......
......@@ -26,13 +26,19 @@ PROGMEM const char TAG[] = "resourceHandler";
ProvResource g_prov;
NetResource g_net;
OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag, OCEntityHandlerRequest *, void *callback);
OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
OCEntityHandlerRequest *ehRequest,
void *callback);
const char *getResult(OCStackResult result);
OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,OCRepPayload** payload);
OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,OCRepPayload** payload);
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,OCRepPayload** payload);
OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
OCRepPayload** payload);
OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
OCRepPayload** payload);
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
OCRepPayload** payload);
OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest);
int g_flag = 0;
ResourceEventCallback g_cbForResEvent = NULL;
......@@ -96,7 +102,8 @@ OCStackResult CreateNetworkResource()
return res;
}
OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
OCRepPayload **payload)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if(!ehRequest)
......@@ -124,7 +131,7 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
}
OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
OCRepPayload** payload)
OCRepPayload** payload)
{
OCEntityHandlerResult ehResult=OC_EH_ERROR;
......@@ -171,7 +178,8 @@ OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
}
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
OCRepPayload** payload)
{
OCEntityHandlerResult ehResult = OC_EH_ERROR;
if(!ehRequest)
......@@ -232,7 +240,6 @@ OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
// This is the entity handler for the registered resource.
// This is invoked by OCStack whenever it recevies a request for this resource.
OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
OCEntityHandlerRequest* entityHandlerRequest,void *callback)
{
......@@ -274,7 +281,8 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
response.requestHandle = entityHandlerRequest->requestHandle;
response.resourceHandle = entityHandlerRequest->resource;
response.ehResult = ehRet;
response.payload = (OCPayload*)(payload); //response uses OCPaylod while all get,put methodes use OCRepPayload
//response uses OCPaylod while all get,put methodes use OCRepPayload
response.payload = (OCPayload*)(payload);
response.numSendVendorSpecificHeaderOptions = 0;
memset(response.sendVendorSpecificHeaderOptions, 0,
sizeof response.sendVendorSpecificHeaderOptions);
......
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