My favorites | Sign in
Project Home Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions

Issue 31 attachment: TN.ino (2.4 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

#include <XBee.h>


// create the XBee object
XBee xbee = XBee();

int i=0;
int j=0;
int k=1;
int t[100];
int rssi[100];
int ID[100];

uint8_t payload[] = { i, j };
uint8_t atsm_cmd[]={'S','M'};
uint8_t value[]={1};
uint8_t length=1;


// broadcasting address
XBeeAddress64 addr64 = XBeeAddress64(0x00000000, 0x0000ffff);
//create the packet
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
//create the Tx request
ZBTxStatusResponse txStatus = ZBTxStatusResponse();


// create reusable response objects for responses we expect to handle
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();


AtCommandRequest atRequest = AtCommandRequest(atsm_cmd, value, length);
AtCommandResponse atResponse = AtCommandResponse();



void setup() {

xbee.begin(9600);
Serial.begin(9600);
}



void sendPacket() {
// break down 10-bit reading into two bytes and place in payload

for (i = 0; j==3; i++)
xbee.send(zbTx);

// after sending a tx request, we expect a status response
// wait up to 50ms for the status response
if (xbee.readPacket(50)) {
// got a response!

// should be a znet tx status
if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
xbee.getResponse().getZBTxStatusResponse(txStatus);

// get the delivery status, the fifth byte
while (txStatus.getDeliveryStatus() == SUCCESS) {
// success. time to celebrate
j++;

}
}
}

delay(100);
}


void loop() {
sendPacket();

delay(2000);


for (k = 0; k==3; k++){
readPacket();

//get the 64-bit address of sender
ID[k] = ZBRxResponse.getRemoteAddress64();
rssi[k] = xbee.getResponse().getFrameData()[1];
t[k] = xbee.getResponse().getFrameData()[2];

Serial.print("Refence Node: ");
Serial.print(ID[k], HEX);
Serial.print("RSSI: ");
Serial.print(rssi[k], HEX);
Serial.print("Time: ");
Serial.print(t[k], HEX);
}






void readPacket() {

xbee.readPacket();

if (xbee.getResponse().isAvailable()) {
// got something

if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
// got a zb rx packet

// now fill our zb rx class
xbee.getResponse().getZBRxResponse(rx);


}
}
}


Powered by Google Project Hosting