PROCESS_THREAD(udpsend_process, ev, data) { static struct etimer etimer; static struct uip_udp_conn *c; PROCESS_EXITHANDLER(goto exit); PROCESS_BEGIN(); printf("udpsend_process starting\n"); { uip_ipaddr_t addr; uip_ipaddr(&addr, 255,255,255,255); /* Change address here! */ c = udp_new(&addr, UIP_HTONS(4321), NULL); c->ttl = 1; /* One hop only. */ } while(1) { etimer_set(&etimer, CLOCK_SECOND); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer)); tcpip_poll_udp(c); PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event); char buf[64]; sprintf(buf, "light sensors %d %d", sensors_light1(), sensors_light2()); uip_send(buf, strlen(buf) + 1); } exit: /* Contiki does automatic garbage collection of uIP state and we * need not worry about that. */ printf("udpsend_process exiting\n"); PROCESS_END(); }
void callback(char name[],void * data){ uint16_t *d = data; *d = sensors_light2(); printf(">>SENSOR APP: %d\n", *d); }