Bhavin Darji / Mbed 2 deprecated m2x-demo-all_mbed1768

Dependencies:   EthernetInterface M2XStreamClient jsonlite mbed-rtos mbed

Fork of m2x-demo-all by AT&T M2X Team

Files at this revision

API Documentation at this revision

Comitter:
brdarji
Date:
Thu Mar 22 07:57:42 2018 +0000
Parent:
0:38a7a8cae773
Commit message:
At&T example lpc1768

Changed in this revision

LM75B.lib Show diff for this revision Revisions of this file
M2XStreamClient.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 38a7a8cae773 -r 88ff5e1fd66f LM75B.lib
--- a/LM75B.lib	Fri Feb 21 21:12:15 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/chris/code/LM75B/#6a70c9303bbe
diff -r 38a7a8cae773 -r 88ff5e1fd66f M2XStreamClient.lib
--- a/M2XStreamClient.lib	Fri Feb 21 21:12:15 2014 +0000
+++ b/M2XStreamClient.lib	Thu Mar 22 07:57:42 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/ATT-M2X-team/code/M2XStreamClient/#f479e4f4db0e
+http://mbed.org/teams/ATT-M2X-team/code/M2XStreamClient/#4d895e732765
diff -r 38a7a8cae773 -r 88ff5e1fd66f main.cpp
--- a/main.cpp	Fri Feb 21 21:12:15 2014 +0000
+++ b/main.cpp	Thu Mar 22 07:57:42 2018 +0000
@@ -1,75 +1,42 @@
+#define MBED_PLATFORM
+
 #include <jsonlite.h>
 #include "M2XStreamClient.h"
 
 #include "mbed.h"
 #include "EthernetInterface.h"
-#include "LM75B.h"  //I2C Temperature Sensor
+
+char deviceId[] = "8f4eeb39f1cb1dc95699bfa266e57662"; // Device you want to push to
+char streamName[] = "temp_data"; // Stream you want to push to
+char m2xKey[] = "4c3ba5e22fc074d4358888afbe96efa7"; // Your M2X API Key or Master API Key
 
-char feedId[] = "<feed id>"; // Feed you want to post to
-char m2xKey[] = "<m2x api key>"; // Your M2X access key
-char streamName[] = "<stream name>"; // Stream you want to post to
-
-char name[] = "<location name>"; // Name of current location of datasource
-double latitude = 33.007872;
-double longitude = -96.751614; // You can also read those values from a GPS
-double elevation = 697.00;
+// For Static IP
+static const char* mbedIp       = "192.168.0.85";  //IP
+static const char* mbedMask     = "255.255.255.0";  // Mask
+static const char* mbedGateway  = "192.168.0.254";  //Gateway
 
 Client client;
 M2XStreamClient m2xClient(&client, m2xKey);
 
 EthernetInterface eth;
-LM75B tmp(p28,p27);         // I2C Temperature Sensor
 
-void on_data_point_found(const char* at, const char* value, int index, void* context) {
-  printf("Found a data point, index: %d\r\n", index);
-  printf("At: %s Value: %s\r\n", at, value);
-}
-
-void on_location_found(const char* name,
-                       double latitude,
-                       double longitude,
-                       double elevation,
-                       const char* timestamp,
-                       int index,
-                       void* context) {
-  printf("Found a location, index: %d\r\n", index);
-  printf("Name: %s  Latitude: %lf  Longitude: %lf\r\n", name, latitude, longitude);
-  printf("Elevation: %lf  Timestamp: %s\r\n", elevation, timestamp);
-}
 
 int main() {
-  eth.init();
+  float data = 32.5;
+   
+  eth.init(mbedIp,mbedMask,mbedGateway);
   eth.connect();
-  printf("IP Address: %s\r\n", eth.getIPAddress());
+  printf("IP Address: %s\n", eth.getIPAddress());
 
-  char amb_temp[6];
-  
   while (true) {
-  
-    // read temp
-    sprintf(amb_temp, "%0.2f", tmp.read());
-    
-    // post temperature
-    int response = m2xClient.post(feedId, streamName, amb_temp);
-    printf("Post response code: %d\r\n", response);
-    if (response == -1) while (true) ;
-    
-    // read temperature
-    response = m2xClient.fetchValues(feedId, streamName, on_data_point_found, NULL);
-    printf("Fetch response code: %d\r\n", response);
-    if (response == -1) while (true) ;
-    
-    // update location
-    response = m2xClient.updateLocation(feedId, name, latitude, longitude, elevation);
-    printf("updateLocation response code: %d\r\n", response);
-    if (response == -1) while (true) ;
-    
-    // read location
-    response = m2xClient.readLocation(feedId, on_location_found, NULL);
-    printf("readLocation response code: %d\r\n", response);
+    double val = data;
+    printf("Current temperature is: %lf", val);
+
+    int response = m2xClient.updateStreamValue(deviceId, streamName, val);
+    printf("Response code: %d\n", response);
+
     if (response == -1) while (true) ;
 
-    // wait 60 secs and then loop
-    delay(60000);
+    delay(5000);
   }
 }
\ No newline at end of file