PROCESS_THREAD(plugtest_server, ev, data) { PROCESS_BEGIN(); PRINTF("ETSI IoT CoAP Plugtests Server\n"); PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); PRINTF("LL header: %u\n", UIP_LLH_LEN); PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); /* if static routes are used rather than RPL */ #if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) set_global_address(); configure_routing(); #endif /* Initialize the REST engine. */ rest_init_engine(); /* Activate the application-specific resources. */ #if REST_RES_TEST rest_activate_resource(&resource_test); #endif #if REST_RES_LONG rest_activate_resource(&resource_longpath); #endif #if REST_RES_QUERY rest_activate_resource(&resource_query); #endif #if REST_RES_SEPARATE rest_activate_periodic_resource(&periodic_resource_separate); #endif #if REST_RES_LARGE rest_activate_resource(&resource_large); #endif #if REST_RES_LARGE_UPDATE large_update_ct = REST.type.APPLICATION_OCTET_STREAM; rest_activate_resource(&resource_large_update); #endif #if REST_RES_LARGE_CREATE rest_activate_resource(&resource_large_create); #endif #if REST_RES_OBS rest_activate_periodic_resource(&periodic_resource_obs); #endif /* Define application-specific events here. */ while(1) { PROCESS_WAIT_EVENT(); } /* while (1) */ PROCESS_END(); }
/*----------------------------------------------------------------------------*/ PROCESS_THREAD(tres_process, ev, data) { PROCESS_BEGIN(); srand(node_id); rest_init_engine(); tres_init(); SENSORS_ACTIVATE(light_sensor); rest_activate_periodic_resource(&periodic_resource_light); rplinfo_activate_resources(); static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */ SERVER_NODE(&server_ipaddr); /* receives all CoAP messages */ coap_receiver_init(); int wait_time = getRandUint(MAX_WAITING); int base_wait = BASE_WAITING; static int g_time=0; static char content[12]; etimer_set(&et, (wait_time + base_wait) * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) break; } etimer_reset(&et); etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); while(1) { PROCESS_YIELD(); if (etimer_expired(&et)) { coap_init_message(request, COAP_TYPE_NON, COAP_POST, 0 ); coap_set_header_uri_path(request, service_urls[1]); coap_set_payload(request, content, snprintf(content, sizeof(content), "%d", g_time++)); coap_transaction_t *transaction; request->mid = coap_get_mid(); if ((transaction = coap_new_transaction(request->mid, &server_ipaddr, REMOTE_PORT))) { transaction->packet_len = coap_serialize_message(request, transaction->packet); coap_send_transaction(transaction); } etimer_reset(&et); } } /* while (1) */ PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(coap_sample, ev, data) { PROCESS_BEGIN(); /* Initialize the REST engine. */ rest_init_engine(); /* Activate the application-specific resources. */ rest_activate_resource(&resource_camera); rest_activate_resource(&resource_take); rest_activate_resource(&resource_size); rest_activate_resource(&resource_count); rest_activate_resource(&resource_packet); #if UIP_CONF_IPV6_RPL rest_activate_resource(&resource_route); #endif rest_activate_periodic_resource(&periodic_resource_temperature); rest_activate_periodic_resource(&periodic_resource_light); rest_activate_periodic_resource(&periodic_resource_voltage); PROCESS_END(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(coap_sample, ev, data) { PROCESS_BEGIN(); //rs232_redirect_stdout(RS232_PORT_1); co2_init(); /* Initialize the REST engine. */ rest_init_engine(); /* Activate the application-specific resources. */ rest_activate_periodic_resource(&periodic_resource_co2); PROCESS_END(); }
PROCESS_THREAD(relay_coap_server, ev, data) { PROCESS_BEGIN(); PRINTF("Starting Relay Coap Server\n"); #ifdef RF_CHANNEL PRINTF("RF channel: %u\n", RF_CHANNEL); #endif #ifdef IEEE802154_PANID PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID); #endif PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); PRINTF("LL header: %u\n", UIP_LLH_LEN); PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); /* if static routes are used rather than RPL */ #if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) && !defined (CONTIKI_TARGET_NATIVE) set_global_address(); configure_routing(); #endif /* Initialize the REST engine. */ rest_init_engine(); /* Activate the application-specific resources. */ #if REST_RES_HELLO rest_activate_resource(&resource_helloworld); #endif #if REST_RES_MIRROR rest_activate_resource(&resource_mirror); #endif #if REST_RES_CHUNKS rest_activate_resource(&resource_chunks); #endif #if REST_RES_PUSHING rest_activate_periodic_resource(&periodic_resource_pushing); #endif #if defined (PLATFORM_HAS_BUTTON) && REST_RES_EVENT rest_activate_event_resource(&resource_event); #endif #if defined (PLATFORM_HAS_BUTTON) && REST_RES_SEPARATE && WITH_COAP > 3 /* No pre-handler anymore, user coap_separate_accept() and coap_separate_reject(). */ rest_activate_resource(&resource_separate); #endif #if defined (PLATFORM_HAS_BUTTON) && (REST_RES_EVENT || (REST_RES_SEPARATE && WITH_COAP > 3)) SENSORS_ACTIVATE(button_sensor); #endif #if REST_RES_SUB rest_activate_resource(&resource_sub); #endif #if defined (PLATFORM_HAS_LEDS) #if REST_RES_LEDS rest_activate_resource(&resource_leds); #endif #if REST_RES_TOGGLE rest_activate_resource(&resource_toggle); #endif #endif /* PLATFORM_HAS_LEDS */ #if defined (PLATFORM_HAS_LIGHT) && REST_RES_LIGHT SENSORS_ACTIVATE(light_sensor); rest_activate_resource(&resource_light); #endif #if defined (PLATFORM_HAS_BATTERY) && REST_RES_BATTERY SENSORS_ACTIVATE(battery_sensor); rest_activate_resource(&resource_battery); #endif #if defined (PLATFORM_HAS_RADIO) && REST_RES_RADIO SENSORS_ACTIVATE(radio_sensor); rest_activate_resource(&resource_radio); #endif #if defined REST_RES_EXTRELAY relay_enable(0); rest_activate_resource(&resource_extrelay); #endif /* Define application-specific events here. */ while(1) { PROCESS_WAIT_EVENT(); #if defined (PLATFORM_HAS_BUTTON) if (ev == sensors_event && data == &button_sensor) { PRINTF("BUTTON\n"); #if REST_RES_EVENT /* Call the event_handler for this application-specific event. */ event_event_handler(&resource_event); #endif #if REST_RES_SEPARATE && WITH_COAP>3 /* Also call the separate response example handler. */ separate_finalize_handler(); #endif } #endif /* PLATFORM_HAS_BUTTON */ } /* while (1) */ PROCESS_END(); }
static void sensor_init() { SENSORS_ACTIVATE(co2_sensor); rest_activate_periodic_resource(&periodic_resource_co2_resource); }
void CoAPServerImpl::activate(PeriodicResource* resource) { resource->_resource.handler = handleRequest; resource->_periodicResource.periodic_handler = handlePeriodic; rest_activate_periodic_resource(&resource->_periodicResource); }
PROCESS_THREAD(rest_server_example, ev, data) { PROCESS_BEGIN(); PRINTF("Rest Example\n"); #ifdef RF_CHANNEL PRINTF("RF channel: %u\n", RF_CHANNEL); #endif #ifdef IEEE802154_PANID PRINTF("PAN ID: 0x%04X\n", IEEE802154_PANID); #endif PRINTF("uIP buffer: %u\n", UIP_BUFSIZE); PRINTF("LL header: %u\n", UIP_LLH_LEN); PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); /* if static routes are used rather than RPL */ #if !UIP_CONF_IPV6_RPL && !defined (CONTIKI_TARGET_MINIMAL_NET) set_global_address(); configure_routing(); #endif /* Initialize the REST framework. */ rest_init_framework(); /* Activate the application-specific resources. */ #if REST_RES_HELLO rest_activate_resource(&resource_helloworld); #endif #if REST_RES_MIRROR rest_activate_resource(&resource_mirror); #endif #if REST_RES_CHUNKS rest_activate_resource(&resource_chunks); #endif #if REST_RES_POLLING rest_activate_periodic_resource(&periodic_resource_polling); #endif #if defined (PLATFORM_HAS_BUTTON) && REST_RES_EVENT SENSORS_ACTIVATE(button_sensor); rest_activate_event_resource(&resource_event); #endif #if defined (PLATFORM_HAS_LEDS) #if REST_RES_LEDS rest_activate_resource(&resource_leds); #endif #if REST_RES_TOGGLE rest_activate_resource(&resource_toggle); #endif #endif /* PLATFORM_HAS_LEDS */ #if defined (PLATFORM_HAS_LIGHT) && REST_RES_LIGHT SENSORS_ACTIVATE(light_sensor); rest_activate_resource(&resource_light); #endif #if defined (PLATFORM_HAS_BATTERY) && REST_RES_BATTERY SENSORS_ACTIVATE(battery_sensor); rest_activate_resource(&resource_battery); #endif /* Define application-specific events here. */ while(1) { PROCESS_WAIT_EVENT(); #if defined (PLATFORM_HAS_BUTTON) && REST_RES_EVENT if (ev == sensors_event && data == &button_sensor) { PRINTF("BUTTON\n"); /* Call the event_handler for this application-specific event. */ event_event_handler(&resource_event); } #endif /* PLATFORM_HAS_BUTTON */ } /* while (1) */ PROCESS_END(); }