• 沒有找到結果。

[2016-Spring] WNFA Lab4

N/A
N/A
Protected

Academic year: 2022

Share "[2016-Spring] WNFA Lab4"

Copied!
38
0
0

加載中.... (立即查看全文)

全文

(1)

Mobile and Vehicular Network Lab

[2016-Spring] WNFA Lab4 Wireless Sensor Network

2016/5/13

Jing-Yeu Chen

(2)

Mobile and Vehicular Network Lab

Project Scheme

7

(3)

Mobile and Vehicular Network Lab

Device Map - CSIE 4F

SRC DST

(4)

Mobile and Vehicular Network Lab

Device Map - CSIE 4F

DST

SRC

(5)

Mobile and Vehicular Network Lab

● Each group will get

● 2 Zigduinos

● 2 Antenna

● 2 USB Line

● We have placed a set at 4F for testing

o lab4 routes reservation time slot

o Use your own 2 Zigduino for src, dst.

(6)

Mobile and Vehicular Network Lab

What You Need to Do...

● Implement MAC protocol

● Implement Routing protocol

● Implement Ping test

(7)

Mobile and Vehicular Network Lab

MAC Protocol

● CSMA/CA

● RTS/CTS

● Aloha

● ACK or NACK

● Error detecting (checksum / CRC)

● …

(8)

Mobile and Vehicular Network Lab

Routing Protocol

● AODV

● DSR

● DSDV

● ...

● Ref : Routing.pdf

(9)

Mobile and Vehicular Network Lab

Ping Tests

(10)

Mobile and Vehicular Network Lab

Ping Tests

(11)

Mobile and Vehicular Network Lab

Environment Installation

● Platform

o Zigduino hardware + Arduino software

● Steps :

1. Follow lab1 Zigduino+Arduino installation guide 2. Download ZigduinoRadiolibrary on course website

(If you encounter compile error in your Mac, try this version of ZigduinoRadio library)

3. Move ZigduinoRadio directory to

PATHWHEREARDUINOINSTALLED/Arduino/libraries (for Window)

~/Document/Arduino/libraries (for OS X)

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

“File -> Examples -> ZigduinoRadio”

(12)

Mobile and Vehicular Network Lab

ZigduinoRadio

● Arduino library

o Allow users using Zigduino's built-in 2.4 GHz radio transceiver easily, simple API for radio propogation

● Examples

o ZigduinoRadioExample

o SpectrumAnalyzer

(13)

Mobile and Vehicular Network Lab

HelloWorld

Compile and upload ZigduinoRadioExample for both Zigduino board

ModifyNODE_ID(line10)and receiver address (line60) pkt_Tx(addr,teststr)

– EX

• Board 1 : NODE_ID 0x0001, pkt_Tx(0x0002, teststr)

• Board 2:NODE_ID 0x0002, pkt_Tx(0x0001, teststr)

Then you will see the transmitting and receiving messages between them

– Take Board 1’Serial Terminal as an example

---

| TxDone: 0 (OK) |

| |

| Rx: ...TT 2.... |

| LQI: 255, RSSI: -37 dBm, ED: -90 dBm |

| |

| ca fail with rssi = -87 |

| |

| TxDone: 1 NO ACK |

| |

| TxDone: 0 (OK) |

| |

| Rx: ...TT 2.... |

| LQI: 255, RSSI: -37 dBm, ED: -90 dBm |

| |

---

(14)

Mobile and Vehicular Network Lab

Functions You Should Know

● 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

(15)

Mobile and Vehicular Network Lab

API - Serial Port Functions

Use Tools -> Serial Monitor

Zigduino reset itself when 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()

(16)

Mobile and Vehicular Network Lab

API - About Packet TX

uint8_t pkt_Tx(uint16_t addr, uint8_t* msg)

o In ZigduinoRadioExample.pde

o A simple packet transmit function.

o Feel free to modify it.

o Set addr 0xffff for broadcast.

(17)

Mobile and Vehicular Network Lab

API - About Packet TX

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

onXmitDone(radio_tx_done_t x)

o Register a handler

o Called after a packet delivery.

o You should check tx status in that handler.

(18)

Mobile and Vehicular Network Lab

API - About Packet RX

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 RxBuffer, then set RX_available.

o Use has_RX() to check if got packet

o uint8_t fcs_failed : a variable indicates incorrect packet

(19)

Mobile and Vehicular Network Lab

API - About Packet TX/RX

● The whole process :

o TX :

set TX_available=1  need_TX()  pkt_Tx()  Fill payload  Carrier Sense  txFrame() 

onXmitDone()  Finished when receiving HW ACK ,or retransmitting until > retry times)

o RX :

(Hardware and pkt_Rx() will automatically run and send HW ACK) Use has_RX() to Check

RX_available==1 or not Data is in RxBuffer

(20)

Mobile and Vehicular Network Lab

API - About Protocol, Settings (p.1)

ZigduinoRadio.begin(channel_t chan, uint8_t* frameHeader)

ZigduinoRadio.setChannel(channel_t chan)

o Initilizer, 11 <= channel <= 26.

o You can see correspond frequency list in

SpectrumAnalyzer.pde (the other example).

o Header must follow the IEEE802.15.4 standard.

(21)

Mobile and Vehicular Network Lab

