1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
15 #define TAG PCF("ocserver")
18 void createLEDResource();
20 typedef struct LEDRESOURCE{
21 OCResourceHandle handle;
25 static LEDResource LED;
27 /* SIGINT handler: set gQuitFlag to 1 for graceful termination */
28 void handleSigInt(int signum) {
29 if (signum == SIGINT) {
36 uint16_t port = USE_RANDOM_PORT;
37 uint8_t ifname[] = "eth0";
39 /*Get Ip address on defined interface and initialize coap on it with random port number
40 * this port number will be used as a source port in all coap communications*/
41 OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr));
43 OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port);
44 if (OCInit((char *) addr, port, OC_SERVER) != OC_STACK_OK) {
45 OC_LOG(ERROR, TAG, "OCStack init error");
50 * Declare and create the example resource: LED
54 // Break from loop with Ctrl-C
55 OC_LOG(INFO, TAG, "Entering ocserver main loop...");
56 signal(SIGINT, handleSigInt);
59 if (OCProcess() != OC_STACK_OK) {
60 OC_LOG(ERROR, TAG, "OCStack process error");
67 OC_LOG(INFO, TAG, "Exiting ocserver main loop...");
69 if (OCStop() != OC_STACK_OK) {
70 OC_LOG(ERROR, TAG, "OCStack process error");
76 void createLEDResource() {
78 OCStackResult res = OCCreateResource(&LED.handle,
80 "state:oc.bt.b;power:oc.bt.i",
82 OC_REST_GET|OC_REST_PUT,
85 OC_DISCOVERABLE|OC_OBSERVABLE);