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
Diff: examples/xbee_network_reset.cpp
- Revision:
- 11:25a790b8feb0
- Child:
- 14:50ee389d681f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/xbee_network_reset.cpp Tue Jan 29 14:00:39 2013 +0000 @@ -0,0 +1,48 @@ +#include "XBee.h" + +void printNetInfo(XBee& xbee) { + printf("OP: %s\n", (char *) XBeeAddress64(*(uint64_t *) xbee.executeCommand("OP"))); + printf("OI: %s\n", (char *) XBeeAddress16(*(uint16_t *) xbee.executeCommand("OI"))); + printf("CH: %d\n", *(uint8_t *) xbee.executeCommand("CH")); +} + +int receiveModemStatus(XBee& xbee) { + if (xbee.receive() == XBee::ModemStatus) { + XBeeStatus status; + if (xbee.scan(status)) { + const char *modemStatus[] = { + "Hardware reset", // 0 + "Watchdog timer reset", // 1 + "Joined network (routers and end devices)", // 2 + "Disassociated", // 3 + "?", "?", // 4, 5 + "Coordinator started" // 6 + }; + printf("Modem Status = %s\n", status < 7 ? modemStatus[status] : "?"); + } + return status; + } + return -1; +} + +void xbee_network_reset() { + XBee xbee(p9, p10); + xbee.baud(115200); + + printf("*** Network Reset ***\n"); + + if (xbee.init()) { + printNetInfo(xbee); + + printf("Issuing NR0 command...\n"); + xbee.sendCommand("NR", 0); + + // wait for XBee to join network + while (receiveModemStatus(xbee) != 2) + ; + printNetInfo(xbee); + } else { + printf("XBee connection error"); + } + +} \ No newline at end of file