Error with receive value from M2X, sharing it for debug purpose
Dependencies: SocketModem jsonlite mbed
Fork of MTS_M2x_Example by
main.cpp@7:d465bf432ce6, 2014-01-05 (annotated)
- Committer:
- k4r7h1k
- Date:
- Sun Jan 05 16:13:15 2014 +0000
- Revision:
- 7:d465bf432ce6
- Parent:
- 6:0dbcf434679b
M2X Receive error
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:032beb056844 | 1 | #include "mbed.h" |
mfiore | 0:032beb056844 | 2 | #include "M2XStreamClient.h" |
mfiore | 0:032beb056844 | 3 | #include "include_me.h" |
mfiore | 0:032beb056844 | 4 | |
mfiore | 0:032beb056844 | 5 | using namespace mts; |
k4r7h1k | 7:d465bf432ce6 | 6 | Serial pc(USBTX, USBRX); // tx, rx |
k4r7h1k | 7:d465bf432ce6 | 7 | DigitalOut myled(LED1); |
k4r7h1k | 7:d465bf432ce6 | 8 | DigitalOut myled2(LED2); |
mfiore | 0:032beb056844 | 9 | |
k4r7h1k | 7:d465bf432ce6 | 10 | const char key[] = "12988a511467b0686dad762d456cb5fc"; // enter your m2x user account master key |
k4r7h1k | 7:d465bf432ce6 | 11 | const char feed[] = "1e93ba89b35bc96e32fac1c43cc1d9f5"; // enter your blueprint feed id |
sam_grove | 3:d24e8bec5610 | 12 | const char stream[] = "amb-temp"; // Create a stream name |
mfiore | 0:032beb056844 | 13 | |
mfiore | 1:b12a128aae0e | 14 | // set to 1 for cellular shield board |
mfiore | 1:b12a128aae0e | 15 | // set to 0 for wifi shield board |
k4r7h1k | 7:d465bf432ce6 | 16 | #define CELL_SHIELD 0 |
sam_grove | 2:76e0d5968991 | 17 | |
sam_grove | 3:d24e8bec5610 | 18 | // ssid and phrase for wifi |
sam_grove | 2:76e0d5968991 | 19 | std::string ssid = "belkin54g"; |
sam_grove | 3:d24e8bec5610 | 20 | std::string phrase = "hackathon"; |
mfiore | 5:d4a4e2577be3 | 21 | Wifi::SecurityType security_type = Wifi::WPA; |
k4r7h1k | 7:d465bf432ce6 | 22 | void on_data_point_found(const char* at, const char* value, int index, void* context) { |
k4r7h1k | 7:d465bf432ce6 | 23 | //pc.printf("Found a data point, index: %d\n", index); |
k4r7h1k | 7:d465bf432ce6 | 24 | //pc.printf("At: %s\n Value: %s\n", at, value); |
k4r7h1k | 7:d465bf432ce6 | 25 | } |
sam_grove | 3:d24e8bec5610 | 26 | int main() |
sam_grove | 3:d24e8bec5610 | 27 | { |
mfiore | 0:032beb056844 | 28 | MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256); |
mfiore | 0:032beb056844 | 29 | serial->baud(9600); |
mfiore | 0:032beb056844 | 30 | Transport::setTransport(Transport::WIFI); |
mfiore | 0:032beb056844 | 31 | Wifi* wifi = Wifi::getInstance(); |
k4r7h1k | 7:d465bf432ce6 | 32 | pc.printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE"); |
k4r7h1k | 7:d465bf432ce6 | 33 | pc.printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork(ssid, security_type, phrase)).c_str()); |
k4r7h1k | 7:d465bf432ce6 | 34 | pc.printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str()); |
k4r7h1k | 7:d465bf432ce6 | 35 | pc.printf("Signal Strnegth (dBm): %d\n\r", wifi->getSignalStrength()); |
k4r7h1k | 7:d465bf432ce6 | 36 | pc.printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); |
k4r7h1k | 7:d465bf432ce6 | 37 | pc.printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure"); |
k4r7h1k | 7:d465bf432ce6 | 38 | pc.printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); |
k4r7h1k | 7:d465bf432ce6 | 39 | |
sam_grove | 3:d24e8bec5610 | 40 | |
mfiore | 0:032beb056844 | 41 | /* send some data */ |
mfiore | 1:b12a128aae0e | 42 | Client client; |
mfiore | 1:b12a128aae0e | 43 | M2XStreamClient m2xClient(&client, key); |
mfiore | 0:032beb056844 | 44 | int ret; |
mfiore | 0:032beb056844 | 45 | while (true) { |
k4r7h1k | 7:d465bf432ce6 | 46 | |
k4r7h1k | 7:d465bf432ce6 | 47 | pc.printf("Receving\r\n"); |
k4r7h1k | 7:d465bf432ce6 | 48 | ret = m2xClient.receive(feed,stream,on_data_point_found,NULL); |
k4r7h1k | 7:d465bf432ce6 | 49 | pc.printf("receive status %d\r\n", ret); |
k4r7h1k | 7:d465bf432ce6 | 50 | // myled = 1; |
k4r7h1k | 7:d465bf432ce6 | 51 | // myled2=0; |
k4r7h1k | 7:d465bf432ce6 | 52 | // wait(0.2); |
k4r7h1k | 7:d465bf432ce6 | 53 | // myled = 0; |
k4r7h1k | 7:d465bf432ce6 | 54 | // myled2=1; |
k4r7h1k | 7:d465bf432ce6 | 55 | // wait(0.2); |
mfiore | 0:032beb056844 | 56 | } |
mfiore | 0:032beb056844 | 57 | } |