Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterfaceWithHostname HygroClip2-LPC mbed-rtos mbed
Fork of TCPSocket_HelloWorld by
Revision 17:85a4dfbe02cb, committed 2016-05-02
- Comitter:
- wolfsberger
- Date:
- Mon May 02 14:09:38 2016 +0000
- Parent:
- 16:de05943e11c4
- Child:
- 18:0c2f6b8b9938
- Commit message:
- -
Changed in this revision
--- a/EthernetInterface.lib Tue Oct 20 02:03:15 2015 +0000 +++ b/EthernetInterface.lib Mon May 02 14:09:38 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f +http://mbed.org/users/mbed_official/code/EthernetInterface/#4d7bff17a592
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HygroClip2.lib Mon May 02 14:09:38 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/wolfsberger/code/HygroClip2/#b41e36e81711
--- a/main.cpp Tue Oct 20 02:03:15 2015 +0000
+++ b/main.cpp Mon May 02 14:09:38 2016 +0000
@@ -1,31 +1,91 @@
#include "mbed.h"
+#include "rtos.h"
#include "EthernetInterface.h"
+#include "HygroClip2.h"
+
+EthernetInterface eth;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+typedef struct {
+ float temperature;
+ float humidity;
+ float dewpoint;
+} SensorData;
+
+Mail<SensorData, 32> sensorMailBox;
+
+void network(void const * arg)
+{
+ while(true)
+ {
+ osEvent event = sensorMailBox.get();
+ if (event.status == osEventMail)
+ {
+ led3 = 1;
+ SensorData * data = static_cast<SensorData*>(event.value.p);
+
+ TCPSocketConnection sock;
+ int connected = sock.connect("192.168.100.100", 1337);
+ if (connected == 0)
+ {
+ char transmissionBuffer[300];
+ int lenght = snprintf(transmissionBuffer, 200, "GET /relay?temperature=%.2f&humidity=%.2f&dewpoint=%.2f&id=1 HTTP/1.0\n\n", data->temperature, data->humidity,data->dewpoint);
+ printf(transmissionBuffer);
+ sock.send_all(transmissionBuffer, lenght);
+ }
+ sock.close();
+
+ sensorMailBox.free(data);
+ led3 = 0;
+ }
+ }
+}
int main() {
- EthernetInterface eth;
- eth.init(); //Use DHCP
- eth.connect();
- printf("IP Address is %s\n", eth.getIPAddress());
+ // Start ethernet module
+ int initOK = eth.init();
+ if (initOK != 0)
+ {
+ while(true);
+ }
+
- TCPSocketConnection sock;
- sock.connect("mbed.org", 80);
+ // Connect to network
+ int connectOK = eth.connect();
+ if (connectOK != 0)
+ {
+ while(true);
+ }
+ led1 = 1;
- char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
- sock.send_all(http_cmd, sizeof(http_cmd)-1);
+ // Create and start ethernet task
+ Thread transmissionTask(network);
+ HygroClip2 sensor(p9,p10);
- 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(!sensor.isDataValid())
+ {
+ sensor.update();
+ Thread::wait(500);
}
-
- sock.close();
+ led2 = 1;
- eth.disconnect();
-
- while(1) {}
+ while(true)
+ {
+ led4 = 1;
+ if (sensor.isDataValid())
+ {
+ SensorData * data = sensorMailBox.alloc();
+ data->temperature = sensor.getTemperature();
+ data->humidity = sensor.getHumidity();
+ data->dewpoint = sensor.getDewPoint();
+ sensorMailBox.put(data);
+ }
+ sensor.update();
+ Thread::wait(50);
+ led4 = 0;
+ Thread::wait(9950);
+ }
}
--- a/mbed-rtos.lib Tue Oct 20 02:03:15 2015 +0000 +++ b/mbed-rtos.lib Mon May 02 14:09:38 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#12552ef4e980 +http://mbed.org/users/mbed_official/code/mbed-rtos/#bdd541595fc5
--- a/mbed.bld Tue Oct 20 02:03:15 2015 +0000 +++ b/mbed.bld Mon May 02 14:09:38 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/082adc85693f \ No newline at end of file
