Exemple #1
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(receiver_node_process, ev, data)
{
  static struct etimer et;
  static struct uip_ds6_notification n;
  uip_ipaddr_t *ipaddr;

  PROCESS_BEGIN();

  ipaddr = set_global_address();

  uip_ds6_notification_add(&n, route_callback);

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  etimer_set(&et, CLOCK_SECOND);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    etimer_reset(&et);
    if(should_blink) {
      leds_on(LEDS_ALL);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
      etimer_reset(&et);
      leds_off(LEDS_ALL);
    }
  }
  PROCESS_END();
}
Exemple #2
0
PROCESS_THREAD(server_process, ev, data)
{
  PROCESS_BEGIN();

  set_global_address();
  leds_init();
  print_local_addresses();
  printf("Starting TCP server on port=%d\n", PORT);
  tcp_listen(UIP_HTONS(PORT));

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);

    if(uip_aborted() )
	printf("TCP aborted\n");
    if(uip_timedout() )
	printf("TCP timeoutn\n");
    if(uip_closed() )
	printf("TCP closed\n");

    if(uip_connected()) {
      printf("TCP Connected\n\r");
      PSOCK_INIT(&ps, buf, sizeof(buf));

      while(!(uip_aborted() || uip_closed() || uip_timedout())) {
	PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
	handle_connection(&ps);
      }
    }
  }
  PROCESS_END();
}
Exemple #3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;
#if WITH_COMPOWER
  static int print = 0;
#endif

  PROCESS_BEGIN();

  PROCESS_PAUSE();

  set_global_address();
  
  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
  if(client_conn == NULL) {
    PRINTF("No UDP connection available, exiting the process!\n");
    PROCESS_EXIT();
  }
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

#if WITH_COMPOWER
  powertrace_sniff(POWERTRACE_ON);
#endif

  etimer_set(&periodic, SEND_INTERVAL);
  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
    
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);

#if WITH_COMPOWER
      if (print == 0) {
	powertrace_print("#P");
      }
      if (++print == 3) {
	print = 0;
      }
