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

Optimized Arduino Logging using PCF

- Modified the error case handling in Enrollee
- Optimized Logging

Change-Id: I6567d748579a207326543ce768bfed107f3f5576
Signed-off-by: default avatarlankamadan <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2464Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
parent 484244c7
......@@ -46,8 +46,8 @@ const char *getResult(OCStackResult result);
PROGMEM const char TAG[] = "ThinServer";
char ssid[] = "hub2.4G";
char passwd[] = "11112222";
char ssid[] = "EasySetup123";
char passwd[] = "EasySetup123";
void EventCallbackInApp(ESResult eventFlag)
{
......@@ -80,13 +80,13 @@ void setup()
OC_LOG_INIT();
OC_LOG(DEBUG, TAG, PCF("OCServer is starting..."));
if(InitEasySetup(ES_WIFI, ssid, passwd, EventCallbackInApp) != ES_OK)
if(InitEasySetup(ES_WIFI, ssid, passwd, EventCallbackInApp) == ES_ERROR)
{
OC_LOG(ERROR, TAG, "EasySetup Init Failed");
return;
}
if(InitProvisioning(EventCallbackInApp)!= ES_OK)
if(InitProvisioning(EventCallbackInApp)== ES_ERROR)
{
OC_LOG(ERROR, TAG, "Init Provisioning Failed");
return;
......
......@@ -20,7 +20,7 @@
#include "networkHandler.h"
PROGMEM const char TAG[] = "networkHandler";
#define TAG PCF("ES_NH")
int findNetwork(const char *ssid);
int ConnectToNetwork(const char *ssid, const char *pass);
......@@ -124,7 +124,7 @@ int ConnectToNetwork(const char *ssid, const char *pass)
// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
OC_LOG_V(INFO, TAG, "Attempting to connect to SSID: %s", ssid);
OC_LOG_V(INFO, TAG, PCF("Attempting to connect to SSID: %s"), ssid);
status = WiFi.begin((char *) ssid, (char *) pass);
......@@ -134,7 +134,7 @@ int ConnectToNetwork(const char *ssid, const char *pass)
OC_LOG(DEBUG, TAG, PCF("Connected to wifi"));
myIP = WiFi.localIP();
OC_LOG_V(INFO, TAG, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
OC_LOG_V(INFO, TAG, PCF("IP Address: %d.%d.%d.%d"), myIP[0], myIP[1], myIP[2], myIP[3]);
char buf[50];
sprintf(buf, "IP Address: %d.%d.%d.%d", myIP[0], myIP[1], myIP[2], myIP[3]);
......
......@@ -21,6 +21,8 @@
#include "easysetup.h"
#include "ocstack.h"
#define TAG PCF("ES")
int g_eventflag = 0;
int g_cnt = 0;
char *targetSsid;
......@@ -55,7 +57,7 @@ void EventCallbackInProvisioning(ESResult event)
if(TerminateEasySetup() != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "Terminating stack failed");
OC_LOG(ERROR, TAG, PCF("Terminating stack failed"));
return;
}
......@@ -98,7 +100,15 @@ ESResult FindNetworkForOnboarding(NetworkType networkType,
g_cbForOnboarding = cb;
}
return ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding);
if(ConnectToWiFiNetwork(ssid, passwd, EventCallbackInOnboarding) != ES_NETWORKCONNECTED)
{
OC_LOG(ERROR, TAG, PCF("ConnectToWiFiNetwork Failed"));
return ES_ERROR;
}
else{
OC_LOG(INFO, TAG, PCF("ConnectToWiFiNetwork Success"));
return ES_OK;
}
}
}
......@@ -108,19 +118,19 @@ ESResult InitEasySetup(NetworkType networkType, const char *ssid, const char *pa
{
if(FindNetworkForOnboarding(networkType, ssid, passwd, cb) != ES_OK)
{
OC_LOG(ERROR, TAG, "OnBoarding Failed");
OC_LOG(ERROR, TAG, PCF("OnBoarding Failed"));
return ES_ERROR;
}
// Initialize the OC Stack in Server mode
if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
{
OC_LOG(INFO, TAG, PCF("OCStack init error"));
OC_LOG(ERROR, TAG, PCF("OCStack init error"));
return ES_ERROR;
}
else
{
OC_LOG(ERROR, TAG, PCF("OCStack init success"));
OC_LOG(DEBUG, TAG, PCF("OCStack init success"));
return ES_OK;
}
}
......
......@@ -21,7 +21,7 @@
#include "resourceHandler.h"
#include "ocpayload.h"
PROGMEM const char TAG[] = "resourceHandler";
#define TAG PCF("ES_RH")
ProvResource g_prov;
NetResource g_net;
......@@ -67,7 +67,7 @@ OCStackResult CreateProvisioningResource()
OCStackResult res = OCCreateResource(&g_prov.handle, "oic.prov", OC_RSRVD_INTERFACE_DEFAULT,
OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
OC_LOG_V(INFO, TAG, "Created Prov resource with result: %s", getResult(res));
OC_LOG_V(INFO, TAG, PCF("Created Prov resource with result: %s"), getResult(res));
return res;
}
......@@ -92,8 +92,8 @@ OCStackResult CreateNetworkResource()
netInfo.ipaddr[3]);
sprintf(g_net.cnn, "%s", netInfo.ssid);
OC_LOG_V(INFO, TAG, "SSID: %s", g_net.cnn);
OC_LOG_V(INFO, TAG, "IP Address: %s", g_net.ipaddr);
OC_LOG_V(INFO, TAG, PCF("SSID: %s"), g_net.cnn);
OC_LOG_V(INFO, TAG, PCF("IP Address: %s"), g_net.ipaddr);
OCStackResult res = OCCreateResource(&g_net.handle, "oic.net", OC_RSRVD_INTERFACE_DEFAULT,
OC_RSRVD_ES_URI_NET, OCEntityHandlerCb,NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
......@@ -120,7 +120,7 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
OCRepPayload *getResp = constructResponse(ehRequest);
if(!getResp)
{
OC_LOG(ERROR, TAG, "constructResponse failed");
OC_LOG(ERROR, TAG, PCF("constructResponse failed"));
return OC_EH_ERROR;
}
......@@ -144,7 +144,7 @@ OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
if(!input)
{
OC_LOG_V(ERROR, TAG, "Failed to parse");
OC_LOG_V(ERROR, TAG, PCF("Failed to parse"));
return ehResult;
}
......@@ -165,7 +165,7 @@ OCEntityHandlerResult ProcessPutRequest (OCEntityHandlerRequest *ehRequest,
OCRepPayload *getResp = constructResponse(ehRequest);
if(!getResp)
{
OC_LOG(ERROR, TAG, "constructResponse failed");
OC_LOG(ERROR, TAG, PCF("constructResponse failed"));
return OC_EH_ERROR;
}
......@@ -196,7 +196,7 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
OCRepPayload* input = (OCRepPayload*)(ehRequest->payload);
if(!input)
{
OC_LOG_V(ERROR, TAG, "Failed to parse" );
OC_LOG_V(ERROR, TAG, PCF("Failed to parse") );
return ehResult;
}
char* tr;
......@@ -252,12 +252,12 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
{
if (OC_REST_GET == entityHandlerRequest->method)
{
OC_LOG_V(INFO, TAG, "Received GET request");
OC_LOG_V(INFO, TAG, PCF("Received GET request"));
ehRet = ProcessGetRequest(entityHandlerRequest, &payload);
}
else if (OC_REST_PUT == entityHandlerRequest->method)
{
OC_LOG_V(INFO, TAG, "Received PUT request");
OC_LOG_V(INFO, TAG, PCF("Received PUT request"));
if (g_prov.handle != NULL && entityHandlerRequest->resource == g_prov.handle)
{
......@@ -293,7 +293,7 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
// Send the response
if (OCDoResponse(&response) != OC_STACK_OK)
{
OC_LOG(ERROR, TAG, "Error sending response");
OC_LOG(ERROR, TAG, PCF("Error sending response"));
ehRet = OC_EH_ERROR;
}
}
......
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