Пример #1
0
PROCESS_THREAD(rest_server_example, ev, data)
{
  PROCESS_BEGIN();

  PRINTF("Starting Erbium Example 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);

  /* Initialize the REST engine. */
  rest_init_engine();

  /* Activate the application-specific resources. */
  rest_activate_resource(&resource_helloworld);
  rest_activate_resource(&resource_leds);
  rest_activate_resource(&resource_toggle);
  leds_on(0);
  /* Define application-specific events here. */
  while(1) {
    PROCESS_WAIT_EVENT();
  } /* while (1) */

  PROCESS_END();
}
Пример #2
0
PROCESS_THREAD(rest_server_example, ev, data)
{
  PROCESS_BEGIN();

#ifdef WITH_COAP
  PRINTF("COAP Server\n");
#else
  PRINTF("HTTP Server\n");
#endif

  rest_init();

#if defined (PLATFORM_HAS_LIGHT)
  SENSORS_ACTIVATE(light_sensor);
  rest_activate_resource(&resource_light);
#endif
#if defined (PLATFORM_HAS_LEDS)
  rest_activate_resource(&resource_led);
  rest_activate_resource(&resource_toggle);
#endif /*defined (PLATFORM_HAS_LEDS)*/

  rest_activate_resource(&resource_helloworld);
  rest_activate_resource(&resource_discover);

  PROCESS_END();
}
Пример #3
0
/*defined in rplinfo.h*/
void
rplinfo_activate_resources(void) 
{
  rest_activate_resource(&parents, "rplinfo/parents");
  rest_activate_resource(&routes, "rplinfo/routes");

}
Пример #4
0
PROCESS_THREAD(rest_server_example, ev, data)
{
  PROCESS_BEGIN();
  PRINTF("Starting Erbium Example 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) && !defined (CONTIKI_TARGET_NATIVE)
  set_global_address();
  configure_routing();
#endif

  /* Initialize the OSD Hardware. */
  hw_init();
  /* Initialize the REST engine. */
  rest_init_engine();

  /* Activate the application-specific resources. */
  rest_activate_resource(&resource_info);

  SENSORS_ACTIVATE(t4_servo_sensor);
  rest_activate_resource(&resource_t4_servo);

  /* Define application-specific events here. */
  while(1) {
    PROCESS_WAIT_EVENT();
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(start_app, ev, data)
{
  PROCESS_BEGIN();
  static int is_coordinator = 0;

  memset(rx_buf, '\0', sizeof(rx_buf));
  /* Define process that handles data */
  process_start(&rx_data_process ,NULL);
  /* Initialise UART1 */
  uart1_init(UART1_BAUD_RATE); 
  /* Callback received byte */
  uart1_set_input(handleRxChar);

  /* Start network stack */
  if(is_coordinator) {
    uip_ipaddr_t prefix;
    uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    rpl_tools_init(&prefix);
  } else {
    rpl_tools_init(NULL);
  }
  printf("Starting RPL node\n");
  
  rest_init_engine();
  rest_activate_resource(&resource_coap_rx_uart1, "UART1-RX");
  rest_activate_resource(&resource_coap_tx_uart1, "UART1-TX");

  PROCESS_END();
}
Пример #6
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_server_process, ev, data)
{
  PROCESS_BEGIN();

  printf("CC26XX CoAP Server\n");

  /* Initialize the REST engine. */
  rest_init_engine();

  rest_activate_resource(&res_batmon_temp, "sen/batmon/temp");
  rest_activate_resource(&res_batmon_volt, "sen/batmon/voltage");

  rest_activate_resource(&res_device_hw, "dev/mdl/hw");
  rest_activate_resource(&res_device_sw, "dev/mdl/sw");
  rest_activate_resource(&res_device_uptime, "dev/uptime");
  rest_activate_resource(&res_device_cfg_reset, "dev/cfg_reset");

  rest_activate_resource(&res_parent_rssi, "net/parent/RSSI");
  rest_activate_resource(&res_parent_ip, "net/parent/IPv6");

#if RF_BLE_ENABLED
  rest_activate_resource(&res_ble_advd, "dev/ble_advd");
#endif

  start_board_resources();

  /* Define application-specific events here. */
  while(1) {
    PROCESS_WAIT_EVENT();
  }

  PROCESS_END();
}
Пример #7
0
void activate_coap_resources()
{
	extern resource_t
		res_hello,
		res_toggle,
		res_leds;
	
	rest_activate_resource(&res_hello, "hello");
	rest_activate_resource(&res_toggle, "leds/toggle");
	rest_activate_resource(&res_leds, "leds");

	return;
}
Пример #8
0
/*---------------------------------------------------------------------------*/
static void
start_board_resources(void) {
  rest_activate_resource(&res_hello, "test/hello");
  #ifdef SWITCH_DEVICE
  rest_activate_resource(&res_switch, "switch");
  #endif

  #ifdef LIGHT_DEVICE
  rest_activate_resource(&res_light, "light");
  #endif

  #ifdef WATER_DEVICE
  rest_activate_resource(&res_water, "water");
  #endif
}
Пример #9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(start_app, ev, data)
{
  PROCESS_BEGIN();
  static int is_coordinator = 0;

  /* Switch off dongle leds */

  /* Initialise ct timer, but don't let it run yet */
  ctimer_set(&ct, TOGGLE_TIME, ct_callback, NULL);
  ctimer_stop(&ct);

  /* Start net stack */
  if(is_coordinator) {
    uip_ipaddr_t prefix;
    uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    rpl_tools_init(&prefix);
  } else {
    rpl_tools_init(NULL);
  } printf("Starting RPL node\n");

  rest_init_engine();
  rest_activate_resource(&resource_led_toggle, "Dongle/LED-toggle");

  PROCESS_END();
}
Пример #10
0
//Reads button presses and adds to variable for LEDs
PROCESS_THREAD(authority_process, ev, data){
	PROCESS_BEGIN();
#ifdef DEBUG
	volatile unsigned int *resetreas_reg = (unsigned int*) 0x40000400;
	if(*resetreas_reg != 1){
		printf("\n Reset reason: %d \n", *resetreas_reg);
		PROCESS_WAIT_EVENT(); //This single line made things work and not crash? What is this unstable hell-machine?
	}

	*resetreas_reg = 0xF00F;
#endif
	rest_init_engine();
	

#if WITH_IPSO
	ipso_objects_init();
#endif
  	rest_activate_resource(&res_door, "doors/door");
	while(1){
		PROCESS_WAIT_EVENT();
		//wait for requests and process data
	}

	PROCESS_END();
}
Пример #11
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_engine, ev, data)
{
  PROCESS_BEGIN();
  PRINTF("Starting %s receiver...\n", coap_rest_implementation.name);

#if WITH_WELL_KNOWN_CORE
  rest_activate_resource(&res_well_known_core, ".well-known/core");
#endif

  coap_register_as_transaction_handler();
  coap_init_connection(SERVER_LISTEN_PORT);

  while(1) {
    PROCESS_YIELD();

    if(ev == tcpip_event) {
      coap_handle_receive(coap_default_context);
    } else if(ev == PROCESS_EVENT_TIMER) {
      /* retransmissions are handled here */
      coap_check_transactions();
    }
  } /* while (1) */

  PROCESS_END();
}
Пример #12
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coap_engine, ev, data, buf)
{
  PROCESS_BEGIN();
#if 0
  /* This is not used in Zephyr. */
  PRINTF("Starting %s receiver...\n", coap_rest_implementation.name);

  rest_activate_resource(&res_well_known_core, ".well-known/core");

  coap_register_as_transaction_handler();
  coap_init_connection(SERVER_LISTEN_PORT);

  while(1) {
    PROCESS_YIELD();

    if(ev == tcpip_event) {
      coap_engine_receive(COAP_CONTEXT_NONE);

    } else if(ev == PROCESS_EVENT_TIMER) {
      /* retransmissions are handled here */
      coap_check_transactions();
    }
  } /* while (1) */
#endif /* 0 */
  PROCESS_END();
}
Пример #13
0
/*----------------------------------------------------------------------------*/
PROCESS_THREAD(coap_receiver, ev, data)
{
  PROCESS_BEGIN();
  PRINTF("Starting CoAP-13 receiver...\n");

  rest_activate_resource(&resource_well_known_core);

#if ! COAP_CEU
  coap_register_as_transaction_handler();
#endif

  coap_init_connection(SERVER_LISTEN_PORT);

  while(1) {
    PROCESS_YIELD();

    if(ev == tcpip_event) {
      coap_receive();
    } else if (ev == PROCESS_EVENT_TIMER) {
      /* retransmissions are handled here */
#if ! COAP_CEU
      coap_check_transactions();
#endif
    }
  } /* while (1) */

  PROCESS_END();
}
Пример #14
0
void
rest_activate_periodic_resource(periodic_resource_t* periodic_resource)
{
  list_add(restful_periodic_services, periodic_resource);
  rest_activate_resource(periodic_resource->resource);

  rest_set_post_handler(periodic_resource->resource, REST.subscription_handler);
}
Пример #15
0
PROCESS_THREAD(rest_example, ev, data)
{
  PROCESS_BEGIN();
  
  /*start the http server*/
  process_start(&httpdProcess, NULL);
  /*Init the restful api*/
  rest_init();
  
  /*Resources should be activated*/
  rest_activate_resource( &resource_helloworld );
  rest_activate_resource( &resource_service );
  rest_activate_resource( &resource_ledControl );
  rest_activate_resource( &resource_configure );
  
  PROCESS_END();
}
Пример #16
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(server, ev, data)
{
  PROCESS_BEGIN();
  SENSORS_ACTIVATE(button_sensor);
  rest_init_engine();
  rest_activate_resource(&resource_example, "example");
  rest_activate_resource(&resource_per, "periodic");
  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == sensors_event && data == &button_sensor){
    	//leds_toggle(LEDS_ALL);
    	printf("Button pressed\n");
	resource_example.trigger();
    }
  }
  PROCESS_END();
}
Пример #17
0
PROCESS_THREAD(flexibity_buzzer, ev, data)
{
  PROCESS_BEGIN();
  SENSORS_ACTIVATE(button_sensor);
  SENSORS_ACTIVATE(battery_sensor);

  /* PWM for buzzer */
  pwm_init_stopped(TMR3, 1500, 10000);

#ifdef WITH_COAP
  PRINTF("COAP Server\n");
#else
  PRINTF("HTTP Server\n");
#endif

  rest_init();

#if DEBUG
  rest_activate_resource(&resource_mem);
#endif
  rest_activate_resource(&resource_buzzer);
  rest_activate_resource(&resource_pwr);
  rest_activate_resource(&resource_led);
  rest_activate_resource(&resource_button);
  rest_activate_resource(&resource_id);
  rest_activate_resource(&resource_discover);

  PROCESS_END();
}
Пример #18
0
/*----------------------------------------------------------------------------*/
PROCESS_THREAD(tres_process, ev, data)
{
    PROCESS_BEGIN();

    srand(node_id);
    rest_init_engine();
    tres_init();
    rest_activate_resource(&actuator, "actuator");
    rplinfo_activate_resources();
    sprintf(setpoint, "0");
#if PYOT_KEEPALIVE
    static coap_packet_t request[1]; /* This way the packet can be treated as pointer as usual. */
    SERVER_NODE(&server_ipaddr);

    int wait_time = (unsigned int)(rand() % 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();
        //PROCESS_WAIT_EVENT();
        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, "/rd");
            coap_set_payload(request, content, snprintf(content, sizeof(content), "%d", g_time++));
            //PRINT6ADDR(&server_ipaddr);
            //PRINTF(" : %u\n", UIP_HTONS(REMOTE_PORT));

            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) */
