1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 // Do not remove the include below
25 #include "easysetup.h"
27 const char *getResult(OCStackResult result);
29 PROGMEM const char TAG[] = "ThinServer";
31 void EventCallbackInApp(ESResult eventFlag)
33 Serial.println("callback!!! in app");
36 // On Arduino Atmel boards with Harvard memory architecture, the stack grows
37 // downwards from the top and the heap grows upwards. This method will print
38 // the distance(in terms of bytes) between those two.
39 // See here for more details :
40 // http://www.atmel.com/webdoc/AVRLibcReferenceManual/malloc_1malloc_intro.html
41 void PrintArduinoMemoryStats()
43 #ifdef ARDUINO_AVR_MEGA2560
44 //This var is declared in avr-libc/stdlib/malloc.c
45 //It keeps the largest address not allocated for heap
46 extern char *__brkval;
47 //address of tmp gives us the current stack boundry
49 OC_LOG_V(INFO, TAG, "Stack: %u Heap: %u", (unsigned int)&tmp, (unsigned int)__brkval);
50 OC_LOG_V(INFO, TAG, "Unallocated Memory between heap and stack: %u",
51 ((unsigned int)&tmp - (unsigned int)__brkval));
54 //The setup function is called once at startup of the sketch
57 // Add your initialization code here
58 // Note : This will initialize Serial port on Arduino at 115200 bauds
60 OC_LOG(DEBUG, TAG, PCF("OCServer is starting..."));
62 if (InitEasySetup(ES_BLE, EventCallbackInApp) == ES_ERROR)
64 OC_LOG(ERROR, TAG, "EasySetup Init Failed");
68 if (InitProvisioning(EventCallbackInApp) == ES_ERROR)
70 OC_LOG(ERROR, TAG, "Init Provisioning Failed");
75 // The loop function is called in an endless loop
78 // This artificial delay is kept here to avoid endless spinning
79 // of Arduino microcontroller. Modify it as per specific application needs.
82 // This call displays the amount of free SRAM available on Arduino
83 PrintArduinoMemoryStats();
85 // Give CPU cycles to OCStack to perform send/recv and other OCStack stuff
86 if (OCProcess() != OC_STACK_OK)
88 OC_LOG(ERROR, TAG, PCF("OCStack process error"));