[102-2] WNFA lab4 - A Tiny Wireless Sensor Network

33  Download (0)

Full text

(1)

[102-2] WNFA lab4 -

A Tiny Wireless Sensor Network

2017/13/12 dalalalalala

(2)

Project Scheme

(3)

Device Map - CSIE 4F

SRC

DST src : R412, out door

dst : inside R435 (茶水 間 )

register the “lab4

routes reservation time slot”

(4)

SRC

1 2 3

4

5 6

7 8

DST

(5)

● Implement MAC protocol

● Implement routing protocol

● Implement ping test

What You Need to Do...

(6)

● Platform

o Zigduino hardware + Arduino software

● Steps :

1. follow lab1 Zigduino+Arduino installation guide 2. download ZigduionoRadio library on our website 3.put ZigduionoRadio directory into

PATHWHEREARDUINOINSTALLED/Arduino/libraries

4. Restart Arduino Software, then you can see 2 examples through

“File -> Examples -> ZigduinoRadio”

Environment Installation

(7)

● An Arduino library

o is created to allow the user to easily use Zigduino's built-in 2.4 GHz radio transceiver

o simple API for radio propogation

● Examples

o ZigduinoRadioExample

o SpectrumAnalyzer

ZigduinoRadio

(8)

● CSMA/CA

● RTS/CTS

● Aloha

● ACK or not

● error detecting code (checksum / CRC)

● …

MAC Protocol

(9)

● AODV

● DSR

● DSDV

● ...

Routing Protocol

(10)

● Application layer examples :

o examples/ZigduinoRadioExample/ZigduinoRadioExample.pde o examples/SpetrumAnalyzer/SpectrumAnalyzer.pde

● For detail :

o ZigduinoRadio.cpp o ZigduinoRadio.h o radio_rfa.c

o radio.h

Functions You Should Know

(11)

● Use Tools -> Serial Monitor

○ Zigduino reset itself when plugged in, open serial monitor, or press the “reset” button.

● Serial I/O functions

○ Serial.begin(int baudrate) // default 9600

○ Serial.available()

○ Serial.read()

○ Serial.print()

○ Serial.println(uin8_t inchar)

● Zigduino has small buffer - crash if too fast I/O

○ solution : higher baudrate or call delay()

API - Serial Port Functions

(12)

● uint8_t pkt_Tx(uint16_t addr, uint8_t* msg, uint8_t pkt_len)

o In ZigduinoRadioExample.pde

o A simple packet transmit function. Feel free to read and modify it.

o Set addr 0xffff for broadcast.

o Return 1 if get ACK. (a broadcast will get 0)

API - About Packet tx/rx (p.1)

(13)

● ZigduinoRadio.attachTxDone(void (*funct) (radio_tx_done_t))

● oxXmitDone(radio_tx_done_t x)

o Register a handler which is called after a packet delivery. You should check tx status in that

handler.

