Network Kernel Architectures and Implementation (01204423) Sensor Node Programming II (UART and Radio)
Chaiporn Jaikaeo chaiporn.j@ku.ac.th Department of Computer Engineering Kasetsart University
(01204423) Sensor Node Programming II (UART and Radio) Chaiporn - - PowerPoint PPT Presentation
Network Kernel Architectures and Implementation (01204423) Sensor Node Programming II (UART and Radio) Chaiporn Jaikaeo chaiporn.j@ku.ac.th Department of Computer Engineering Kasetsart University Outline UART communication Single-hop
Chaiporn Jaikaeo chaiporn.j@ku.ac.th Department of Computer Engineering Kasetsart University
2
3
3.3V 5V RX TX GND
USB Dongle based on Silicon Labs’s CP2102 ThaiEasyElec’s USB Dongle (FDTI)
3.3V RX TX GND
4
uartEnable(true,true); uint8_t buf[10]; : uartWrite(buf, 10); uartWriteByte(50);
5
uint8_t byte = uartReadByte(); #include <stdio.h> : : printf("Hello, world\n"); printf("i = %d\n", i); if (uartInputLen() > 0) ...
6
$ dmesg : [70063.712091] usb 4-1: new low speed USB device using uhci_hcd and .. [70063.871042] usb 4-1: config 1 interface 1 altsetting .. [70063.871056] usb 4-1: config 1 interface 1 altsetting .. [70063.895220] cdc_acm 4-1:1.0: ttyACM0: USB ACM device
7
$ make UART_VIA_USB=1 ...
8
#include <stdio.h> #include <motelib/system.h> #include <motelib/timer.h> #include <motelib/uart.h> #include <motelib/sensor.h> #include <motelib/actor.h> Timer t; void senseDone(uint16_t value); void sense(Timer *t); void boot() { uartEnable(true,true); timerCreate(&t); timerStart(&t, TIMER_PERIODIC, 1000, sense); } void senseDone(uint16_t value) { printf("Light = %d\r\n", value); actorSetState(ACTOR_0, 0); } void sense(Timer *t) { actorSetState(ACTOR_0, 1); sensorRequestAnalog(SENSOR_1, senseDone); }
9
$ make UART_VIA_USB=1 flash $ screen /dev/ttyACM0
10
11
$ cd $MOTELIB_DIR/platforms/iwing-mrf/tools $ ./config-mote.py $ ./config-mote.py --address 234 --panid 555 $ ./config-mote.py --channel 0x1A
12
$ make PLATFORM=iwing-jn DEFAULT_ADDR=50
13
Type (1 byte) 802.15.4 Header Seq No. (1 byte) App Data (max ~100 bytes) Check sum
14
radioRequestTx(BROADCAST_ADDR, 7, "HELLO", 5, txDone); : void txDone(RadioStatus status) { : } radioRequestTx(BROADCAST_ADDR, 7, "HELLO", 5, NULL);
15
radioSetRxHandler(receive); : void receive(Address src, MessageType type, void *msg, uint8_t len) { : }
16
Base station Sensor nodes measuring light intensity Sensor node
17
void sense(Timer *t) { actorSetState(ACTOR_0, 1); sensorRequestAnalog( SENSOR_1, senseDone); } void senseDone(uint16_t value) { radioRequestTx(0, 1, &value, sizeof(value), NULL); actorSetState(ACTOR_0, 0); } #include <motelib/system.h> #include <motelib/timer.h> #include <motelib/radio.h> #include <motelib/sensor.h> #include <motelib/actor.h> Timer t; void sense(Timer *t); void senseDone(uint16_t value); void boot() { timerCreate(&t); timerStart( &t, TIMER_PERIODIC, 1000, sense); }
18
#include <stdio.h> #include <motelib/system.h> #include <motelib/radio.h> #include <motelib/uart.h> void receive(Address src, MessageType type, void *msg, uint8_t len) { if (type == 1) { printf("Node %d: Light = %d\n", src, *((uint16_t*)msg)); } } void boot() { uartEnable(true,true); radioSetRxHandler(receive); }
19
message type 50