#endif

    }
  }

  PROCESS_END();
}
/*-----------------------------------------------------------------------*/
PROCESS_THREAD(udp_sender_process, ev, data)
{
	static struct etimer period_timer, wait_timer;
	PROCESS_BEGIN();
	
	set_global_address();
	PRINTF("UDP sender process started\n");
	print_local_address();

	/* new connection with remote host */
	sender_conn = udp_new(NULL, UIP_HTONS(UDP_SINK_PORT), NULL);
	udp_bind(sender_conn, UIP_HTONS(UDP_SENDER_PORT));

	PRINTF("Created a connection with the sink ");
	PRINT6ADDR(&sender_conn->ripaddr);
	PRINTF(" local/remote port %u/%u\n",
			UIP_HTONS(sender_conn->lport), UIP_HTONS(sender_conn->rport));
	
	etimer_set(&period_timer, CLOCK_SECOND * PERIOD);
	while(1) {
		PROCESS_WAIT_EVENT();
		if(ev == PROCESS_EVENT_TIMER) {
			if(data == &period_timer) {
				etimer_reset(&period_timer);
				etimer_set(&wait_timer,
							random_rand() % (CLOCK_SECOND * RANDWAIT));
			} else if(data ==&wait_timer) {
				/* Time to send a data. */
				collect_common_send();
			}
		}
	}
	PROCESS_END();
}
Exemple #5
0
/*---------------------------------------------------------------------------*/
void
simple_rpl_init(void)
{
  to_become_root = 0;
  set_global_address();
  uip_ds6_notification_add(&n, route_callback);
}
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(otau_client_process, ev, data)
{
  static struct etimer server_timer;
  uip_ip6addr_t *srv_addr;
  
  PROCESS_BEGIN();
  servreg_hack_init();
  set_global_address();
  
  ota_mgr_init();
  
  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);
  etimer_set(&server_timer, SEND_INTERVAL);					  

  while(1) {
	PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&server_timer));
	srv_addr = servreg_hack_lookup(SERVICE_ID);
	if(srv_addr != NULL) {
		printf("Server address configured\r\n");
		server_configured =1;
		configure_server_details(srv_addr);
		memcpy((uint8_t *)&(global_server_addr.u16[4]),&(srv_addr->u16[4]),NATIVE_ADDR_SIZE);
        //uip_create_linklocal_allnodes_mcast(srv_addr);
		etimer_stop(&server_timer);
	}
	else
	{
		etimer_reset(&server_timer);
		printf("server not found\r\n");
	}
  }
  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  PROCESS_BEGIN();

  PROCESS_PAUSE();

  set_global_address();

  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
        UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udpstream_process, ev, data)
{
  static uint16_t streamno;
  static struct etimer et;
  static uip_ipaddr_t *ipaddr;

  PROCESS_BEGIN();
  PROCESS_PAUSE();

  printf("Formatting Coffee FS...\n");
  cfs_coffee_format();
  printf("done.\n");
  /* We need re-initialize queuebuf after formatting */
  queuebuf_init();

  /* Start service registration */
  servreg_hack_init();
  ipaddr = set_global_address();

  if(node_id == SINK_ID) {
    /* The sink creates a dag and waits for UDP datagrams */
    create_rpl_dag(ipaddr);
    servreg_hack_register(SERVICE_ID, ipaddr);
    simple_udp_register(&unicast_connection, UDP_PORT,
                        NULL, UDP_PORT, receiver);
    while(1) {
      PROCESS_WAIT_EVENT();
    }
  } else if(node_id == SENDER_ID) {
    /* The sender looks for the sink and sends UDP streams */
    ipaddr = NULL;
    simple_udp_register(&unicast_connection, UDP_PORT,
                          NULL, UDP_PORT, receiver);

    etimer_set(&et, 10*CLOCK_SECOND);
    etimer_restart(&et);

    while(1) {
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
      if(ipaddr != NULL) {
        streamno++;
        send_stream(ipaddr, streamno);
      } else {
        ipaddr = servreg_hack_lookup(SERVICE_ID);
        if(ipaddr != NULL) {
          etimer_set(&et, 2*CLOCK_SECOND);
          printf("Streaming to ");
          uip_debug_ipaddr_print(ipaddr);
          printf("\n");
        } else {
          printf("Service %d not found\n", SERVICE_ID);
        }
      }
      etimer_restart(&et);
    }
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;

  uip_ipaddr_t *addr;

  PROCESS_BEGIN();

  SENSORS_ACTIVATE(button_sensor);
 // SENSORS_ACTIVATE(light_sensor);

  servreg_hack_init();

  set_global_address();

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  //etimer_set(&periodic_timer, SEND_INTERVAL);
  while(1) {

   // PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);
   // etimer_reset(&periodic_timer);
    etimer_set(&send_timer, SEND_TIME);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
    addr = servreg_hack_lookup(SERVICE_ID);

    if(addr != NULL) {
      static unsigned int button_number;
      char buf[50];

      if(button_number == 0) {
	button_number = 1;
	leds_toggle(LEDS_ALL);
      } else {
	button_number = 0;
	leds_toggle(LEDS_ALL);
      }

      printf("Sending unicast to ");
      uip_debug_ipaddr_print(addr);
      printf("\n");

      //sprintf(buf, "Occupancy Detector: %d, Luminaire Illuminance: %d", button_number, LUMINAIRE_ILLUMINANCE);
      sprintf(buf, "Occupancy Detector: %d, Luminaire Illuminance: %d", button_number, (int)(410 ));      

      simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr);
    } else {
      printf("Service %d not found\n", SERVICE_ID);
    }
  }

  PROCESS_END();
}
Exemple #11
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et, wake_timer, periodic_timer;
  uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();
  PRINTF("UDP client process started\n");

