example code for Axeda backend using SocketModem library for Cellular or Wifi access

Dependencies:   AxedaWrapper SocketModem mbed

Files at this revision

API Documentation at this revision

Comitter:
mfiore
Date:
Sat Jan 04 06:15:19 2014 +0000
Child:
1:f0b38aa21aaf
Commit message:
Axeda dev initial commit

Changed in this revision

AxedaWrapper.lib Show annotated file Show diff for this revision Revisions of this file
SocketModem.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.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AxedaWrapper.lib	Sat Jan 04 06:15:19 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/Multi-Hackers/code/AxedaWrapper/#dd1e00e3eba5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SocketModem.lib	Sat Jan 04 06:15:19 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/teams/Multi-Hackers/code/SocketModem/#571e0ef6c8dc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Jan 04 06:15:19 2014 +0000
@@ -0,0 +1,98 @@
+#include "mbed.h"
+#include "include_me.h"
+#include "AxedaWrapper.h"
+
+// set to 1 for cellular shield board
+// set to 0 for wifi shield board
+#define CELL_SHIELD 1
+
+using namespace mts;
+
+int main() {
+#if CELL_SHIELD
+    for (int i = 30; i >= 0; i = i - 2) {
+        wait(2);
+        printf("Waiting %d seconds...\n\r", i);
+    }
+    
+    MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
+    serial->baud(115200);
+    Transport::setTransport(Transport::CELLULAR);
+    Cellular* cell = Cellular::getInstance();
+    cell->init(serial);
+
+    int max_tries = 5;
+    int i;
+    std::string apn = "wap.cingular";
+    
+    i = 0;
+    while (i++ < max_tries) {
+        if (cell->getRegistration() == Cellular::REGISTERED) {
+            printf("registered with tower\n\r");
+            break;
+        } else if (i >= max_tries) {
+            printf("failed to register with tower\n\r");
+        } else {
+            wait(3);
+        }
+    }
+    
+    printf("signal strength: %d\n\r", cell->getSignalStrength());
+
+    i = 0;
+    printf("setting APN to %s\n\r", apn.c_str());
+    while (i++ < max_tries) {
+        if (cell->setApn(apn) == SUCCESS) {
+            printf("successfully set APN\n\r");
+            break;
+        } else if (i >= max_tries) {
+            printf("failed to set APN\n\r");
+        } else {
+            wait(1);
+        }
+    }
+    
+    i = 0;
+    printf("bringing up PPP link\n\r");
+    while (i++ < max_tries) {
+        if (cell->connect()) {
+            printf("PPP link is up\n\r");
+            break;
+        } else if (i >= max_tries) {
+            printf("failed to bring PPP link up\n\r");
+        } else {
+            wait(1);
+        }
+    }
+#else
+    for (int i = 6; i >= 0; i = i - 2) {
+        wait(2);
+        printf("Waiting %d seconds...\n\r", i);
+    }
+    MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256);
+    serial->baud(9600);
+    Transport::setTransport(Transport::WIFI);
+    Wifi* wifi = Wifi::getInstance();
+    printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE");
+    printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork("", Wifi::WPA2, "")).c_str());
+    printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str());
+    printf("Signal Strnegth (dBm): %d\n\r", wifi->getSignalStrength());
+    printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
+    printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure");
+    printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
+#endif
+    
+    std::string serial_num = "";
+    AxedaWrapper* client = new AxedaWrapper(serial_num);
+    //AxedaWrapper* client = new AxedaWrapper(serial_num, "mbed", "54.235.103.204");
+    bool retval;
+    while (true) {
+        int val = rand();
+        printf("sending %d\r\n", val);
+        retval = client->send("test", val);
+        printf("%s\n\r", retval ? "succeeded" : "failed");
+        wait(5);
+    }
+    
+    return 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.lib	Sat Jan 04 06:15:19 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/#a842253909c9