A basic example of using the mbed NXP LPC1768 Application Board with Exosite.

Dependencies:   C12832_lcd EthernetInterface HTTPClient LM75B MMA7660 RGBLed mbed-rtos mbed

Fork of exosite_http_example by Patrick Barrett

Files at this revision

API Documentation at this revision

Comitter:
maanenson
Date:
Fri May 02 14:53:22 2014 +0000
Child:
1:ae20607dd0c1
Commit message:
first commit, not working

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
LM75B.lib Show annotated file Show diff for this revision Revisions of this file
MMA7660.lib Show annotated file Show diff for this revision Revisions of this file
RgbLED.lib Show annotated file Show diff for this revision Revisions of this file
Socket.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
nsdl_lib.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#f6ec7a025939
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.lib	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/chris/code/LM75B/#6a70c9303bbe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA7660.lib	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MMA7660/#a8e20db7901e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RgbLED.lib	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/vandep01/code/RgbLED/#396b3f9574ea
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Socket.lib	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/Socket/#434906b5b977
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,100 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+
+EthernetInterface eth;  
+
+string CIK = "996a6abfb619711dbf3532cc82a6df6513821532";  // copy Device CIK from Portals
+
+AnalogIn aPot1(p19);
+Timer t;
+
+int main() {
+    t.start();
+    
+    printf("\r\nStart\n");
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("\r\nSetting up...\r\n");
+    printf("IP Address is %s\n", eth.getIPAddress());
+    printf("MAC Address is %s\n", eth.getMACAddress());
+    printf("\r\nSetup OK\r\n");
+    
+
+    int ping = 0;
+    
+    while (1) {
+        wait(20);
+
+        float totalPot1 = 0;
+        float avgPot1 = 0;
+        for (int i = 0; i<30; i++) {
+            totalPot1 += abs(aPot1);
+        }
+        avgPot1 = totalPot1/30;
+        printf("Pot1 Value: %03f \r\n", avgPot1);
+        
+        float newTime = t.read();
+        printf("Current Time: %f \r\n",newTime);
+        
+        if (newTime  > 320) {
+            t.reset();
+            ping ++;
+            if (ping > 100) {
+                ping = 1;
+            }
+            char data [70];
+            int len = sprintf(data, "ping=%d&power=%03f",ping,avgPot1);
+            
+            TCPSocketConnection sock;
+            sock.connect("m2.exosite.com/", 80);
+    
+            char http_cmd[] = "GET /api:v1/stack/alias HTTP/1.1\r\n";
+            sock.send_all(http_cmd, sizeof(http_cmd)-1);
+            char http_format[] = "application/x-www-form-urlencoded; charset=utf-8";
+            sock.send_all(http_format, sizeof(http_format)-1);
+            
+            
+            char buffer[300];
+            int ret;
+            while (true) {
+                ret = sock.receive(buffer, sizeof(buffer)-1);
+                if (ret <= 0)
+                    break;
+                buffer[ret] = '\0';
+                printf("Received %d chars from server:\n%s\n", ret, buffer);
+            }
+              
+            sock.close();
+            
+            eth.disconnect();
+            
+            HTTPClient http;
+            http.setRequestHeader("X-Exosite-CIK", CIK);
+            
+            HTTPText Content("application/x-www-form-urlencoded; charset=utf-8");
+            Content.set(data);
+            string uri = "http://m2.exosite.com/api:v1/stack/alias";    // uri for post includes feed ID  // uri for post includes feed ID
+            
+            printf("Sending Data to Exosite...");
+            HTTPResult result = http.post(uri.c_str(), Content, NULL);
+            // result should be 0 and response should be 200 for successful post
+            int response = http.getHTTPResponseCode();
+            if (result==HTTP_OK) {
+                printf("done\r\n");
+                //printf("Response: %d\n",response);
+            } else {
+                if (response == 204) { //expected No Content (204) error
+                    printf("done\r\n");
+                    //printf("Response: %d\n",response);
+                } else {
+                    printf("failed\r\n");
+                    printf("Error %d\r\n", result);
+                    printf("Response: %d\r\n",response);
+                }
+            }
+        }
+    }
+
+    return 0;
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8a40adfe8776
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nsdl_lib.lib	Fri May 02 14:53:22 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Sensinode/code/nsdl_lib/#050d0f54a0dc