#if UIP_CONF_ROUTER
  set_global_address();
#endif

  print_local_addresses();

  set_connection_address(&ipaddr);

  /* new connection with remote host */
  client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
  udp_bind(client_conn, UIP_HTONS(3001));

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  etimer_set(&et, CLOCK_SECOND*10);
  PROCESS_WAIT_UNTIL(etimer_expired(&et)); // Wait for DAD and Router Discovery procedure to end.

  etimer_set(&et, SEND_INTERVAL);
  etimer_set(&wake_timer, AWAKE_INTERVAL);
  etimer_set(&periodic_timer, 1);

  while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&wake_timer)){  // if timer hasn't expired do not go in deep sleep, in order to receive a response.
		printf("Sleeping...\r\n");
		sensorsPowerDown();
		sleep_seconds(SLEEP_INTERVAL_SECONDS); // Put system in deep sleep mode for a while.
		sensorsPowerUp();
		printf("Awake\r\n");
    }
    if(etimer_expired(&et)) {
      timeout_handler();
      etimer_restart(&et);
      etimer_restart(&wake_timer);
    } else if(ev == tcpip_event) {
      tcpip_handler();
    }

    /* Make the process be called almost immediately,
     * so that it can force the system to go into deep sleep. */
    etimer_restart(&periodic_timer);
  }

  PROCESS_END();
}
Exemple #12
0
/*--------------------------------------------------------*/
void udp_client_process(void){
     
/******************** lock the Scheduler ************************/
      cyg_scheduler_lock();
/****************************************************************/
        static struct ctimer backoff_timer;
 
	 PRINTF("UDP client started\n");
	 
         set_global_address();   
	 
	 
	 print_local_addresses();
	 
	  

     client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
 

     udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));
     PRINTF("Created a connection with the server ");
     PRINT6ADDR(&client_conn->ripaddr);
     PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

     ctimer_set(&backoff_timer,SEND_TIME,send_packet,NULL);
	 
//      PRINTF(" local/remote port %u/%u\n", client_conn->lport, client_conn->rport);
	 
	        void* message = NULL;
                
                 
/******************** unlock the Scheduler ************************/
        cyg_scheduler_unlock();
