-//******************************************************************
-//
-// Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+/******************************************************************
+*
+* Copyright 2014 Samsung Electronics All Rights Reserved.
+*
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+******************************************************************/
// Do not remove the include below
#include "Arduino.h"
char temp[100];
-#define LENGTH_VAR 100
+#define LENGTH_VAR 100
static int base_length = 0;
-bool JsonGenerator( THResource& th, char* jsonBuf, uint16_t buf_length )
+bool JsonGenerator( THResource &th, char *jsonBuf, uint16_t buf_length )
{
- if( (buf_length - base_length) < LENGTH_VAR )
- {
- OC_LOG_V(ERROR, TAG, "Error : length is very long.");
- return false;
- }
+ if ( (buf_length - base_length) < LENGTH_VAR )
+ {
+ OC_LOG_V(ERROR, TAG, "Error : length is very long.");
+ return false;
+ }
- sprintf(jsonBuf, JSON_BASE00 JSON_BASE01"%d",th.m_temp);
- sprintf(jsonBuf+strlen(jsonBuf), JSON_BASE02"%d"JSON_BASE03, th.m_humid);
+ sprintf(jsonBuf, JSON_BASE00 JSON_BASE01"%d", th.m_temp);
+ sprintf(jsonBuf + strlen(jsonBuf), JSON_BASE02"%d"JSON_BASE03, th.m_humid);
- Serial.println(jsonBuf);
+ Serial.println(jsonBuf);
- return true;
+ return true;
}
byte read_dht11_dat()
// 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 )
+OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
+ OCEntityHandlerRequest *entityHandlerRequest )
{
OCEntityHandlerResult ehRet = OC_EH_OK;
OCEntityHandlerResponse response = {0};
char payload[MAX_RESPONSE_LENGTH] = {0};
- if(entityHandlerRequest && (flag & OC_REQUEST_FLAG))
+ if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
{
OC_LOG (INFO, TAG, PCF("Flag includes OC_REQUEST_FLAG"));
- if(OC_REST_GET == entityHandlerRequest->method)
+ if (OC_REST_GET == entityHandlerRequest->method)
{
- if(JsonGenerator( TH, payload, MAX_RESPONSE_LENGTH))
- {
- }
- else
+ if (JsonGenerator( TH, payload, MAX_RESPONSE_LENGTH))
+ {
+ }
+ else
{
ehRet = OC_EH_ERROR;
}
}
- if(OC_REST_PUT == entityHandlerRequest->method)
+ if (OC_REST_PUT == entityHandlerRequest->method)
{
//Do something with the 'put' payload
if (JsonGenerator( TH, payload, MAX_RESPONSE_LENGTH))
{
ehRet = OC_EH_ERROR;
}
- }
+ }
if (ehRet == OC_EH_OK)
- {
- // Format the response. Note this requires some info about the request
- response.requestHandle = entityHandlerRequest->requestHandle;
- response.resourceHandle = entityHandlerRequest->resource;
- response.ehResult = ehRet;
- response.payload = (unsigned char *)payload;
- response.payloadSize = strlen(payload);
- response.numSendVendorSpecificHeaderOptions = 0;
- memset(response.sendVendorSpecificHeaderOptions, 0, sizeof response.sendVendorSpecificHeaderOptions);
- memset(response.resourceUri, 0, sizeof response.resourceUri);
- // Indicate that response is NOT in a persistent buffer
- response.persistentBufferFlag = 0;
-
- // Send the response
- if (OCDoResponse(&response) != OC_STACK_OK)
- {
- OC_LOG(ERROR, TAG, "Error sending response");
- ehRet = OC_EH_ERROR;
- }
- }
+ {
+ // Format the response. Note this requires some info about the request
+ response.requestHandle = entityHandlerRequest->requestHandle;
+ response.resourceHandle = entityHandlerRequest->resource;
+ response.ehResult = ehRet;
+ response.payload = (unsigned char *)payload;
+ response.payloadSize = strlen(payload);
+ response.numSendVendorSpecificHeaderOptions = 0;
+ memset(response.sendVendorSpecificHeaderOptions, 0,
+ sizeof response.sendVendorSpecificHeaderOptions);
+ memset(response.resourceUri, 0, sizeof response.resourceUri);
+ // Indicate that response is NOT in a persistent buffer
+ response.persistentBufferFlag = 0;
+
+ // Send the response
+ if (OCDoResponse(&response) != OC_STACK_OK)
+ {
+ OC_LOG(ERROR, TAG, "Error sending response");
+ ehRet = OC_EH_ERROR;
+ }
+ }
}
if (entityHandlerRequest && (flag & OC_OBSERVE_FLAG))
{
TH.m_humid = dht11_dat[0];
TH.m_temp = dht11_dat[2];
- if (g_THUnderObservation)
+ if (g_THUnderObservation)
{
OC_LOG_V(INFO, TAG, " =====> Notifying stack of new humid level %d\n", TH.m_humid);
OC_LOG_V(INFO, TAG, " =====> Notifying stack of new temp level %d\n", TH.m_temp);
TH.m_temp = 0;
OCStackResult res = OCCreateResource(&TH.m_handle,
- "SoftSensorManager.Sensor",
- "oc.mi.def",
- "/Thing_TempHumSensor1",
+ "SSManager.Sensor",
+ OC_RSRVD_INTERFACE_DEFAULT,
+ "/Thing_TempHumSensor",
OCEntityHandlerCb,
OC_DISCOVERABLE | OC_OBSERVABLE);
OC_LOG_V(INFO, TAG, "Created TH resource with result: %s", getResult(res));