Transmit pressure/temperature reading once per hour from xDot to iupivot server
Dependencies: ATParser MPL3115A2 mbed
Diff: main.cpp
- Revision:
- 3:59fbf4f41f69
- Parent:
- 2:9af94ceb9d37
- Child:
- 4:9235d082b6a3
--- a/main.cpp Thu Apr 05 14:56:40 2018 +0000 +++ b/main.cpp Fri Apr 06 15:24:35 2018 +0000 @@ -13,32 +13,38 @@ confirm that operation has succeeded */ int confirmOK() { + // Wait until device has a response while (!device.readable()) { wait_ms(100); } int bufferSize = 100; char buf[bufferSize]; - int i = 0; - for (i = 0; i < bufferSize; i++) { + int i = 0; + for (i = 0; i < bufferSize; i++) { buf[i] = 0; } i = 0; - // Wait until device has a response + + //Read message from device into buffer for (i = 0; device.readable(); i++) { buf[i] = device.getc(); + if (buf[i] == '\n') { + // Read new line so check to see if we got an OK or Error + // else keep reading til we get one + if (!strncmp("OK",buf,2)) { + //pc.printf("I compared against %s and got OK\r\n",buf); + return 1; + } else if (!strncmp("ERROR",buf,5)) { + //pc.printf("I compared against %s and got ERROR\r\n",buf); + return 0; + } + return confirmOK(); + } if (i >= bufferSize) { return 0; } } - pc.printf("I got %s from the device\r\n", buf); - wait_ms(100); - if (strncmp("OK",buf,2)) { - return 1; - } else if (strncmp("ERROR",buf,5)) { - return 0; - } else { - confirmOK(); - } + return 0; } /* Sends a message to the xDot Messages are expected to end in \n so that an OK confirmation will be