15
Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT (http://link.kut.ac.kr ) Yong-hwan Kim Spring Semester, 2011

Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

Embed Size (px)

Citation preview

Page 1: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

Ubiquitous Computing Practice- Part 4(RSSI) -

Laboratory of Intelligent Networks @ KUT(http://link.kut.ac.kr)

Yong-hwan Kim

Spring Semester, 2011

Page 2: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

7. RF Power Control, Multichannel and RSSI

RF Power Control 과 Multichannel 에 대해 이해RSSI 값 활용 방법 예제 수행

Ubiquitous Computing

Page 3: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

기본 지식Power Control 무선 전파는 전송되는 거리의 제곱 or 네제곱에

반비례 어느 정도의 세기가 보장되어야수신측에서 데이터

값을 읽을 수 있다 . 전송거리가 클수록 링크가 유지되기 쉬우나 , 다른

노드들의 통신을 방해하며 전력 소모가 많다 . CC2420 RF 인터페이스는 8 단계로 Power

ControlOutput Power[dBm]

Current Consumption

[mA]

Output Power[dBm]

Current Consumption

[mA]

0 17.4 -1 16.5

-3 15.2 -5 13.9

-7 12.5 -10 11.2

-15 9.9 -25 8.5

Ubiquitous Computing

Page 4: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

기본 지식Multichannel IEEE 802.15.4 표준 – 26 채널 CC2420 – 16 개 채널 지원

F = 2405 + 5(k-11) Mhz , k = 11, 12, …, 26

RSSI(Received Signal Strength Indicator) RF 인터페이스에서 수신한 전파의 세기 (dBm) RSSI 가 -94dBm 이상이어야 메시지 디코딩 가능 RSSI.RSSI_VAL 레지스터에 저장

저장 값이 -20 일 경우 , 실제 RSSI 는 -65dBm

Ubiquitous Computing

Page 5: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSI 예제 소개 1 번 노드

RF_Configuration_Setting() Task 함수에서 노드 자신의 파워 및 채널을 변경

변경된 설정에 의해 1 초마다 데이터 무선 전송 0 번 노드

받은 RSSI 값을 계산하여 PC 로 전달( 제대로 수신 되었을 경우 Red LED 점멸 )

ZigbeX 1 ZigbeX 0시리얼케이블

무선통신

MCH_PTRSSIID : 1

MCH_PTRSSIID : 0

Ubiquitous Computing

Page 6: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSI.nc

CC2420ActiveMessageC : 전송 파워 제어 CC2420ControlC : 채널 제어 무선 통신 , 시리얼 통신 동시 사용

Ubiquitous Computing

Page 7: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSI.ncconfiguration MCH_PTRSSI { } implementation {components MainC, MCH_PTRSSIM, new TimerMilliC(), LedsC, BusyWaitMicroC

, ActiveMessageC, new AMSenderC(AM_MCH_PTRSSI_Msg), new AMReceiverC(AM_MCH_PTRSSI_Msg), CC2420ActiveMessageC, CC2420ControlC, SerialActiveMessageC as Serial;

MCH_PTRSSIM.Boot -> MainC; MCH_PTRSSIM.Timer -> TimerMilliC; MCH_PTRSSIM.Leds -> LedsC; MCH_PTRSSIM.BusyWait ->BusyWaitMicroC;

// RF Component MCH_PTRSSIM.CommControl -> ActiveMessageC; MCH_PTRSSIM.RecvMsg -> AMReceiverC; MCH_PTRSSIM.DataMsg -> AMSenderC; MCH_PTRSSIM.CC2420Packet -> CC2420ActiveMessageC; // 전송 파워제어 MCH_PTRSSIM.CC2420Config -> CC2420ControlC; // 채널 제어

// Serial Component MCH_PTRSSIM.Serial_Control -> Serial; MCH_PTRSSIM.Serial_Packet -> Serial; MCH_PTRSSIM.Serial_Send -> Serial.AMSend[AM_MCH_PTRSSI_Uart]; }

Ubiquitous Computing

Page 8: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSIM.nc

MCH_PTRSSIM.nc 파일 경로 :

/opt/tinyos-2.x/contrib/zigbex/MCH_PTRSSI/MCH_PTRSSIM.nc

함수 실행순서 Boot.booted() → CommControl, SerialControl → RF

configuration( 파워 , 채널 설정 ) → CC2420config.sync()

CC2420config.syncDone() → Timer.startPeriodic () 반복

Timer.fired () → task TryToSend () → DataMsg.send ()

RecvMsg.receive() → Serial_Send.sendDone()

Ubiquitous Computing

Page 9: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSIM.nc1: includes MCH_PTRSSI;2: module MCH_PTRSSIM{3: uses {4: interface Boot; interface Timer<TMilli>;5: interface Leds;6: interface BusyWait<TMicro, uint16_t>;7: interface SplitControl as CommControl;8: interface AMSend as DataMsg;9: interface Receive as RecvMsg;10: interface SplitControl as Serial_Control;11: interface AMPacket as Serial_Packet;12: interface AMSend as Serial_Send;13: interface CC2420Packet;14: interface CC2420Config; }}15: implementation16: {17: message_t sendmsg, uartmsg;18: uint16_t mySeq;19: uint8_t myPowerLevel;20: uint8_t myChannel;21: task void RF_Configuration_Setting ();22: task void TryToSend();

7~9: RF 관련 인터페이스

10~12: Serial 관련 인터페이스

Ubiquitous Computing

Page 10: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSIM.nc23: event void Boot.booted() {24: atomic mySeq = 0;25: call CommControl.start();26: }27: event void CommControl.startDone(error_t error) {28: call Serial_Control.start();29: }30: event void Serial_Control.startDone(error_t error) {31: post RF_Configuration_Setting ();32: }33: event void CommControl.stopDone(error_t error) {}34: event void Serial_Control.stopDone(error_t error) {}

35: task void RF_Configuration_Setting () {36: call BusyWait.wait(3000);37: atomic myPowerLevel = 0x1f;38: call CC2420Packet.setPower (&sendmsg,

myPowerLevel);39: atomic myChannel = 15;40: call CC2420Config.setChannel (myChannel);41: call CC2420Config.sync();42: }

23: RF 컴포넌트를 시작하기 위해 CommControl.start() 호출 ( 원형은 ActiveMessageC 와 연결되는SplitControl)

27: Serial 컴포넌트를 시작하기 위해 Serial_Control.start() 호출

30: 모트의 RF 채널과 파워를 조절하기 위한 RF_Configuration_Setting() 함수를 호출

38 : RF 파워 조절 함수 호출실제 RF 파워는 message_t 구조체의 Meta 필드에있는 tx_power 변수에 의해 설정되는데 이 함수로 그 값을 조절한다// 0x1f = 0 dBm // 0x1b = -1 dBm// 0x17 = -3 dBm // 0x13 = -5 dBm// 0x0f = -7 dBm // 0x0b = -10 dBm// 0x07 = -15 dBm // 0x03 = -25 dBm40: RF 채널 변경 함수 호출// Channel Ranges: 11 ~ 26

41: 설정된 값을 CC2420 RF 칩으로 전송

Ubiquitous Computing

Page 11: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSIM.nc43: event void CC2420Config.syncDone ( error_t error ) {44: if ( error == SUCCESS ) {45: call Timer.startPeriodic(1000);46: call Leds.led1On(); //Green On47: }else{ post RF_Configuration_Setting ();48: }}49: event void Timer.fired() {50: call Leds.led1Toggle(); //Green Toggle51: post TryToSend();52: }53: task void TryToSend() {54: struct MCH_PTRSSI_Msg *pack;55: pack = (struct MCH_PTRSSI_Msg *) call

DataMsg.getPayload(&sendmsg);56: pack->seq = mySeq++;57: pack->SenderID = TOS_NODE_ID;58: pack->PowerLevel = myPowerLevel;59: pack->Channel = myChannel;60: if (call DataMsg.send(AM_BROADCAST_ADDR,

&sendmsg, sizeof(struct MCH_PTRSSI_Msg)) == SUCCESS){

61: call Leds.led2On(); //Yellow On62: }}

43: 원하는 채널을 CC2420 RF 칩에 설정하게 되면CC2420Config.syncDone() 이벤트 함수가 호출된다 .성공이라면 , 주기적 동작을 위해 Timer.startPeriodic(1000) 을 호출하고 , 실패라면 설정함수를 다시 호출

53: TryToSend() 함수에서는 MCH_PTRSSI_Msg구조체에 seq, 자신의 주소 , 설정한 파워 및 채널정보를 넣어 RF 로 send 한다 .

Ubiquitous Computing

Page 12: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSIM.nc63: event void DataMsg.sendDone(message_t* msg,

error_t error) {64: if (error == SUCCESS){65: call Leds.led2Off();66: }}

67: event message_t* RecvMsg.receive(message_t* msg, void* payload, uint8_t len) {

68: struct MCH_PTRSSI_Msg *recv_pack = (struct MCH_PTRSSI_Msg *) call DataMsg..getPayload(&uartmsg);

69: memcpy((void*)recv_pack, payload, len);70: recv_pack->RSSI = call CC2420Packet.getRssi(msg); 71: recv_pack->RSSI -= 45; 72: call Serial_Packet.setSource(&uartmsg,

recv_pack->SenderID);73: if (call Serial_Send.send(TOS_NODE_ID, &uartmsg,

sizeof(struct MCH_PTRSSI_Msg)) == SUCCESS)74: call Leds.led0Toggle();75: return msg;76: }77:}

67: 만약 다른 노드로부터 RF 패킷을 받으면RecvMsg.receive() 함수가 호출된다 . 함수에서 받은 패킷의 RSSI 값에서 -45 를 하여 dBm단위의 RSSI 값을 만든 뒤 Serial 로 전송

Ubiquitous Computing

Page 13: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSI.hMCH_PTRSSI.h 에 정의된 데이터 포멧

#define MSG_LEN 6

struct MCH_PTRSSI_Msg{

uint16_t seq;uint16_t SenderID;uint8_t PowerLevel;uint8_t Channel;char RSSI; //RSSI value can be a minus(a negative value).uint8_t Pending;

};

enum { AM_MCH_PTRSSI_Msg = 26, AM_MCH_PTRSSI_Uart = 27};

Ubiquitous Computing

Page 14: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

MCH_PTRSSI 예제 실습MCH_PTRSSI 컴파일 및 포팅

AVR Studio 를 이용하여 두 개의 센서 노드에 각각 reinstall 된 hex 파일을 program 함 .

SerialText 프로그램을 이용하여 ( 시리얼 통신을 통해 ) SenderID, Power Level, Channel, RSSI 확인

$ cd /opt/tinyos-2.x/contrib/zigbex/MCH_PTRSSI$ make zigbex$ make zigbex reinstall.0 //0 번 아이디$ make zigbex reinstall.1 //1 번 아이디

Ubiquitous Computing

Page 15: Ubiquitous Computing Practice - Part 4(RSSI) - Laboratory of Intelligent Networks @ KUT () Yong-hwan Kim Spring

Packet Heaer Serial Header

Seq Src

Power

Channel

RSSI(-59dBm)

Pedding

Data

unsigned char RSSI = 197; //C5char RSSI_Signed = (char) RSSI;printf("%d, %d\n", RSSI, RSSI_Signed); //-59

Ubiquitous Computing