/** * main using gopt to check command line arguments * -h for help */ int main(int argc, char* argv[]) { // Set nabto to default values nabto_main_setup* nms = unabto_init_context(); // Overwrite default values with command line args if (!check_args(argc, argv, nms)) { return 1; } NABTO_LOG_INFO(("Identity: '%s'", nms->id)); NABTO_LOG_INFO(("Program Release %i.%i", RELEASE_MAJOR, RELEASE_MINOR)); NABTO_LOG_INFO(("Buffer size: %i", nms->bufsize)); // Initialize nabto if (!unabto_init()) { NABTO_LOG_FATAL(("Failed at nabto_main_init")); } nabto_stamp_t attachExpireStamp; // 20 seconds nabtoSetFutureStamp(&attachExpireStamp, 1000*20); // The main loop gives nabto a tick from time to time. // Everything else is taken care of behind the scenes. while (true) { unabto_tick(); nabto_yield(10); if (nabtoIsStampPassed(&attachExpireStamp)) { NABTO_LOG_ERROR(("Attach took too long.")); exit(4); } if (unabto_is_connected_to_gsp()) { NABTO_LOG_INFO(("Successfully attached to the gsp, now exiting.")); exit(0); } } NABTO_LOG_ERROR(("we should not end here")); exit(5); unabto_close(); return 0; }
// Query whether a response to a queued request is ready bool application_poll_query(application_request** appreq) { if (saved_app_req) { /** * Fake a delay for demonstration purpose. * This could be replaced with a variable that is first * set when some proccessing is done and a response * to the client should be send. */ static int fake_delay = 0; nabto_yield(20); if (++fake_delay >= 450) { //3000 fake_delay = 0; *appreq = saved_app_req; NABTO_LOG_INFO(("Application poll query: Response ready")); return true; } } return false; }
/** * main using gopt to check command line arguments * -h for help */ int main(int argc, char* argv[]) { // Set nabto to default values nabto_main_setup* nms = unabto_init_context(); // Initialise application if (!application_init()){ NABTO_LOG_FATAL(("Unable to initialise serial connection")); } // Optionally set alternative url to html device driver //nmc.nabtoMainSetup.url = "https://dl.dropbox.com/u/15998645/html_dd_demo.zip"; // Overwrite default values with command line args if (!check_args(argc, argv, nms)) { return 1; } NABTO_LOG_INFO(("Identity: '%s'", nms->id)); NABTO_LOG_INFO(("Program Release %" PRIu32 ".%" PRIu32, RELEASE_MAJOR, RELEASE_MINOR)); NABTO_LOG_INFO(("Buffer size: %d" , nms->bufsize)); // Initialize nabto if (!unabto_init()) { NABTO_LOG_FATAL(("Failed at nabto_main_init")); } // The main loop gives nabto a tick from time to time. // Everything else is taken care of behind the scenes. while (true) { unabto_tick(); nabto_yield(10); } unabto_close(); return 0; }