start project for students

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPSocket_HelloWorld by mbed_example

Files at this revision

API Documentation at this revision

Comitter:
sillevl
Date:
Fri Nov 07 14:37:02 2014 +0000
Parent:
15:69e41cbbc8ac
Commit message:
temperature dashboard start for students

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Sep 21 05:55:13 2014 +0000
+++ b/main.cpp	Fri Nov 07 14:37:02 2014 +0000
@@ -1,31 +1,33 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
+#include "TempDashSocketConnection.h"
+#include "TemperatureSensor.h"
+#include <string.h>
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+std::string key = "";
+std::string name = "mbed";
+static const char SERVER[] = "labict.be";
+static const int PORT = 45678;
 
 int main() {
+    pc.baud(115200);
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
+    pc.printf("IP Address is %s\r\n", eth.getIPAddress());
     
-    TCPSocketConnection sock;
-    sock.connect("mbed.org", 80);
+    TemperatureSensor sensor(p28, p27, key, name);
     
-    char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
-    sock.send_all(http_cmd, sizeof(http_cmd)-1);
+    TempDashSocketConnection sock;
     
-    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);
+    while(1) {
+        if (sensor.open()) {
+            sock.connect(SERVER, PORT);
+            sock.sendSensorData(sensor.getDataPacket());            
+            sock.close();
+            wait(1.0);
+        }
     }
-      
-    sock.close();
-    
     eth.disconnect();
-    
-    while(1) {}
 }