Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed XBee mbed-rtos
xbee9.cpp@0:34e0352d7396, 2011-11-09 (annotated)
- Committer:
- yamaguch
- Date:
- Wed Nov 09 07:33:40 2011 +0000
- Revision:
- 0:34e0352d7396
- Child:
- 5:d01cf03058f6
initial creation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 0:34e0352d7396 | 1 | #include "XBee.h" |
yamaguch | 0:34e0352d7396 | 2 | |
yamaguch | 0:34e0352d7396 | 3 | void xbee9() { |
yamaguch | 0:34e0352d7396 | 4 | Serial ser(p9, p10); |
yamaguch | 0:34e0352d7396 | 5 | ser.baud(115200); |
yamaguch | 0:34e0352d7396 | 6 | XBee xbee(ser); |
yamaguch | 0:34e0352d7396 | 7 | xbee.init(); |
yamaguch | 0:34e0352d7396 | 8 | |
yamaguch | 0:34e0352d7396 | 9 | xbee.setDestination(0xFFFF); |
yamaguch | 0:34e0352d7396 | 10 | while (xbee.receive(5) != XBee::ZigBeeReceivePacket) { |
yamaguch | 0:34e0352d7396 | 11 | xbee.printf("Hello?"); |
yamaguch | 0:34e0352d7396 | 12 | printf("sent: Hello?\n"); |
yamaguch | 0:34e0352d7396 | 13 | } |
yamaguch | 0:34e0352d7396 | 14 | |
yamaguch | 0:34e0352d7396 | 15 | do { |
yamaguch | 0:34e0352d7396 | 16 | char address64[8], data[64] = {}; |
yamaguch | 0:34e0352d7396 | 17 | xbee.scan(XBee::Address64, address64, sizeof(address64)); |
yamaguch | 0:34e0352d7396 | 18 | xbee.scan(XBee::ReceivedData, data, sizeof(data) - 1); |
yamaguch | 0:34e0352d7396 | 19 | printf("received from %02X%02X%02X%02X %02X%02X%02X%02X: %s\n", |
yamaguch | 0:34e0352d7396 | 20 | address64[0], address64[1], address64[2], address64[3], |
yamaguch | 0:34e0352d7396 | 21 | address64[4], address64[5], address64[6], address64[7], data); |
yamaguch | 0:34e0352d7396 | 22 | if (strcmp(data, "Hello?") == 0) { |
yamaguch | 0:34e0352d7396 | 23 | xbee.setDestination(address64); |
yamaguch | 0:34e0352d7396 | 24 | xbee.printf("Hello!"); |
yamaguch | 0:34e0352d7396 | 25 | } |
yamaguch | 0:34e0352d7396 | 26 | } while (xbee.receive(0) == XBee::ZigBeeReceivePacket); |
yamaguch | 0:34e0352d7396 | 27 | |
yamaguch | 0:34e0352d7396 | 28 | printf("done!\n"); |
yamaguch | 0:34e0352d7396 | 29 | } |