Upload to cosm (pachube) from mbed. (No LCD)

Dependencies:   EthernetInterface WebSocketClient mbed-rtos mbed

Upload to cosm (pachube) from mbed. thank you for http://mbed.org/forum/bugs-suggestions/topic/3956/ thread.

Use AMS302,LM61BIZ,CHS-GSS.

Use LCD, SCP-1000 version is here. http://mbed.org/users/kumajoi/code/ku-make_sensor/

Files at this revision

API Documentation at this revision

Comitter:
kumajoi
Date:
Thu Dec 06 18:45:22 2012 +0000
Commit message:
for MakeFaireTokyo2012

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
WebSocketClient.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	Thu Dec 06 18:45:22 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#a0ee3ae75cfa
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebSocketClient.lib	Thu Dec 06 18:45:22 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/samux/code/WebSocketClient/#86e89a0369b9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 06 18:45:22 2012 +0000
@@ -0,0 +1,60 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "Websocket.h"
+
+DigitalOut myled(LED1);
+AnalogIn light_in(p20);
+AnalogIn temp_in(p19);
+AnalogIn humid_in(p18);
+ 
+int main()
+{
+    const char apikey[] = "xxxxxxxxxxxxxxxxxxxxxxx"; // your apikey
+    const char feed[]= "/feeds/00000"; // //your feed URL
+    char cms[512];
+    char recv[512];
+    int token = 0;
+    EthernetInterface eth;
+    eth.init();
+    eth.connect();
+    wait(5);
+    printf("IP Address is %s\n\r", eth.getIPAddress());
+    
+    while (1) {
+    Websocket ws("ws://api.cosm.com:8080/feeds/");
+    ws.connect();
+    if(ws.read(recv)) {
+        printf("rcv: %s\r\n", recv);
+    }
+   
+    float r_light, r_temp, r_humid;
+    float light, temp, humid;
+    
+    light = light_in;
+    temp = temp_in;
+    humid = humid_in;
+    
+    r_light = light * 3.3 * 5 / 0.013;
+    r_temp = temp * 3.3 * 100 - 60;
+    r_humid = humid * 3.3 * 100;
+
+    myled = 1;
+    sprintf (cms,"{\"method\" : \"put\",\"resource\" : \"%s\",\"params\" : {},\"headers\" : {\"X-ApiKey\":\"%s\"},\"body\" :{\"version\" : \"1.0.0\",\"datastreams\" : [{\"id\" : \"0\",\"current_value\" : \"%4.0f\"},{\"id\" : \"1\",\"current_value\" : \"%3.0f\"},{\"id\" : \"2\",\"current_value\" : \"%3.0f\"}]},\"token\" : \"0x%d\"}\r\n",feed,apikey,r_light,r_temp,r_humid,token);
+    //set your ID and value
+    printf ("%s\r\n",cms);
+    token++;
+    int res = ws.send(cms);
+    myled= 0 ;
+    wait(5);
+ 
+ 
+    if(ws.read(recv)) {
+        printf("rcv: %s\r\n", recv);
+        wait(1);
+    }
+        
+    ws.close();
+    wait(300);
+ 
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Thu Dec 06 18:45:22 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#88a1a9c26ae3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Dec 06 18:45:22 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1
\ No newline at end of file