/****************************************************************/
          while(1){
                    // cyg_thread_yield();

		     message = cyg_mbox_tryget (mbox_out_tcpip_handle);
		     MyEvent_t* msg_local = message ;
			 if (  message != NULL){ 
                              cyg_handle_t* event_handlePtr;
                              event_handlePtr = (cyg_handle_t*) msg_local-> dataPtr;

                              if( cyg_thread_self() == *event_handlePtr){
			 
			                            tcpip_handler();
			                    }
 
 
		
		
                             }
                          cyg_thread_yield();
                     }
}
Exemple #13
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(tcp_client_process, ev, data)
{
  static struct etimer et;

  PROCESS_BEGIN();

  PRINTF("TCP client process started\n");

  process_start(&adjust_packet_length_process, 0);

#if UIP_CONF_ROUTER
  set_global_address();
#endif

  print_local_addresses();

  /* Fill buffer with test data */
  for (int i = 0; i < MAX_PAYLOAD_LEN; i++) {
    buf[i] = i;
  }

  static resolv_status_t status = RESOLV_STATUS_UNCACHED;
  while(status != RESOLV_STATUS_CACHED) {
    status = set_connection_address(&ipaddr);

    if(status == RESOLV_STATUS_RESOLVING) {
      PROCESS_WAIT_EVENT_UNTIL(ev == resolv_event_found);
    } else if(status != RESOLV_STATUS_CACHED) {
      PRINTF("Can't get connection address.\n");
      PROCESS_YIELD();
    }
  }

  /* new connection with remote host */
  tcp_socket_register(&socket, NULL,
                        inputbuf, sizeof(inputbuf),
                        outputbuf, sizeof(outputbuf),
                        input, event);
  tcp_socket_connect(&socket, &ipaddr, SERVER_PORT);

  PRINTF("Connecting with the server...");
  PRINT6ADDR(&ipaddr);
  PRINTF("\n");

  while(1) {
    etimer_set(&et, send_interval);
    PROCESS_YIELD();
    if(etimer_expired(&et)) {
      timeout_handler();
    }
  }

  PROCESS_END();
}
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();
}
Exemple #15
0
/*---------------------------------------------------------------------------*/
void
rpl_dag_root_init(void)
{
  static uint8_t initialized = 0;

  if(!initialized) {
    to_become_root = 0;
    set_global_address();
    uip_ds6_notification_add(&n, route_callback);
    initialized = 1;
  }
}
Exemple #16
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;


  PROCESS_BEGIN();

  /* Start powertracing, once every 60 seconds. */
  //powertrace_start(CLOCK_SECOND * 60);

  PROCESS_PAUSE();

  set_global_address();
  
  PRINTF("UDP Client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
  if(client_conn == NULL) {
    PRINTF("No UDP connection available, exiting the process!\n");
    PROCESS_EXIT();
  }

  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF("\nlocal/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  etimer_set(&periodic, SEND_INTERVAL);

  while(1) {

    PROCESS_YIELD();

    if(ev == tcpip_event) {
      tcpip_handler();
    }
    
    // send sensor data to root periodically.
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);

    }
  }

  PROCESS_END();
}
Exemple #17
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;
  uip_ipaddr_t ipaddr;
  int port = 3000; /* Default to 3000 if not using service discovery. */

  PROCESS_BEGIN();
  PRINTF("UDP client process started\n");

#if UIP_CONF_ROUTER
  set_global_address();
#endif

  print_local_addresses();

  static resolv_status_t status = RESOLV_STATUS_UNCACHED;
  while(status != RESOLV_STATUS_CACHED) {
#if RESOLV_CONF_SUPPORTS_MDNS && RESOLV_CONF_SUPPORTS_DNS_SD
    status = set_connection_address(&ipaddr, &port);
#else
    status = set_connection_address(&ipaddr, NULL);
#endif

    if(status == RESOLV_STATUS_RESOLVING) {
      PROCESS_WAIT_EVENT_UNTIL(ev == resolv_event_found);
    } else if(status != RESOLV_STATUS_CACHED) {
      PRINTF("Can't get connection address.\n");
      PROCESS_YIELD();
    }
  }

  /* new connection with remote host */
  client_conn = udp_new(&ipaddr, UIP_HTONS(port), NULL);
  udp_bind(client_conn, UIP_HTONS(port + 1));

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  etimer_set(&et, SEND_INTERVAL);
  while(1) {
    PROCESS_YIELD();
    if(etimer_expired(&et)) {
      timeout_handler();
      etimer_restart(&et);
    } else if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Exemple #18
0
/*---------------------------------------------------------------------------*/
void
rpl_dag_root_init(void)
{
  static uint8_t initialized = 0;

  if(!initialized) {
    to_become_root = 0;
    set_global_address();
#if (UIP_CONF_MAX_ROUTES != 0)
    uip_ds6_notification_add(&n, route_callback);
#endif /* (UIP_CONF_MAX_ROUTES != 0) */
    initialized = 1;
  }
}
Exemple #19
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_receiver_process, ev, data)
{
  uip_ipaddr_t *ipaddr;

  PROCESS_BEGIN();

  ipaddr = set_global_address();

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  while(1) {
    PROCESS_WAIT_EVENT();
  }
  PROCESS_END();
}
Exemple #20
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_sender_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t *addr;

  PROCESS_BEGIN();

  servreg_hack_init();

  set_global_address();

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  etimer_set(&periodic_timer, SEND_INTERVAL);
  while(1) {

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_reset(&periodic_timer);
    etimer_set(&send_timer, SEND_TIME);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));
	PRINTF("SIMPLE_UNICAST_SENDER: Unicast attempt!\n");
    addr = servreg_hack_lookup(SERVICE_ID);
	
    if(addr != NULL) {
      static unsigned int message_number;
      char buf[20];

      printf("Sending unicast to ");
      uip_debug_ipaddr_print(addr);
      printf(" \n");
      sprintf(buf, "Message %d", message_number);
      message_number++;
      simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, addr);
    } else {
      printf("Service %d not found\n", SERVICE_ID);
    }
  }

  PROCESS_END();
}
Exemple #21
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;
  uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();
  PRINTF("UDP client process started\n");

