1 //******************************************************************
3 // Copyright 2014 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
29 // Arduino WiFi Shield
34 // Arduino Ethernet Shield
35 #include <EthernetServer.h>
38 #include <EthernetClient.h>
40 #include <EthernetUdp.h>
44 #include "easysetup.h"
46 const char *getResult(OCStackResult result);
48 PROGMEM const char TAG[] = "ThinServer";
50 char ssid[] = "hub2.4G";
51 char passwd[] = "09877890";
53 void EventCallbackInApp(ES_RESULT eventFlag)
55 Serial.println("callback!!! in app");
58 // On Arduino Atmel boards with Harvard memory architecture, the stack grows
59 // downwards from the top and the heap grows upwards. This method will print
60 // the distance(in terms of bytes) between those two.
61 // See here for more details :
62 // http://www.atmel.com/webdoc/AVRLibcReferenceManual/malloc_1malloc_intro.html
63 void PrintArduinoMemoryStats()
65 #ifdef ARDUINO_AVR_MEGA2560
66 //This var is declared in avr-libc/stdlib/malloc.c
67 //It keeps the largest address not allocated for heap
68 extern char *__brkval;
69 //address of tmp gives us the current stack boundry
71 OC_LOG_V(INFO, TAG, "Stack: %u Heap: %u", (unsigned int)&tmp, (unsigned int)__brkval);
72 OC_LOG_V(INFO, TAG, "Unallocated Memory between heap and stack: %u",
73 ((unsigned int)&tmp - (unsigned int)__brkval));
76 //The setup function is called once at startup of the sketch
79 // Add your initialization code here
80 // Note : This will initialize Serial port on Arduino at 115200 bauds
82 OC_LOG(DEBUG, TAG, PCF("OCServer is starting..."));
84 FindNetworkForOnboarding(ES_WIFI, ssid, passwd, EventCallbackInApp);
86 // Initialize the OC Stack in Server mode
87 if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
89 OC_LOG(ERROR, TAG, PCF("OCStack init error"));
93 InitializeProvisioning(EventCallbackInApp);
95 if (OCStartPresence(0) != OC_STACK_OK)
97 OC_LOG(ERROR, TAG, PCF("Start Presence init error"));
102 // The loop function is called in an endless loop
105 // This artificial delay is kept here to avoid endless spinning
106 // of Arduino microcontroller. Modify it as per specific application needs.
109 // This call displays the amount of free SRAM available on Arduino
110 PrintArduinoMemoryStats();
112 // Give CPU cycles to OCStack to perform send/recv and other OCStack stuff
113 if (OCProcess() != OC_STACK_OK)
115 OC_LOG(ERROR, TAG, PCF("OCStack process error"));