An m2x sample code that uses accelerometers. Not working yet.

Dependencies:   MMA8451Q SocketModem jsonlite mbed

Fork of MTS_M2x_Example by Multi-Hackers

Files at this revision

API Documentation at this revision

Comitter:
mfiore
Date:
Sat Jan 04 06:27:12 2014 +0000
Parent:
0:032beb056844
Child:
2:76e0d5968991
Commit message:
updated SocketModem to latest; updated Cell initialization code

Changed in this revision

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
--- a/SocketModem.lib	Sat Jan 04 05:55:16 2014 +0000
+++ b/SocketModem.lib	Sat Jan 04 06:27:12 2014 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/teams/Multi-Hackers/code/SocketModem/#a233b9775f93
+https://mbed.org/teams/Multi-Hackers/code/SocketModem/#571e0ef6c8dc
--- a/main.cpp	Sat Jan 04 05:55:16 2014 +0000
+++ b/main.cpp	Sat Jan 04 06:27:12 2014 +0000
@@ -8,11 +8,20 @@
 const char feed[] = "5996c26815bd3245c8ec35089d51b614";
 const char stream[] = "test_test_test";
 
+// set to 1 for cellular shield board
+// set to 0 for wifi shield board
+#define CELL_SHIELD 1
+
 int main() {
-    /* bring up PPP link */
-    /*
+#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);
 
@@ -20,10 +29,6 @@
     int i;
     std::string apn = "wap.cingular";
     
-    wait(10);
-    printf("waiting for radio to come up\n\r");
-    wait(10);
-    
     i = 0;
     while (i++ < max_tries) {
         if (cell->getRegistration() == Cellular::REGISTERED) {
@@ -36,7 +41,10 @@
         }
     }
     
+    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");
@@ -49,6 +57,7 @@
     }
     
     i = 0;
+    printf("bringing up PPP link\n\r");
     while (i++ < max_tries) {
         if (cell->connect()) {
             printf("PPP link is up\n\r");
@@ -59,31 +68,27 @@
             wait(1);
         }
     }
-    
-    if (! cell->isConnected()) {
-        printf("could not connect\n\r");
-        return 1;
+#else
+    for (int i = 6; i >= 0; i = i - 2) {
+        wait(2);
+        printf("Waiting %d seconds...\n\r", i);
     }
-    */
-    
-    printf("Program Started\n\r");
     MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256);
     serial->baud(9600);
     Transport::setTransport(Transport::WIFI);
-    Client client;
-    //M2XStreamClient m2xClient(&client, key, "54.214.25.232");
-    M2XStreamClient m2xClient(&client, key);
     Wifi* wifi = Wifi::getInstance();
     printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE");
-    printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork("Multi-Tech", Wifi::WPA2, "VivaLasVegas2014")).c_str());
-    //printf("Set Static: %s\n\r", getCodeNames(wifi->setDeviceIP("192.168.18.164")).c_str());
+    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
     
     /* send some data */
+    Client client;
+    M2XStreamClient m2xClient(&client, key);
     int ret;
     int num;
     while (true) {