#endif
    PROCESS_END();
}
Пример #19
0
PROCESS_THREAD(rest_server_example, ev, data)
{
  PROCESS_BEGIN();
  PRINTF("Starting Erbium Example 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 OSD Hardware. */
  hw_init();
  /* Initialize the REST engine. */
  rest_init_engine();

  /* Activate the application-specific resources. */
  rest_activate_resource(&resource_info);
  rest_activate_resource(&resource_led_pwm);

  /* Define application-specific events here. */
  while(1) {
    PROCESS_WAIT_EVENT();
  } /* while (1) */

  PROCESS_END();
}
Пример #20
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(start_app, ev, data)
{
  PROCESS_BEGIN();
  static int is_coordinator = 0;
 
  /* Start network stack */
  if(is_coordinator) {
    uip_ipaddr_t prefix;
    uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0);
    rpl_tools_init(&prefix);
  } else {
    rpl_tools_init(NULL);
  }
  printf("Starting RPL node\n");
  
  rest_init_engine();
  rest_activate_resource(&resource_set_tx_power, "Set-TX-Power");
  rest_activate_resource(&resource_get_tx_power, "Get-TX-Power");

  PROCESS_END();
}
Пример #21
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(start_app, ev, data)
{
  PROCESS_BEGIN();
  static int is_coordinator = 0;
 
  /* Start RICH stack */
  if(is_coordinator) {
    uip_ipaddr_t prefix;
    uip_ip6addr(&prefix, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
    rich_init(&prefix);
  } else {
    rich_init(NULL);
  }
  printf("Starting RPL node\n");
  
  rest_init_engine();
  rest_activate_resource(&resource_set_tx_power, "Set-TX-Power");
  rest_activate_resource(&resource_get_tx_power, "Get-TX-Power");

  PROCESS_END();
}
Пример #22
0
int8_t demo_coapInit(void)
{

//    LOG_INFO("%s\n\r","Starting CoAP Example Server");

    /* Initialize the REST engine. */
    rest_init_engine();

/*
* Bind the resources to their Uri-Path.
* WARNING: Activating twice only means alternatle path, not two instances!
* All static variables are the same for each URI path.
*/
    rest_activate_resource(&res_temp, "sensors/temperature");
    rest_activate_resource(&res_push, "test/push");
    rest_activate_resource(&res_toggle, "actuators/LED");
    rest_activate_resource(&res_led_toggle, "actuators/LED_toggle");
    rest_activate_resource(&res_rf_info, "status/rf_info");

    return 1;
}
Пример #23
0
coap_context_t *coap_init_server(uip_ipaddr_t *server_addr,
				 uint16_t server_port,
				 uip_ipaddr_t *peer_addr,
				 uint16_t peer_port)
{
  PRINTF("Starting %s receiver...\n", coap_rest_implementation.name);

  rest_activate_resource(&res_well_known_core, ".well-known/core");

  coap_register_as_transaction_handler();
  return coap_init_connection(server_addr, server_port, peer_addr, peer_port);
}
int coap_RegisterUri(const char * uri)
{
    resource_t * temp = malloc(sizeof(resource_t));
    char * uriCopy = strdup(&uri[1]);

    Lwm2m_Debug("register %s\n", uriCopy);

    memcpy(temp, &rest_resource_template, sizeof(resource_t));

    rest_activate_resource(temp, uriCopy);

    return 0;
}
Пример #25
0
/*---------------------------PROCESS COAP SERVER--------------------------------------*/
PROCESS_THREAD(coap_server, ev, data)
{

  PROCESS_BEGIN();

  PROCESS_PAUSE();

  PRINTF("Starting Erbium 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);

  /* Initialize the REST engine. */
  rest_init_engine();

  /*
   * Bind the resources to their Uri-Path.
   * WARNING: Activating twice only means alternate path, not two instances!
   * All static variables are the same for each URI path.
   */

  rest_activate_resource(&res_event, "test/event");
#if PLATFORM_HAS_BUTTON
  SENSORS_ACTIVATE(button_sensor);
#endif

  /* Define application-specific events here. */
  while(1) {
    PROCESS_WAIT_EVENT();
#if PLATFORM_HAS_BUTTON
    if(ev == sensors_event && data == &button_sensor) {
      PRINTF("*******BUTTON*******\n");

      /* Call the event_handler for this application-specific event. */
      //      res_event.trigger();
    }
#endif /* PLATFORM_HAS_BUTTON */

  } /* while (1) */

  PROCESS_END();
}
Пример #26
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(border_router_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();

/* While waiting for the prefix to be sent through the SLIP connection, the future
 * border router can join an existing DAG as a parent or child, or acquire a default
 * router that will later take precedence over the SLIP fallback interface.
 * Prevent that by turning the radio off until we are initialized as a DAG root.
 */
  prefix_set = 0;

  PROCESS_PAUSE();

  PRINTF("RPL-Border router started\n");

  /* Request prefix until it has been received */
  while(!prefix_set) {
    etimer_set(&et, CLOCK_SECOND);
    request_prefix();
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    PRINTF("Waiting for prefix\n");
  }

  PRINTF("Obtained prefix: ");
  uip_debug_ipaddr_print(&prefix);
  PRINTF("\n");

  rpl_tools_init(&prefix);

  rest_init_engine();
  rest_activate_resource(&resource_get_rssi, "Get-RSSI");
  rest_activate_resource(&resource_get_last_rssi, "Get-Last-RSSI");


  PROCESS_END();
}
Пример #27
0
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();
}
Пример #28
0
PROCESS_THREAD(rest_server_example, ev, data)
{
  PROCESS_BEGIN();

  PRINTF("Starting Erbium Example 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);

  /* Initialize the REST engine. */
  rest_init_engine();

  /* Activate the application-specific resources. */
  rest_activate_resource(&helloworld, "hello");
  /* Define application-specific events here. */
  while(1) {
    PROCESS_WAIT_EVENT();
  } /* while (1) */

  PROCESS_END();
}
Пример #29
0
/*---------------------------------------------------------------------------*/
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();
}
Пример #30
0
PROCESS_THREAD(poti, ev, data)
{

  static struct etimer loop_timer;
  PROCESS_BEGIN();

  /* Initialize the REST engine. */
  rest_init_engine ();
  SERVER_NODE (&server_ipaddr);
  adc_init ();

  /* Activate the application-specific resources. */
#if PLATFORM_HAS_BATTERY
  SENSORS_ACTIVATE(battery_sensor);
  rest_activate_resource (&res_battery,         "s/battery");
#endif
  rest_activate_resource (&res_server_ip,       "poti/ip");
  rest_activate_resource (&res_server_resource, "poti/resource");
  rest_activate_resource (&res_interval,        "poti/interval");

  etimer_set (&loop_timer, LOOP_INTERVAL);
  /* Define application-specific events here. */
  while(1) {
    static int count = 0;
    static int lastval = -1;
    static coap_packet_t request [1]; /* Array: treat as pointer */
    uint8_t val = 127;

    PROCESS_WAIT_EVENT();
    if (etimer_expired (&loop_timer)) {
        uint16_t sum = 0;
        int i;
        count++;
        adc_setup (ADC_DEFAULT, A5);
        for (i=0; i<5; i++) {
            sum += adc_read ();
            clock_delay_usec (50);
        }
        adc_fin ();
        val = (sum / 5) >> 2;
        if ((interval > 0 && count > interval) || (val != lastval)) {
            char buf [4];
            coap_transaction_t *transaction;

            sprintf (buf, "%d", val);
            lastval = val;
            printf ("Sending Value: %s\n", buf);
            coap_init_message (request, COAP_TYPE_NON, COAP_PUT, 0);
            coap_set_header_uri_path (request, server_resource);
            coap_set_header_content_format (request, REST.type.TEXT_PLAIN);
            coap_set_payload (request, buf, strlen (buf));
            request->mid = coap_get_mid ();
            transaction = coap_new_transaction
                (request->mid, &server_ipaddr, REMOTE_PORT);
            transaction->packet_len = coap_serialize_message
                (request, transaction->packet);
            coap_send_transaction (transaction);
            count = 0;
        }
        etimer_reset (&loop_timer);
    }
  } /* while (1) */