#if UIP_CONF_ROUTER
  set_global_address();
#endif

  print_local_addresses();

  set_connection_address(&ipaddr);

  /* new connection with remote host */
  SENSORS_ACTIVATE(button_sensor);//activate button
  //client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
   simple_udp_register(&udp_connection, UDP_PORT, NULL, UDP_PORT,    receiver);
 // udp_bind(client_conn, UIP_HTONS(3001));

  //PRINTF("Created a connection with the server ");
 // PRINT6ADDR(&client_conn->ripaddr);
 // PRINTF(" local/remote port %u/%u\n",
//	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

 // etimer_set(&et, SEND_INTERVAL);
  while(1) {
    //PROCESS_YIELD();
    PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event && data == &button_sensor);

   // if(etimer_expired(&et)) {
      timeout_handler();
    //  etimer_restart(&et);
    //} else 
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
PROCESS_THREAD(sender_process, ev, data)
{
    
    static struct etimer periodic;
    static struct ctimer backoff_timer;

    PROCESS_BEGIN();

//    PROCESS_PAUSE();

    set_global_address();
    
    PRINTF("The sender process begins.\n");
    
    print_local_addresses();
    /* new connection with remote host */
    sender_conn = udp_new(NULL, UIP_HTONS(UDP_SINK_PORT), NULL);
    if(sender_conn == NULL)
    {
        PRINTF("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(sender_conn, UIP_HTONS(UDP_SENDER_PORT));
    PRINTF("Created a connection with the server ");
    PRINT6ADDR(&sender_conn->ripaddr);
    PRINTF(" local/remote port %u/%u\n", UIP_HTONS(sender_conn->lport),
                UIP_HTONS(sender_conn->rport));

    etimer_set(&periodic, SEND_INTERVAL * CLOCK_SECOND);
    while(1) {
        PROCESS_YIELD();
        if(ev == tcpip_event)
          tcpip_handler();

        if(etimer_expired(&periodic))
        {
            etimer_reset(&periodic);
            ctimer_set(&backoff_timer, RANDWAIT * CLOCK_SECOND, send_packet, NULL);
        }
    }

    PROCESS_END();
}
Exemple #23
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;
  uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();
  PRINTF("UDP client process started\n");

#if UIP_CONF_ROUTER
  set_global_address();
#endif

  print_local_addresses();

  set_connection_address(&ipaddr);

  /* new connection with remote host */
  client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
  udp_bind(client_conn, UIP_HTONS(3001));

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
         UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  etimer_set(&et, SEND_INTERVAL);
  while(1)
  {
    PROCESS_YIELD();
    if(etimer_expired(&et))
    {
      timeout_handler();
      etimer_restart(&et);
    }
    else if(ev == tcpip_event)
    {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
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();
}
Exemple #25
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  PROCESS_BEGIN();

  PROCESS_PAUSE();

  set_global_address();

  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));

  /* One socket to act as sever */
  server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);
  udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
        UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));
  
  /* Starting of the node is anonymous */
  /* user with the help of serial command line argument set the region of the node */
  region = ANONYMOUS;
  /* number of neighbor in the starting is always zero */
  cur_nbr = 0;

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(unicast_receiver_process, ev, data)
{
  uip_ipaddr_t *ipaddr;

  PROCESS_BEGIN();

  servreg_hack_init();

  ipaddr = set_global_address();

  create_rpl_dag(ipaddr);

  servreg_hack_register(SERVICE_ID, ipaddr);

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  while(1) {
    PROCESS_WAIT_EVENT();
  }
  PROCESS_END();
}
Exemple #27
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sender_node_process, ev, data)
{
  static struct etimer periodic_timer;
  static struct etimer send_timer;
  uip_ipaddr_t addr;

  PROCESS_BEGIN();

  set_global_address();

  simple_udp_register(&unicast_connection, UDP_PORT,
                      NULL, UDP_PORT, receiver);

  etimer_set(&periodic_timer, SEND_INTERVAL);
  while(1) {

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
    etimer_reset(&periodic_timer);
    etimer_set(&send_timer, SEND_TIME);

    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&send_timer));

    uip_ip6addr(&addr, 0xaaaa, 0, 0, 0, 0x0201, 0x001, 0x001, 0x001);

    {
      static unsigned int message_number;
      char buf[20];

      printf("Sending unicast to ");
      uip_debug_ipaddr_print(&addr);
      printf("\n");
      sprintf(buf, "Message %d", message_number);
      message_number++;
      simple_udp_sendto(&unicast_connection, buf, strlen(buf) + 1, &addr);
    }
  }

  PROCESS_END();
}
Exemple #28
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;

  PROCESS_BEGIN();

  PROCESS_PAUSE();

  set_global_address();
  
  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  etimer_set(&periodic, SEND_INTERVAL);
  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
    
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);
    }
  }

  PROCESS_END();
}
Exemple #29
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;
  PROCESS_BEGIN();
  /* Start powertracing, once every two seconds. */
  //powertrace_start(CLOCK_SECOND * 30);

  PROCESS_PAUSE();

  set_global_address();

  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));

  /* for sending data */
  etimer_set(&periodic, SEND_INTERVAL);

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
    /*Changed*/
    /*Set interval for send critical packet*/ 
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);

    }
  }

  PROCESS_END();
}
Exemple #30
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;
#if WITH_COMPOWER
  static int print = 0;