IEEE802.15.4 Header

(22)

Mobile and Vehicular Network Lab

API - About Protocol, Settings (p.2)

STATE_TX / STATE_TXAUTO / STATE_RX / STATE_RXAUTO.

o STATE_TXAUTO requires an ACK or return with TX_NO_ACK.

o STATE_RXAUTO implements destination address check, hardware ACK, but no FCS (one kind of error detecting code).

o Zigduino sends ACK once the packet passed dst addr check .

o We strongly recommend you using both STATE_TXAUTO and STATE_RXAUTO, and paired with original/your SW error detection(FCS).

(23)

Mobile and Vehicular Network Lab

API - About Protocol, Settings (p.3)

● 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

(24)

Mobile and Vehicular Network Lab

API - About Protocol, Settings (p.4)

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 in ZigduinoRadioExample.pde, feel free to modify it

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 retransmitting latest packet.

o …...

(25)

Mobile and Vehicular Network Lab

API - About Protocol, Settings (p.5)

ZigduinoRadio.getRssiNow()

ZigduinoRadio::doCca()

o for RSSI and carrier sense

o Should addZigduinoRadio.setParam(phyCCAMode, (uint8_t)3);” in setup().

o You can implement CSMA using these function

(26)

Mobile and Vehicular Network Lab

● The hardware FCS

o Usually wrong. Suggest you do it by yourself.

o EX. 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.)

API - Problems

(27)

Mobile and Vehicular Network Lab

● The software ACK

o Usually wrong. Please do not use Software ACK (set TX_SOFT_ACK as 0 instead of 1)

o Just use Hardware ACK and design your own algorithm to detect packet error

API - Problems

(28)

Mobile and Vehicular Network Lab

Ping Tests

● Write your own ping()

● What we focus on :

o 1. Average RTT (round-trip time)

o 2. Ping success rate (we’ll ping 100 times)

o 3. the route this pkt has passed through

● Calculate and print them in your code

o show above information during pinging

(29)

Mobile and Vehicular Network Lab

Calculate Consumed Time

Use millis() to get the system time

unsigned long ts1, ts2;

void loop(){

ts1 = millis();

my_ping();

ts2 = millis();

serial.println(ts2 - ts1);

}

(30)

Mobile and Vehicular Network Lab

Review - all you have to do (1)

● 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 …...

(31)

Mobile and Vehicular Network Lab

Review - all you have to do (2)

● Routing table - the algorithm

o “reset” packet (clear table quickly, 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 …...

(32)

Mobile and Vehicular Network Lab

Review - all you have to do (3)

● The ping test

o packet design (sequence number, get route, ping period)

o timing to rebuild path ? o calculate time

o whole I/O design

o reset routing table o start ping

o print time+route+success_rate

● Tips

o Use LED to debug !!!

o Note the “reset” button on Zigduino board

(33)

Mobile and Vehicular Network Lab

GRADE

(34)

Mobile and Vehicular Network Lab

Grade

• Demo-6/7(Tues.)

– Please register the Demo Slot. And come to CSIE R424 at that time.

• Deadline:6/7(Tues.) 23:59 email to wn@csie.ntu.edu.tw

– Email subject:[WN]lab4_teamXX – [WN]lab4_teamXX.zip

• Source code and Modified Library Files (ex ZigduinoRadio.ino)

• Report(pdf)

(35)

Mobile and Vehicular Network Lab

Grade

• Demo - the ping test (70%)

– 40% : base line, a success ping

– 10% : average RTT, get by ranking

– 10% : success rate (100 pings, 0.1% for each sec) – 10% : path rebuild after removing 1 node

• Report (20%)

– Describe what you have done, why choosing this way, and problems encountered

• Peer Review (10%)

• Bonus (5%)

– any other things you have done

(36)

Mobile and Vehicular Network Lab

• Contact to TAs :

– facebook

https://www.facebook.com/groups/wn15spring/

– Email : wn@csie.ntu.edu.tw

– Office hour : Tues. 13:20~14:10@ CSIE R424

(37)

Mobile and Vehicular Network Lab

Reference

● 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 https://en.wikipedia.org/wiki/Frame_check_sequ ence

o Checksum

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

(38)

Mobile and Vehicular Network Lab

Q&A

參考文獻

相關文件

Once you get down to a purely business level, your influence is gone and the true light of your life isdimmed. You must work in the missionary spirit, with a breadth of charity

A floating point number in double precision IEEE standard format uses two words (64 bits) to store the number as shown in the following figure.. 1 sign

Your problem may be modest, but if it challenges your curiosity and brings into play your inventive faculties, and if you solve it by your own means, you may experience the tension

A floating point number in double precision IEEE standard format uses two words (64 bits) to store the number as shown in the following figure.. 1 sign

In this report, formats were specified for single, double, and extended precisions, and these standards are generally followed by microcomputer manufactures using

If the bootstrap distribution of a statistic shows a normal shape and small bias, we can get a confidence interval for the parameter by using the boot- strap standard error and

Please liaise with the officer in your school who are responsible for the Class and Subject Details Survey for using of the same class names in both the Class and Subject

• For some non-strongly convex functions, we provide rate analysis of linear convergence for feasible descent methods. • The key idea is to prove an error bound between any point