int main(int argc, char** argv) { uint8_t addr[20] = {0}; uint8_t* paddr = NULL; uint16_t port = OC_WELL_KNOWN_PORT; uint8_t ifname[] = "wlan0"; pthread_t threadId; pthread_t threadId_presence; int opt; printf ("OCServer is starting...\n"); if (OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr)) == ERR_SUCCESS) { printf ("Starting ocserver on address %s:%d\n",addr,port); paddr = addr; } /* * Init IoTivity as a SERVER. */ if (OCInit((char *) paddr, port, OC_SERVER) != OC_STACK_OK) { printf ("OCStack init error\n"); return 0; } OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandlerCb); OCStackResult deviceResult = SetDeviceInfo(contentType, dateOfManufacture, deviceName, deviceUUID, firmwareVersion, hostName, manufacturerName, manufacturerUrl, modelNumber, platformVersion, supportUrl, version); deviceResult = OCSetDeviceInfo(deviceInfo); if (deviceResult != OC_STACK_OK) { printf ("Device Registration failed!\n"); exit (EXIT_FAILURE); } DeleteDeviceInfo(); /* * Create ONE light resource. */ createLightResource(gResourceUri, &Light); printf ("Entering ocserver main loop...\n"); signal(SIGINT, handleSigInt); while (!gQuitFlag) { /* * Main IoTivity function for processing. */ if (OCProcess() != OC_STACK_OK) { printf ("OCStack process error\n"); return 0; } sleep(2); } if (OCStop() != OC_STACK_OK) { printf ("OCStack process error\n"); } return 0; }
void ocInitialize () { char ipAddr[16] = ""; OCGetInterfaceAddress (NULL, 0, AF_INET, (uint8_t *)ipAddr, 16); OC_LOG(DEBUG, TAG, PCF("IP addr is:")); OC_LOG_BUFFER(INFO, TAG, (uint8_t*)ipAddr, sizeof(ipAddr)); delay(2000); OCInit (ipAddr, 8001, OC_SERVER); }
int main(int argc, char** argv) { uint8_t addr[20] = {0}; uint8_t* paddr = NULL; uint16_t port = USE_RANDOM_PORT; uint8_t ifname[] = "wlan0"; int opt; printf ("OCClient is starting...\n"); if (OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr)) == ERR_SUCCESS) { printf ("Starting occlient on address %s\n",addr); paddr = addr; } if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) { printf ("OCStack init error\n"); return 0; } InitDiscovery (); signal(SIGINT, handleSigInt); while (!gQuitFlag) { if (OCProcess() != OC_STACK_OK) { printf ("OCStack process error\n"); return 0; } sleep(2); } if (OCStop() != OC_STACK_OK) { printf ("OCStack process error\n"); } return 0; }
int main(int argc, char* argv[]) { uint8_t addr[20] = {0}; uint8_t* paddr = NULL; uint16_t port = OC_WELL_KNOWN_PORT; uint8_t ifname[] = "eth0"; pthread_t threadId; pthread_t threadId_presence; int opt; while ((opt = getopt(argc, argv, "o:")) != -1) { switch(opt) { case 'o': gObserveNotifyType = atoi(optarg); break; default: PrintUsage(); return -1; } } if ((gObserveNotifyType != 0) && (gObserveNotifyType != 1)) { PrintUsage(); return -1; } OC_LOG(DEBUG, TAG, "OCServer is starting..."); /*Get Ip address on defined interface and initialize coap on it with random port number * this port number will be used as a source port in all coap communications*/ if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr)) == ERR_SUCCESS) { OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port); paddr = addr; } if (OCInit((char *) paddr, port, OC_SERVER) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack init error"); return 0; } #ifdef WITH_PRESENCE if (OCStartPresence(0) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack presence/discovery error"); return 0; } #endif OCSetDefaultDeviceEntityHandler(OCDeviceEntityHandlerCb); OCStackResult deviceResult = SetDeviceInfo(contentType, dateOfManufacture, deviceName, deviceUUID, firmwareVersion, hostName, manufacturerName, manufacturerUrl, modelNumber, platformVersion, supportUrl, version); if (deviceResult != OC_STACK_OK) { OC_LOG(INFO, TAG, "Device Registration failed!"); exit (EXIT_FAILURE); } deviceResult = OCSetDeviceInfo(deviceInfo); if (deviceResult != OC_STACK_OK) { OC_LOG(INFO, TAG, "Device Registration failed!"); exit (EXIT_FAILURE); } /* * Declare and create the example resource: Light */ createLightResource(gResourceUri, &Light); // Initialize observations data structure for the resource for (uint8_t i = 0; i < SAMPLE_MAX_NUM_OBSERVATIONS; i++) { interestedObservers[i].valid = false; } /* * Create a thread for changing the representation of the Light */ pthread_create (&threadId, NULL, ChangeLightRepresentation, (void *)NULL); /* * Create a thread for generating changes that cause presence notifications * to be sent to clients */ pthread_create(&threadId_presence, NULL, presenceNotificationGenerator, (void *)NULL); // Break from loop with Ctrl-C OC_LOG(INFO, TAG, "Entering ocserver main loop..."); DeleteDeviceInfo(); signal(SIGINT, handleSigInt); while (!gQuitFlag) { if (OCProcess() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack process error"); return 0; } sleep(2); } /* * Cancel the Light thread and wait for it to terminate */ pthread_cancel(threadId); pthread_join(threadId, NULL); pthread_cancel(threadId_presence); pthread_join(threadId_presence, NULL); OC_LOG(INFO, TAG, "Exiting ocserver main loop..."); if (OCStop() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack process error"); } return 0; }
int main(int argc, char* argv[]) { uint8_t addr[20] = {0}; uint8_t* paddr = NULL; uint16_t port = USE_RANDOM_PORT; uint8_t ifname[] = "eth0"; int opt; while ((opt = getopt(argc, argv, "u:t:")) != -1) { switch(opt) { case 'u': UNICAST_DISCOVERY = atoi(optarg); break; case 't': TEST_CASE = atoi(optarg); break; default: PrintUsage(); return -1; } } if ((UNICAST_DISCOVERY != 0 && UNICAST_DISCOVERY != 1) || (TEST_CASE < TEST_DISCOVER_REQ || TEST_CASE >= MAX_TESTS) ) { PrintUsage(); return -1; } /*Get Ip address on defined interface and initialize coap on it with random port number * this port number will be used as a source port in all coap communications*/ if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr)) == ERR_SUCCESS) { OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr); paddr = addr; } /* Initialize OCStack*/ if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack init error"); return 0; } InitDiscovery(); // Break from loop with Ctrl+C OC_LOG(INFO, TAG, "Entering occlient main loop..."); signal(SIGINT, handleSigInt); while (!gQuitFlag) { if (OCProcess() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack process error"); return 0; } sleep(2); } OC_LOG(INFO, TAG, "Exiting occlient main loop..."); if (OCStop() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack stop error"); } return 0; }
int main(int argc, char* argv[]) { uint8_t addr[20] = {0}; uint8_t* paddr = NULL; uint16_t port = 0; uint8_t ifname[] = "eth0"; pthread_t threadId; int opt; while ((opt = getopt(argc, argv, "t:")) != -1) { switch(opt) { case 't': TEST = atoi(optarg); break; default: PrintUsage(); return -1; } } if(TEST <= TEST_INVALID || TEST >= MAX_TESTS){ PrintUsage(); return -1; } OC_LOG(DEBUG, TAG, "OCServer is starting..."); /*Get Ip address on defined interface and initialize coap on it with random port number * this port number will be used as a source port in all coap communications*/ if (OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr)) == ERR_SUCCESS) { OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port); paddr = addr; } if (OCInit((char *) paddr, port, OC_SERVER) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack init error"); return 0; } /* * Declare and create the example resource: light */ createResources(); /* * Create a thread for changing the representation of the light */ pthread_create (&threadId, NULL, ChangeLightRepresentation, (void *)NULL); // Break from loop with Ctrl-C OC_LOG(INFO, TAG, "Entering ocserver main loop..."); signal(SIGINT, handleSigInt); while (!gQuitFlag) { if (OCProcess() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack process error"); return 0; } sleep(2); } /* * Cancel the light thread and wait for it to terminate */ pthread_cancel(threadId); pthread_join(threadId, NULL); OC_LOG(INFO, TAG, "Exiting ocserver main loop..."); if (OCStop() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack process error"); } return 0; }
int main( int argc, char* argv[] ) { uint8_t addr[20] = {0}; uint8_t* paddr = NULL; uint16_t port = USE_RANDOM_PORT; xmpp_ctx_t *ctx = NULL; xmpp_conn_t* conn = NULL; int reg_act = DMC_REGISTER; int errornum=0; void *ptr; pthread_attr_init(&attr1); pthread_attr_setstacksize(&attr1, PTHREAD_STACK_MIN * 2); if(!setPIN("2345678901")) { fprintf(stderr, "PIN read error\n"); return 1; } else printf("\t\tRead PIN : %s\n", getPIN()); if( argc < 2 ) { exit(-1); } uint8_t *ifname = (uint8_t *)argv[1]; /*Get Ip address on defined interface and initialize coap on it with random port number * this port number will be used as a source port in all coap communications*/ if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr)) == ERR_SUCCESS) { OC_LOG_V(INFO, TAG, "Starting occlient on address %s",addr); paddr = addr; } /* Initialize OCStack*/ if (OCInit((char *) paddr, port, OC_CLIENT) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack init error"); return 0; } time(&last_discovery_time); InitDiscovery(); // conn = XMPP_Init( xmpp_un , xmpp_pw , xmpp_server, &ctx); // Break from loop with Ctrl+C OC_LOG(INFO, TAG, "Entering occlient main loop..."); signal(SIGINT, handleSigInt); while (!gQuitFlag) { if( cmd_head != NULL ) { switch( cmd_head->command ) { case COMMAND_DISCOVERY: InitDiscovery(); break; case COMMAND_GET: InitGetRequest(cmd_head); break; case COMMAND_PUT: InitPutRequest(cmd_head); break; case COMMAND_POST: InitPutRequest(cmd_head); break; case COMMAND_OBSERVE: break; default: break; } struct cmd *cmd_temp = cmd_head; cmd_head = cmd_head->next; free(cmd_temp); } else { //do discovery every 10 seconds time_t now; time(&now); if( now - last_discovery_time > DMC_INTERVAL ) { struct dmc_result *res = dmc_discovery_finish(reg_act); if( res->state == REG_SUCCEED ) { reg_act = DMC_UPDATE; snprintf( xmpp_un, sizeof(xmpp_un), "%s", res->username ); snprintf( xmpp_pw, sizeof(xmpp_pw), "%s", res->password ); snprintf( xmpp_server, sizeof(xmpp_server), "%s", res->server ); free( res ); printf("%s\n%s\n%s\n", xmpp_server, xmpp_un, xmpp_pw); if(conn==NULL) { conn = XMPP_Init( \ xmpp_un , xmpp_pw, xmpp_server, &ctx); if(ctx !=NULL) pthread_create(&pid1, \ &attr1, (void*)xmpp_run, (void*)ctx ); else printf("ctx null\n"); } } else free(res); OC_LOG_V( INFO, TAG, "DM client returns state %s", get_dmcresult_char(res->state) ); InitDiscovery(); time(&last_discovery_time); } } if (OCProcess() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack process error"); return 0; } usleep(200*1000); } printf("Quit\n"); OC_LOG(INFO, TAG, "Exiting occlient main loop..."); if (OCStop() != OC_STACK_OK) { OC_LOG_V(ERROR, TAG, "OCStack stop error"); } xmpp_stop(ctx); sleep(1); XMPP_Close(ctx, conn); if ((errornum = pthread_cancel(pid1)) != 0) OC_LOG_V(INFO, TAG, "pthread_cancel: %s", strerror(errornum)); if ((errornum = pthread_join(pid1, &ptr)) != 0) OC_LOG_V(INFO, TAG, "pthread_join: %s", strerror(errornum)); printf("Done\n"); return 0; }
int main(int argc, char* argv[]) { uint8_t addr[20] = {0}; uint8_t* paddr = NULL; uint16_t port = OC_WELL_KNOWN_PORT; uint8_t ifname[] = "eth0"; OC_LOG(DEBUG, TAG, "OCServer is starting..."); /*Get Ip address on defined interface and initialize coap on it with random port number * this port number will be used as a source port in all coap communications*/ if ( OCGetInterfaceAddress(ifname, sizeof(ifname), AF_INET, addr, sizeof(addr)) == ERR_SUCCESS) { OC_LOG_V(INFO, TAG, "Starting ocserver on address %s:%d",addr,port); paddr = addr; } if (OCInit((char *) paddr, port, OC_SERVER) != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack init error"); return 0; } /* * Declare and create the example resource: LED */ createLEDResource(gResourceUri, &LED, false, 0); // Initialize slow response alarm signal(SIGALRM, AlarmHandler); // Break from loop with Ctrl-C OC_LOG(INFO, TAG, "Entering ocserver main loop..."); signal(SIGINT, handleSigInt); while (!gQuitFlag) { if (OCProcess() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack process error"); return 0; } sleep(2); } OC_LOG(INFO, TAG, "Exiting ocserver main loop..."); // Free requests if (!gRequestList.empty()) { for (auto iter = gRequestList.begin(); iter != gRequestList.end(); ++iter) { OCFree((*iter)->query); OCFree((*iter)->reqJSONPayload); OCFree(*iter); } gRequestList.clear(); } if (OCStop() != OC_STACK_OK) { OC_LOG(ERROR, TAG, "OCStack process error"); } return 0; }