#endif

  PROCESS_BEGIN();

  PROCESS_PAUSE();

  SENSORS_ACTIVATE(button_sensor);

  set_global_address();
  
  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
  if(client_conn == NULL) {
    PRINTF("No UDP connection available, exiting the process!\n");
    PROCESS_EXIT();
  }
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
	UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

#if WITH_COMPOWER
  powertrace_sniff(POWERTRACE_ON);
#endif

  etimer_set(&periodic, SEND_INTERVAL);
  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
else if (ev == sensors_event && data == &button_sensor) {
    	PRINTF("Erase keys\n");
    	xmem_erase(XMEM_ERASE_UNIT_SIZE, MAC_SECURITY_DATA);
    	watchdog_reboot();

//    	uint8_t i;
//    	for(i=0; i<16; i++) {temp_sec_device_list[i+16] = 8;}
//    	temp_sec_device_list[15] = 2;
//    	temp_sec_device_list[32] = 1;
//    	for(i=0; i<16; i++) {temp_sec_device_list[i+49] = 9;}
//    	temp_sec_device_list[48] = 3;
//    	temp_sec_device_list[65] = 4;
//
//
//    	PRINTF("App mem set\n");
//    	xmem_erase(XMEM_ERASE_UNIT_SIZE, APP_SECURITY_DATA);
//    	xmem_pwrite(temp_sec_device_list, 66, APP_SECURITY_DATA);
    }
    
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);

#if WITH_COMPOWER
      if (print == 0) {
	powertrace_print("#P");
      }
      if (++print == 3) {
	print = 0;
      }
#endif

    }
  }

  PROCESS_END();
}