Error with receive value from M2X, sharing it for debug purpose
Dependencies: SocketModem jsonlite mbed
Fork of MTS_M2x_Example by
main.cpp
00001 #include "mbed.h" 00002 #include "M2XStreamClient.h" 00003 #include "include_me.h" 00004 00005 using namespace mts; 00006 Serial pc(USBTX, USBRX); // tx, rx 00007 DigitalOut myled(LED1); 00008 DigitalOut myled2(LED2); 00009 00010 const char key[] = "12988a511467b0686dad762d456cb5fc"; // enter your m2x user account master key 00011 const char feed[] = "1e93ba89b35bc96e32fac1c43cc1d9f5"; // enter your blueprint feed id 00012 const char stream[] = "amb-temp"; // Create a stream name 00013 00014 // set to 1 for cellular shield board 00015 // set to 0 for wifi shield board 00016 #define CELL_SHIELD 0 00017 00018 // ssid and phrase for wifi 00019 std::string ssid = "belkin54g"; 00020 std::string phrase = "hackathon"; 00021 Wifi::SecurityType security_type = Wifi::WPA; 00022 void on_data_point_found(const char* at, const char* value, int index, void* context) { 00023 //pc.printf("Found a data point, index: %d\n", index); 00024 //pc.printf("At: %s\n Value: %s\n", at, value); 00025 } 00026 int main() 00027 { 00028 MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256); 00029 serial->baud(9600); 00030 Transport::setTransport(Transport::WIFI); 00031 Wifi* wifi = Wifi::getInstance(); 00032 pc.printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE"); 00033 pc.printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork(ssid, security_type, phrase)).c_str()); 00034 pc.printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str()); 00035 pc.printf("Signal Strnegth (dBm): %d\n\r", wifi->getSignalStrength()); 00036 pc.printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); 00037 pc.printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure"); 00038 pc.printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); 00039 00040 00041 /* send some data */ 00042 Client client; 00043 M2XStreamClient m2xClient(&client, key); 00044 int ret; 00045 while (true) { 00046 00047 pc.printf("Receving\r\n"); 00048 ret = m2xClient.receive(feed,stream,on_data_point_found,NULL); 00049 pc.printf("receive status %d\r\n", ret); 00050 // myled = 1; 00051 // myled2=0; 00052 // wait(0.2); 00053 // myled = 0; 00054 // myled2=1; 00055 // wait(0.2); 00056 } 00057 }
Generated on Wed Jul 20 2022 00:03:18 by 1.7.2