thermometer, hygrometer and barometer. Using VFD for display.

Dependencies:   AM2321 LPS331_I2C mbed-rtos mbed EthernetInterface

Files at this revision

API Documentation at this revision

Comitter:
mia_0032
Date:
Sat Nov 22 15:11:00 2014 +0000
Parent:
3:d48728390f04
Commit message:
fluentd?POST???????????

Changed in this revision

EthernetInterface.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 d48728390f04 -r 6e0a2e9fe23a EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Sat Nov 22 15:11:00 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#de796e2a5e98
diff -r d48728390f04 -r 6e0a2e9fe23a main.cpp
--- a/main.cpp	Sat Nov 15 03:49:54 2014 +0000
+++ b/main.cpp	Sat Nov 22 15:11:00 2014 +0000
@@ -1,7 +1,9 @@
 #include "mbed.h"
 #include "rtos.h"
+#include "EthernetInterface.h"
 #include "LPS331_I2C.h"
 #include "AM2321.h"
+#include <string>
 
 //for debug
 DigitalOut led1(LED1, 0);
@@ -10,7 +12,13 @@
 DigitalOut led4(LED4, 0);
 Serial pc(USBTX, USBRX);
 
-// for ethernet led
+// data
+float pressure = 0;
+float temperature = 0;
+float humidity = 0;
+
+// for ethernet
+EthernetInterface eth;
 DigitalIn lnk(P1_25);
 DigitalIn spd(P1_26);
 DigitalOut speed(p29);
@@ -21,6 +29,34 @@
     link = !lnk;
 }
 
+// for fluentd in_http
+void send_fluentd(const string host, const int port)
+{
+    TCPSocketConnection sock;
+    sock.connect(host.c_str(), port);
+
+    char post_data[128];
+    sprintf(post_data, "json={\"humid\":%d,\"temp\":%d,\"press\":%d}", (int)humidity, (int)temperature, (int)pressure);
+    pc.printf("POST Data:\r\n%s\r\n%d", post_data, strlen(post_data));
+    char http_cmd[512];
+    sprintf(http_cmd, "POST /mbed.climate HTTP/1.1\r\nHost: %s:%d\r\nAccept: */*\r\nContent-Length: %d\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n%s\r\n\r\n", host.c_str(), port, strlen(post_data), post_data);
+    pc.printf("Request:\r\n%s\r\n", http_cmd);
+    sock.send_all(http_cmd, sizeof(http_cmd)-1);
+
+    char buffer[1024];
+    int ret;
+    while (true) {
+        ret = sock.receive(buffer, sizeof(buffer)-1);
+        if (ret <= 0)
+            break;
+        buffer[ret] = '\0';
+        pc.printf("Received %d chars from server:\r\n%s\r\n", ret, buffer);
+    }
+
+    sock.close();
+}
+
+
 // for LPS331
 LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH);
 
@@ -37,8 +73,6 @@
     lps331.setActive(true);
 }
 
-float pressure = 0;
-
 void update_pressure()
 {
     led2 = !led2;
@@ -49,9 +83,6 @@
 // for AM2321
 AM2321 am2321(p9, p10);
 
-float temperature = 0;
-float humidity = 0;
-
 void update_temperature_and_humidity()
 {
     if(am2321.poll())
@@ -186,6 +217,8 @@
     // start ethernet
     RtosTimer flipper(flip, osTimerPeriodic, NULL);
     flipper.start(50);
+    eth.init();
+    eth.connect();
 
     // start auto mode change
     RtosTimer mode_changer(next_mode, osTimerPeriodic, NULL);
@@ -200,9 +233,11 @@
     Thread::wait(2000);
 
     while(1) {
-        update_pressure();
-        update_temperature_and_humidity();
-        
-        Thread::wait(1000);
+        for(int i=0;i < 30;i++){
+            update_pressure();
+            update_temperature_and_humidity();
+            Thread::wait(1000);
+        }
+        send_fluentd("192.168.10.100", 8888);
     }
 }