Demo app to read data from FXOS8700Q accelerometer on FRDM-K64F and send values to AT&T M2X Data Service. For use with DevLab

Dependencies:   EthernetInterface FXOS8700Q M2XStreamClient jsonlite mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
jb8414
Date:
Tue Aug 05 14:46:55 2014 +0000
Commit message:
initial commit

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
FXOS8700Q.lib Show annotated file Show diff for this revision Revisions of this file
M2XStreamClient.lib Show annotated file Show diff for this revision Revisions of this file
jsonlite.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r ece599ab76bb EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Tue Aug 05 14:46:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#f69b81aa9eb1
diff -r 000000000000 -r ece599ab76bb FXOS8700Q.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXOS8700Q.lib	Tue Aug 05 14:46:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JimCarver/code/FXOS8700Q/#5553a64d0762
diff -r 000000000000 -r ece599ab76bb M2XStreamClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/M2XStreamClient.lib	Tue Aug 05 14:46:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ATT-M2X-team/code/M2XStreamClient/#f479e4f4db0e
diff -r 000000000000 -r ece599ab76bb jsonlite.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jsonlite.lib	Tue Aug 05 14:46:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/citrusbyte/code/jsonlite/#807034181e02
diff -r 000000000000 -r ece599ab76bb main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 05 14:46:55 2014 +0000
@@ -0,0 +1,66 @@
+#include "mbed.h"
+#include "FXOS8700Q.h"
+#include "M2XStreamClient.h"
+#include "EthernetInterface.h"
+
+
+#ifndef MAX
+#define max(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
+#endif
+
+#ifndef MIN
+#define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
+#endif
+
+const char key[] = "<key>";       // Replace with your M2X user account master key
+const char feed[] = "<feed>";     // Replace with your blueprint feed ID
+const char stream[] = "<stream>"; // Replace with your stream name
+
+int main()
+{
+    // Setup Ethernet
+    printf("Start\r\n");
+    EthernetInterface eth;
+    printf("Init...\r\n");
+    eth.init(); //Use DHCP
+    //eth.init(ip,mask,gateway); //Use Static IP Configuration
+    printf("Connect\r\n");
+    eth.connect();
+    printf("Device IP Address is %s\r\n", eth.getIPAddress());
+
+    // Initialize the M2X client
+    Client client;
+    M2XStreamClient m2xClient(&client, key);
+    int ret;
+
+    // Create an accelerometer instance
+    FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board
+    acc.enable();
+    printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI());
+
+    while (true) {
+
+        float x, y, z;
+        acc.getX(&x);
+        acc.getY(&y);
+        acc.getZ(&z);
+
+        printf("Accel X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", x, y, z);
+
+        // Calculate pitch and roll. Find the maximum tilt angle.
+        float pitch = atan(x / sqrt(y * y + z * z));
+        float roll = atan(y / sqrt(x * x + z * z));
+        float maxTilt =
+            max(abs(roll), abs(pitch)) * 180.0 / 3.14159;
+        printf("pitch: %5.1f roll: %5.1f maxTilt: %5.1f\n\r",
+               pitch, roll, maxTilt);
+
+        // If the maximum title is over 20 degrees, then send
+        // data to stream
+        if (maxTilt > 20) {
+            ret = m2xClient.post(feed, stream, maxTilt);
+            printf("send() returned %d\r\n", ret);
+            // wait(0.5);
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r ece599ab76bb mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Aug 05 14:46:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#34e80e862021
diff -r 000000000000 -r ece599ab76bb mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Aug 05 14:46:55 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804
\ No newline at end of file