33
[102-2] WNFA lab4 - A Tiny Wireless Sensor Network 2017/13/12 dalalalalala

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

Embed Size (px)

DESCRIPTION

[102-2] WNFA lab4 - A Tiny Wireless Sensor Network. 201 7 / 13 /12 dalalalalala. Project Scheme. Device Map - CSIE 4F. src : R412, out door dst : inside R435 (茶水間) register the “lab4 routes reservation time slot”. DST. SRC. 8. DST. 4. 3. 7. 2. 6. 5. SRC. 1. - PowerPoint PPT Presentation

Citation preview

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

Network

2017/13/12dalalalalala

Project Scheme

Device Map - CSIE 4F

SRC

DST ● src : R412, out door● dst : inside R435 (茶水間 )

● register the “lab4 routes reservation time slot”

SRC

1

2

34

5

6

7

8

DST

● Implement MAC protocol● Implement routing protocol● Implement ping test

What You Need to Do...

● Platformo Zigduino hardware + Arduino software

● Steps : 1. follow lab1 Zigduino+Arduino installation guide 2. download ZigduionoRadio library on our website3.put ZigduionoRadio directory into PATHWHEREARDUINOINSTALLED/Arduino/libraries4. Restart Arduino Software, then you can see 2 examples through “File -> Examples -> ZigduinoRadio”

Environment Installation

● An Arduino libraryo is created to allow the user to easily use

Zigduino's built-in 2.4 GHz radio transceivero simple API for radio propogation

● Exampleso ZigduinoRadioExampleo SpectrumAnalyzer

ZigduinoRadio

● CSMA/CA● RTS/CTS● Aloha● ACK or not● error detecting code (checksum / CRC)● …

MAC Protocol

● AODV● DSR● DSDV● ...

Routing Protocol

● Application layer examples :o examples/ZigduinoRadioExample/ZigduinoRadioExample.pdeo examples/SpetrumAnalyzer/SpectrumAnalyzer.pde

● For detail :o ZigduinoRadio.cppo ZigduinoRadio.ho radio_rfa.co radio.h

Functions You Should Know

● 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

● uint8_t pkt_Tx(uint16_t addr, uint8_t* msg, uint8_t pkt_len)o In ZigduinoRadioExample.pdeo 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)

● 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)

● 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)

● 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)

● 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)

IEEE802.15.4 Header

● STATE_TX / STATE_TXAUTO / STATE_RX / STATE_RXAUTOo 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)

● Error detection schemeso checksum, CRC, FCS, ……o Hardware FCS is broken, please ignore thato 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)

● MAC layer design● already in ZigduinoRadioExample.pde

o #define NODE_ID 0x0001 // node id of this node. change it with different boardso #define CHANNEL 26 // check correspond frequency in SpectrumAnalyzero #define TX_DO_CARRIER_SENSE 1o #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 implemento retransmissiono error indicating packet - RX got bad packet, then tell TX to retransmit lastest packet.o …...

API - About Protocol, Settings (p.4)

● ZigduinoRadio.getRssiNow()● cZigduinoRadio::doCca()

o for RSSI and carrier senseo 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)

API - Problems

● The hardware FCSo 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 ACKo The hw ACK have no sender information / FCS.o RX still send ACK even if packet content error

(FCS failed.)

Ping Tests

● 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 codeo show them real-time once a ping is end

Ping Tests

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);}

● MAC protocolo change CHANNELo 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.co design error detecting code (FCS / checksum / ...)o …...

Review - all you have to do (1)

● Routing table - the algorithmo “reset” packet (clear table, can save time :P)o route rebuildo traffic estimate: packet send rate / packet loss

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

Review - all you have to do (2)

● The ping testo packet design (seq num, get route, ping period)o timing to rebuild path ?o calculate timeo 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)

● Each group will get 2 Zigduinos● We have placed 2 sets at 4F for testing

o lab4 routes reservation time sloto Use your own 2 Zigduino for src, dst.

● Demoo 5/27(Tue.) or 5/29 (Thu.) @ CSIE 4Fo demo time slot reservationo We will do the ping tests.

Devices & Demo

● Demo - the ping test (75%)o 45% : base line, a success pingo 10% : average RTT, get by rankingo 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

● Deadlineo 5/29 (Thu.) 23:59o Required documents (teamXX_lab4_v1.zip)

Report All source code files

o Email [email protected]

Deadline

● Zigduino-radioo https://code.google.com/p/zigduino-radioo http://www.daxia.com/bibis/upload/ZigDuino%B5%C4Arduino%D1%A7%CF%B0%B1%CA%BC%C7.640.pd

f

● Error detecting codeo FCSo http://cs.nju.edu.cn/yangxc/dcc_teach/fcs-calc.pdfo CRCo checksumo http://en.wikipedia.org/wiki/Checksum

Reference

Q&A