XBee Wifi on EA LPC4088 QS bBoard
Dependencies: EthernetNetIf XBee_EA_LPC4088_QS mbed
Fork of XBee_wifi_sample by
Diff: main.cpp
- Revision:
- 3:91764c4bb3d3
- Parent:
- 1:27bf8d24244b
--- a/main.cpp Wed Dec 18 02:25:14 2013 +0000 +++ b/main.cpp Tue Feb 10 21:17:48 2015 +0000 @@ -5,13 +5,9 @@ #define SECURITY SECURITY_WPA2 -#define SSID "XBEEWIFI" -#define PASSPHRASE "PASSWORD" -/* -#define SECURITY SECURITY_OPEN -#define SSID "XBEEWIFI" -#define PASSPHRASE "" -*/ +#define SSID "HomeNet24" +#define PASSPHRASE "L57Q1*P3h" + #define HTTP_PORT 80 #define HTTP_SRC_PORT 10080 #define HTTP_TIMEOUT 5000 // ms @@ -19,10 +15,12 @@ #define METHOD_POST 1 DigitalOut myled(LED1); -Serial pc(USBTX, USBRX); +Serial pc(p9, p10); -XBeeWiFi xbee(p13, p14, p12, P0_22); // TX, RX, CTS, RTS -//XBeeWiFi xbee(p13, p14, p12, p11); // TX, RX, CTS, RTS +XBeeWiFi xbee(P4_22 , P4_23, P4_20, P4_21); // TX, RX, CTS, RTS + +int led_count = 0; +int error_fail = 0; int init_wifi (int timeout) { int i, r; @@ -154,27 +152,58 @@ } int main() { - int i; + //int i; IpAddr ipaddr, netmask, gateway, nameserver; Host host; - - xbee.begin(115200); -// xbee.baud(921000); + //Host host.setIp(IpAddr(217,140,96,42)); + pc.baud(115200); - pc.printf("XBee WiFi test\r\n"); + pc.printf("Starting main program...\r\n\n"); + +// pc.printf("1 cycles of LED1 on/off start...\r\n"); +// +// led_count = 0; +// while(led_count<1) { +// myled = 1; +// wait(1); +// myled = 0; +// wait(1); +// led_count++; +// } +// myled = 1; +// +// pc.printf("1 cycles of LED1 on/off DONE.\r\n\n"); - if (init_wifi(20)) { +// pc.printf("XBee WiFi test starting...\r\n\n"); + + pc.printf("**CALLING xbee.begin...\r\n"); + xbee.begin(9600); + pc.printf("xbee.begin DONE.**\r\n\n"); + pc.printf("**CALLING init_wifi...\r\n"); + if (init_wifi(10)) { pc.printf("XBee error\r\n"); - return -1; + //return -1; + error_fail = 1; } + pc.printf("init_wifi DONE.*\r\n\n"); + while(error_fail) { + myled = 1; + wait(1); + myled = 0; + wait(1); + } + + pc.printf("**Getting IP address**\r\n\n"); xbee.getAddress(ipaddr, netmask, gateway, nameserver); pc.printf("IP address %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); if (ipaddr == 0) { pc.printf("not configure\r\n"); return -1; } + wait(5); +///////////////////////////////// /* // DNS lookup // *** Note: wifi is turned off when XBee send/recv the port 53 udp packet. @@ -192,6 +221,7 @@ pc.printf("resolv address %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); } */ +/////////////////////////////////////// // HTTP request wait(1); host.setIp(IpAddr(217,140,96,42)); @@ -199,18 +229,19 @@ httpRequest(METHOD_GET, &host, "/", "", ""); // Serial through - { - Serial xbeeserial(p13, p14); - DigitalOut rts(p22); + // { + // Serial xbeeserial(p9, p10); + //DigitalOut rts(p22); + //DigitalOut rts(P4_21); - xbeeserial.baud(115200); - rts = 0; - pc.printf("Serial through\r\n"); - for (;;) { - if (pc.readable()) xbeeserial.putc(pc.getc()); - if (xbeeserial.readable()) pc.putc(xbeeserial.getc()); + // xbeeserial.baud(115200); + //rts = 0; +// pc.printf("Serial through\r\n"); +// for (;;) { +// if (pc.readable()) xbeeserial.putc(pc.getc()); +// if (xbeeserial.readable()) pc.putc(xbeeserial.getc()); // if (xbeeserial.readable()) pc.printf("%02x ", xbeeserial.getc()); - } - } +// } +// } }