http://mbed.org/users/okini3939/notebook/xbee-mbed/

Dependencies:   mbed XBee EthernetNetIf

Files at this revision

API Documentation at this revision

Comitter:
okini3939
Date:
Thu Mar 08 17:45:00 2012 +0000
Child:
1:27bf8d24244b
Commit message:

Changed in this revision

EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
XBee.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Thu Mar 08 17:45:00 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/XBee.lib	Thu Mar 08 17:45:00 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/okini3939/code/XBee/#8573b122fa84
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 08 17:45:00 2012 +0000
@@ -0,0 +1,108 @@
+#include "mbed.h"
+#include "XBeeWiFi.h"
+
+/*
+#define SECURITY SECURITY_WPA2
+#define SSID "XBEEWIFI"
+#define PASSPHRASE "PASSWORD"
+*/
+#define SECURITY SECURITY_OPEN
+#define SSID "XBEEWIFI"
+#define PASSPHRASE ""
+
+DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
+
+XBeeWiFi xbee(p13, p14, p21);
+
+
+int init_wifi (int timeout) {
+    int i, r;
+
+    pc.printf("reset %d\r\n");
+    r = xbee.reset();
+    if (r) {
+        pc.printf("error %x\r\n", r);
+        return -1;
+    }
+    xbee.getWiResponse(MODEM_STATUS_RESPONSE, 5000);    
+
+    xbee.setup(SECURITY, SSID, PASSPHRASE);
+
+    for (i = 0; i < timeout; i ++) {
+        wait(1);
+        r = xbee.getStatus();
+        pc.printf("status %02x: ", r);    
+        switch (r) {
+        case JOINED_AP:
+            pc.printf("Successfully joined an access point.\r\n");
+            return 0;
+        case INITIALIZATION:
+            pc.printf("WiFi initialization in progress.\r\n");
+            break;
+        case SSID_NOT_FOUND:
+            pc.printf("SSID not found.\r\n");
+            return -1;
+        case SSID_NOT_CONFIGURED:
+            pc.printf("SSID not configured.\r\n");
+            return -1;
+        case JOIN_FAILED:
+            pc.printf("SSID join failed.\r\n");
+            return -1;
+        case WAITING_IPADDRESS:
+            pc.printf("Waiting for IP configuration.\r\n");
+            break;
+        case WAITING_SOCKETS:
+            pc.printf("Listening sockets are being set up.\r\n");
+            break;
+        case SCANNING_SSID:
+            pc.printf("Currently scanning for SSID.\r\n");
+            break;
+        default:
+            pc.printf("\r\n");
+            break;
+        }
+    }
+    return -1;
+}
+
+
+int main() {
+    int i;
+    IpAddr ipaddr, netmask, gateway, nameserver;
+
+    xbee.begin(115200);
+    pc.baud(115200);
+    pc.printf("XBee WiFi test\r\n");
+
+    if (init_wifi(10)) {
+        pc.printf("XBee error\r\n");
+        return -1;
+    }
+
+    xbee.getAddress(ipaddr, netmask, gateway, nameserver);
+    pc.printf("IP address %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
+
+    nameserver = gateway;
+//    nameserver = IpAddr(202,232,2,35);
+    xbee.setNameserver(nameserver);
+
+    i = xbee.getHostByName("mbed.org", ipaddr);
+    if (i) {
+        pc.printf("error resolv %d\r\n", i);
+    } else {
+        pc.printf("resolv address %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
+    }
+
+    {
+        Serial xbeeserial(p13, p14);
+        xbeeserial.baud(115200);
+        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());
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Mar 08 17:45:00 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e