3c4770174c73f16c1d2cb591e1065de53a55962e
[platform/upstream/iotivity.git] / resource / csdk / stack / test / arduino / ocserver.cpp
1 #include <Time.h>
2 #include <SPI.h>
3 #include <Ethernet.h>
4 #include <ocstack.h>
5 #include <logger.h>
6
7 static uint8_t ETHERNET_MAC[] = {0x90, 0xA2, 0xDA, 0x0F, 0x2B, 0x72 };
8
9 #define TAG PCF("ocserver")
10
11 void ocInitialize () {
12     char ipAddr[16] = "";
13     OCGetInterfaceAddress (NULL, 0, AF_INET, (uint8_t *)ipAddr, 16);
14     OC_LOG(DEBUG, TAG, PCF("IP addr is:"));
15     OC_LOG_BUFFER(INFO, TAG, (uint8_t*)ipAddr, sizeof(ipAddr));
16     delay(2000);
17     OCInit (ipAddr, 8001, OC_SERVER);
18 }
19
20 void setup() {
21         Serial.begin(115200);
22    
23     Serial.println ("Trying to get an IP addr using DHCP");
24     if (Ethernet.begin(ETHERNET_MAC) == 0) {
25         Serial.println("DHCP failed");
26     }
27         ocInitialize ();
28 }
29
30 void loop() {
31         Serial.println ("Processing CoAP messages!\n");
32     OCProcess ();
33         delay(1000);
34 }