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
28 // Arduino WiFi Shield
33 // Arduino Ethernet Shield
34 #include <EthernetServer.h>
37 #include <EthernetClient.h>
39 #include <EthernetUdp.h>
43 #include "easysetup.h"
47 const char *getResult(OCStackResult result);
49 char ssid[] = "EasySetup123";
50 char passwd[] = "EasySetup123";
52 void EventCallbackInApp(ESResult eventFlag)
54 Serial.println("callback!!! in app");
57 // On Arduino Atmel boards with Harvard memory architecture, the stack grows
58 // downwards from the top and the heap grows upwards. This method will print
59 // the distance(in terms of bytes) between those two.
60 // See here for more details :
61 // http://www.atmel.com/webdoc/AVRLibcReferenceManual/malloc_1malloc_intro.html
62 void PrintArduinoMemoryStats()
64 #ifdef ARDUINO_AVR_MEGA2560
65 //This var is declared in avr-libc/stdlib/malloc.c
66 //It keeps the largest address not allocated for heap
67 extern char *__brkval;
68 //address of tmp gives us the current stack boundry
70 OC_LOG_V(INFO, TAG, "Stack: %u Heap: %u", (unsigned int)&tmp, (unsigned int)__brkval);
71 OC_LOG_V(INFO, TAG, "Unallocated Memory between heap and stack: %u",
72 ((unsigned int)&tmp - (unsigned int)__brkval));
75 //The setup function is called once at startup of the sketch
78 // Add your initialization code here
79 // Note : This will initialize Serial port on Arduino at 115200 bauds
81 OC_LOG(DEBUG, TAG, "OCServer is starting...");
83 if(InitEasySetup(CT_ADAPTER_IP, ssid, passwd, EventCallbackInApp) == ES_ERROR)
85 OC_LOG(ERROR, TAG, "EasySetup Init Failed");
89 if(InitProvisioning()== ES_ERROR)
91 OC_LOG(ERROR, TAG, "Init Provisioning Failed");
96 // The loop function is called in an endless loop
99 // This artificial delay is kept here to avoid endless spinning
100 // of Arduino microcontroller. Modify it as per specific application needs.
103 // This call displays the amount of free SRAM available on Arduino
104 PrintArduinoMemoryStats();
106 // Give CPU cycles to OCStack to perform send/recv and other OCStack stuff
107 if (OCProcess() != OC_STACK_OK)
109 OC_LOG(ERROR, TAG, "OCStack process error");