A ShipIoT tutorial for connecting a FRDM-K64F to bip.io

Dependencies:   EthernetInterface FXOS8700Q mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
cthulhuology
Date:
Mon Aug 17 14:46:26 2015 +0000
Commit message:
Initial Release

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
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Mon Aug 17 14:46:26 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXOS8700Q.lib	Mon Aug 17 14:46:26 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/Freescale/code/FXOS8700Q/#aee7dea904e2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Aug 17 14:46:26 2015 +0000
@@ -0,0 +1,60 @@
+#include <mbed.h>
+#include <EthernetInterface.h>
+#include "FXOS8700Q.h"
+
+int main(int argc, char** argv) {
+    
+    int16_t X, Y, Z;
+    
+    Serial pc(USBTX, USBRX);
+    pc.baud(115200);
+    
+    I2C i2c(PTE25,PTE24);
+    FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1);
+    acc.enable();
+    
+    pc.printf("Welcome to the FRDM + Bipio\r\n");
+    
+    EthernetInterface eth;
+    eth.init();
+    eth.connect();
+    
+    pc.printf("IP Addr: %s\r\n", eth.getIPAddress());
+    
+    while(true) {
+      pc.printf("Polling x,y,z\r\n");
+      TCPSocketConnection sock;
+      sock.connect("david.api.shipiot.net",80);
+      
+      acc.getX(X);   
+      acc.getY(Y);   
+      acc.getZ(Z); 
+      
+      char http_request[] =     "POST /bip/http/accel HTTP/1.1\r\n"
+                                "Host: username.api.shipiot.net\r\n"            // change the username to your username
+                                "Content-Type: application/json\r\n"
+                                "Content-Length: %d\r\n"
+                                "Authorization: Basic dGVzdDp0ZXN0\r\n"         // change the dGVzdDp0ZXN0 to your auth token
+                                "\r\n"
+                                "%s";
+                                
+       char buffer[255];
+       char json[] = "{ \"x\": %d, \"y\": %d, \"z\": %d }";
+       
+       sprintf(buffer,json,X,Y,Z);
+       
+       char request[512];
+       
+       sprintf(request,http_request,strlen(buffer), buffer);
+       
+       sock.send_all(request, strlen(request));
+       
+       pc.printf(buffer);
+       
+       sock.close();
+       
+       wait(1.0);              
+        
+    }
+    // should never get here...
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Aug 17 14:46:26 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#21b438192b0f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Aug 17 14:46:26 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b9ad9a133dc7
\ No newline at end of file