Error with receive value from M2X, sharing it for debug purpose

Dependencies:   SocketModem jsonlite mbed

Fork of MTS_M2x_Example by Multi-Hackers

Revision:
7:d465bf432ce6
Parent:
6:0dbcf434679b
--- a/main.cpp	Sun Jan 05 07:03:49 2014 +0000
+++ b/main.cpp	Sun Jan 05 16:13:15 2014 +0000
@@ -3,100 +3,55 @@
 #include "include_me.h"
 
 using namespace mts;
+Serial pc(USBTX, USBRX); // tx, rx
+DigitalOut myled(LED1);
+DigitalOut myled2(LED2);
 
-const char key[] = "";  // enter your m2x user account master key
-const char feed[] = ""; // enter your blueprint feed id
+const char key[] = "12988a511467b0686dad762d456cb5fc";  // enter your m2x user account master key
+const char feed[] = "1e93ba89b35bc96e32fac1c43cc1d9f5"; // enter your blueprint feed id
 const char stream[] = "amb-temp";   // Create a stream name
 
 // set to 1 for cellular shield board
 // set to 0 for wifi shield board
-#define CELL_SHIELD 1
+#define CELL_SHIELD 0
 
 // ssid and phrase for wifi
 std::string ssid = "belkin54g";
 std::string phrase = "hackathon";
 Wifi::SecurityType security_type = Wifi::WPA;
-
+void on_data_point_found(const char* at, const char* value, int index, void* context) {
+  //pc.printf("Found a data point, index: %d\n", index);
+  //pc.printf("At: %s\n Value: %s\n", at, value);
+}
 int main()
 {
-#if CELL_SHIELD
-    MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
-    serial->baud(115200);
-    Transport::setTransport(Transport::CELLULAR);
-    Cellular* cell = Cellular::getInstance();
-    cell->init(serial, PTA4, PTC9); //DCD and DTR pins for KL46Z
-
-    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(ssid, security_type, phrase)).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
+    pc.printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE");
+    pc.printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork(ssid, security_type, phrase)).c_str());
+    pc.printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str());
+    pc.printf("Signal Strnegth (dBm): %d\n\r", wifi->getSignalStrength());
+    pc.printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
+    pc.printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure");
+    pc.printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
+
 
     /* send some data */
     Client client;
     M2XStreamClient m2xClient(&client, key);
     int ret;
-    int num;
     while (true) {
-        num = rand();
-        printf("sending %d\r\n", num);
-        ret = m2xClient.send(feed, stream, num);
-        printf("send() returned %d\r\n", ret);
-        wait(5);
+    
+        pc.printf("Receving\r\n");
+        ret = m2xClient.receive(feed,stream,on_data_point_found,NULL);
+        pc.printf("receive status %d\r\n", ret);
+       // myled = 1;
+       // myled2=0;
+       // wait(0.2);
+       // myled = 0;
+       // myled2=1;
+       // wait(0.2);
     }
 }
\ No newline at end of file