![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
I added functionality to get the RSSI, BER, and Cell Neighbor for reporting connection issues to M2X
Dependencies: mbed FXOS8700CQ mbed-rtos WNCInterface M2XStreamClient-JMF jsonlite
Diff: main.cpp
- Revision:
- 2:eb0768c06c1b
- Parent:
- 1:1c840717deea
- Child:
- 4:08979e323c6e
--- a/main.cpp Tue Sep 27 20:02:21 2016 +0000 +++ b/main.cpp Fri Oct 07 01:05:11 2016 +0000 @@ -42,14 +42,14 @@ MODSERIAL pc(USBTX,USBRX,256,256); void on_data_point_found(const char* at, const char* value, int index, void* context, int type) { - printf(">>Found a data point, index: %d type: %d" CRLF, index, type); - printf(">>At: %s" CRLF " Value: %s" CRLF, at, value); + pc.printf(">>Found a data point, index: %d type: %d" CRLF, index, type); + pc.printf(">>At: %s" CRLF " Value: %s" CRLF, at, value); } void on_command_found(const char* id, const char* name, int index, void *context) { - printf(">>Found a command, index: %d" CRLF, index); - printf(">>ID: %s\n Name: %s" CRLF, id, name); + pc.printf(">>Found a command, index: %d" CRLF, index); + pc.printf(">>ID: %s\n Name: %s" CRLF, id, name); } void on_location_found(const char* name, @@ -59,9 +59,9 @@ const char* timestamp, int index, void* context) { - printf(">>Found a location, index: %d" CRLF, index); - printf(">>Name: %s" CRLF ">>Latitude: %lf" CRLF ">>Longitude: %lf" CRLF, name, latitude, longitude); - printf(">>Elevation: %lf" CRLF ">>Timestamp: %s" CRLF, elevation, timestamp); + pc.printf(">>Found a location, index: %d" CRLF, index); + pc.printf(">>Name: %s" CRLF ">>Latitude: %lf" CRLF ">>Longitude: %lf" CRLF, name, latitude, longitude); + pc.printf(">>Elevation: %lf" CRLF ">>Timestamp: %s" CRLF, elevation, timestamp); } int main() { @@ -74,43 +74,43 @@ double humid=0.00; //we will just increment these 1 each time through the loop wrapping at 100 pc.baud(115200); - printf("Start m2x-demo-all by initializng the network" CRLF); + pc.printf("Start m2x-demo-all by initializng the network" CRLF); response = eth.init(); - printf("WNC Module %s initialized (%02X)." CRLF, response?"IS":"IS NOT", response); + pc.printf("WNC Module %s initialized (%02X)." CRLF, response?"IS":"IS NOT", response); if( !response ) { - printf(" - - - - - - - ALL DONE - - - - - - - " CRLF); + pc.printf(" - - - - - - - ALL DONE - - - - - - - " CRLF); while(1); } - response = eth.connect(); - printf("IP Address: %s " CRLF CRLF, eth.getIPAddress()); + response = eth.connect(); + pc.printf("IP Address: %s " CRLF CRLF, eth.getIPAddress()); - printf("initialize the M2X time service" CRLF); + pc.printf("initialize the M2X time service" CRLF); if (!m2x_status_is_success(timeService.init())) - printf("Cannot initialize time service!" CRLF); + pc.printf("Cannot initialize time service!" CRLF); else { - timeService.getTimestamp(timestamp, &length); - printf("Current timestamp: %s" CRLF, timestamp); - strcpy(endTime,timestamp); + timeService.getTimestamp(timestamp, &length); + pc.printf("Current timestamp: %s" CRLF, timestamp); + strcpy(endTime,timestamp); } - printf("Now delete all existing values" CRLF); + pc.printf("Now delete all existing values" CRLF); // Delete values - printf("Delete humidity values..." CRLF); + pc.printf("Delete humidity values..." CRLF); response = m2xClient.deleteValues(deviceId,hstreamName, fromTime, endTime); - printf("Delete response code: %d" CRLF, response); + pc.printf("Delete response code: %d" CRLF, response); - printf("Delete temp values..." CRLF); + pc.printf("Delete temp values..." CRLF); response = m2xClient.deleteValues(deviceId,tstreamName, fromTime, endTime); - printf("Delete response code: %d" CRLF, response); + pc.printf("Delete response code: %d" CRLF, response); - printf("Delete location values..." CRLF); + pc.printf("Delete location values..." CRLF); response = m2xClient.deleteLocations(deviceId, fromTime, endTime); - printf("Delete response code: %d" CRLF, response); + pc.printf("Delete response code: %d" CRLF, response); - printf("Query for possible commands using this device..." CRLF); + pc.printf("Query for possible commands using this device..." CRLF); response = m2xClient.listCommands(deviceId, on_command_found, NULL); - printf("listCommands response code: %d" CRLF, response); + pc.printf("listCommands response code: %d" CRLF, response); while (true) { // read temp -- for now, just use a fixed temp, but will need to read the HTS221 @@ -120,46 +120,46 @@ temp += .01; humid += 1.0; humid = fmod(humid,100.0); - printf("cnt=%d\r\n",cnt++); + pc.printf("cnt=%d\r\n",cnt++); // post the humidity value - printf("Post updateStreamValue (humidity)..." CRLF); + pc.printf("Post updateStreamValue (humidity)..." CRLF); response = m2xClient.updateStreamValue(deviceId, "humidity", humid); - printf("Post response code: %d" CRLF, response); + pc.printf("Post response code: %d" CRLF, response); // post the temp value - printf("Post updateStreamValue (temp)..." CRLF); + pc.printf("Post updateStreamValue (temp)..." CRLF); response = m2xClient.updateStreamValue(deviceId, "temperature", temp); - printf("Post response code: %d" CRLF, response); + pc.printf("Post response code: %d" CRLF, response); // read temperature - printf("listStreamValues (temp)..." CRLF); + pc.printf("listStreamValues (temp)..." CRLF); response = m2xClient.listStreamValues(deviceId, tstreamName, on_data_point_found, NULL); - printf("listStreamValues response code: %d" CRLF, response); + pc.printf("listStreamValues response code: %d" CRLF, response); if (response == -1) while (true) ; // read temperature - printf("listStreamValues (humid)..." CRLF); + pc.printf("listStreamValues (humid)..." CRLF); response = m2xClient.listStreamValues(deviceId, hstreamName, on_data_point_found, NULL); - printf("listStreamValues response code: %d" CRLF, response); + pc.printf("listStreamValues response code: %d" CRLF, response); if (response == -1) while (true) ; // update location - printf("updateLocation..." CRLF); + pc.printf("updateLocation..." CRLF); response = m2xClient.updateLocation(deviceId, name, latitude, longitude, elevation); - printf("updateLocation response code: %d" CRLF, response); + pc.printf("updateLocation response code: %d" CRLF, response); if (response == -1) while (true) ; // read location - printf("readLocation..." CRLF); + pc.printf("readLocation..." CRLF); int response = m2xClient.readLocation(deviceId, on_location_found, NULL); - printf("readLocation response code: %d" CRLF, response); + pc.printf("readLocation response code: %d" CRLF, response); - printf("PostDeviceUpdates..." CRLF); + pc.printf("PostDeviceUpdates..." CRLF); response = m2xClient.postDeviceUpdates(deviceId, 2, streamNames, counts, ats, values); - printf("Post response code: %d" CRLF, response); + pc.printf("Post response code: %d" CRLF, response); timeService.getTimestamp(timestamp, &length); - printf("Thats all folks, got to wait 60 seconds... (%s)" CRLF CRLF CRLF, timestamp); + pc.printf("Thats all folks, got to wait 60 seconds... (%s)" CRLF CRLF CRLF, timestamp); // wait 60 secs and then loop delay(6000);