o (note: We use onXmitDone() in example. The TX_CCA_FAILED isn't implemented)

API - About Packet tx/rx (p.2)

(14)

● ZigduinoRadio.attachReceiveFrame(uint8_t* (*funct)(uint8_t, uint8_t*, uint8_t, uint8_t))

● uint8_t* pkt_Rx(uint8_t len, uint8_t* frm, uint8_t lqi, uint8_t crc_fail) o pkt_Rx() is called automatically when Zigduino

got a packet. No calling by yourself.

o pkt_Rx() will put packet in RxInternal with size RxInternal_len, then set RX_available at last.

o uint8_t fcs_failed : a variable indicates incorrect packet

API - About Packet tx/rx (p.3)

(15)

● The whole process :

o TX :

run pkt_Tx()

o RX :

(Hardware and API will automatically get packets and run pkt_Rx())

Check RX_available==1 if got a packet.

Data is put in RxInternal and RxInternal_len, move them to another buffer and set

RX_available=0 for HW receiving next packet.

API - About Packet tx/rx (p.4)

(16)

● ZigduinoRadio.begin(channel_t chan, uint8_t*

frameHeader)

o Initilizer, where input 11 <= channel <= 26.

o You can see correspond frequency list in SpectrumAnalyzer.pde (the other example program).

o Header must follow the IEEE802.15.4 standard.

API - About Protocol, Settings (p.1)

(17)

IEEE802.15.4 Header

(18)

● STATE_TX / STATE_TXAUTO / STATE_RX / STATE_RXAUTO

o You can change them in ZigduinoRadio.cpp.

o STATE_TXAUTO requires an ACK or return with TX_NO_ACK.

o STATE_RXAUTO implements destnation address check,

hardware ACK, but no FCS (one kind of error detecting code).

Zigduino sends ACK once the dst addr check is passed.

o We recommend you to use STATE_TXAUTO and

STATE_RXAUTO, paired with SW error detection(FCS).

API - About Protocol, Settings (p.2)

(19)

● Error detection schemes

o checksum, CRC, FCS, ……

o Hardware FCS is broken, please ignore that

o uint16_t cal_fcs(uint8_t* frm, uint8_t len)

in ZigduinoRadioExample.pde

kind of checksum, very simple

no good in some situations

API - About Protocol, Settings (p.3)

(20)

● MAC layer design

● already in ZigduinoRadioExample.pde

o #define NODE_ID 0x0001 // node id of this node. change it with different boards o #define CHANNEL 26 // check correspond frequency in SpectrumAnalyzer o #define TX_DO_CARRIER_SENSE 1

o #define TX_SOFT_FCS 1

they are defined at top of ZigduinoRadioExample.pde, feel free to change and test them

set 0 as unused, 1 as used

change NODE_ID with different boards (used as node id)

● what you can implement

o retransmission

o error indicating packet - RX got bad packet, then tell TX to retransmit lastest packet.

o …...

API - About Protocol, Settings (p.4)

(21)

● ZigduinoRadio.getRssiNow()

● cZigduinoRadio::doCca()

o for RSSI and carrier sense

o should have “ZigduinoRadio.setParam(phyCCAMode, (uint8_t)3);” in setup(). this is for the meaning of RSSI.

o you can implement CSMA using them

API - About Protocol, Settings (p.5)

(22)

API - Problems

● The hardware FCS

o Usually wrong. You should do it yourself.

o Pad 2 bytes after data, and ignore the last 2 bytes in pkt (the original FCS part in the protocol)

o header payload(msg) myFCS FCS

● The hardware ACK

o The hw ACK have no sender information / FCS.

o RX still send ACK even if packet content error (FCS failed.)

(23)

Ping Tests

(24)

● Write your own ping()

● What we focus on :

o average RTT (round-trip time)

o ping success rate (we’ll ping 50 times)

o the route this pkt has passed through

● Calculate and print them in your code

o show them real-time once a ping is end

Ping Tests

(25)

Use millis() to get the system time

Calculate Consumed Time

unsigned long ts1, ts2;

void loop(){

ts1 = millis();

my_ping();

ts2 = millis();

serial.println(ts2 - ts1);

}

(26)

● MAC protocol

o change CHANNEL

o design carrier sense and retry machenism

 modify pkt_Tx() function

 random backoff time

o STATE_TX(AUTO), STATE_RX(AUTO)

use hardware ACK

modify time period waiting ACK

add delay in ISR(TRX24_TX_END_vect) in radio_rfa.c o design error detecting code (FCS / checksum / ...)

o …...

Review - all you have to do (1)

(27)

● Routing table - the algorithm

o “reset” packet (clear table, can save time :P)

o route rebuild

o traffic estimate: packet send rate / packet loss rate

o route optimize : ETX (hop count vs. success rate)

o …...

Review - all you have to do (2)

(28)

● The ping test

o packet design (seq num, get route, ping period)

o timing to rebuild path ? o calculate time

o whole I/O design (reset routing table / start ping and print time+route)

● Tips

o Use LED to debug !!!

o Note the “reset” button on Zigduino board

Review - all you have to do (3)

(29)

● Each group will get 2 Zigduinos

● We have placed 2 sets at 4F for testing

o lab4 routes reservation time slot

o Use your own 2 Zigduino for src, dst.

● Demo

o 5/27(Tue.) or 5/29 (Thu.) @ CSIE 4F

o demo time slot reservation o We will do the ping tests.

Devices & Demo

(30)

● Demo - the ping test (75%)

o 45% : base line, a success ping

o 10% : average RTT, get by ranking

o 10% : success rate (50 pings, 0.2% for each suc)

o 10% : path rebuild after removing 1 node

● Report (25%)

o describe what you have done, why choosing this way, and problems encountered)

● Bonus (5%)

o any other things you have done)

Grade

(31)

● Deadline

o 5/29 (Thu.) 23:59

o Required documents (teamXX_lab4_v1.zip)

Report

All source code files

o Email

wn@csie.ntu.edu.tw

Deadline

(32)

● Zigduino-radio

o https://code.google.com/p/zigduino-radio

o http://www.daxia.com/bibis/upload/ZigDuino%B5%C4Arduino%D1%A7%CF%B0%B1%CA%BC%C7.640.pdf

● Error detecting code

o FCS

o http://cs.nju.edu.cn/yangxc/dcc_teach/fcs-calc.pdf

o CRC

o checksum

o http://en.wikipedia.org/wiki/Checksum

Reference

(33)

Q&A

Figure

Updating...

References

Related subjects :