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: HTTPServer WIZnetInterface mbed-rpc DHT mbed-src
Diff: main.cpp
- Revision:
- 1:cffa64d79a8b
- Parent:
- 0:ca442200bc8a
diff -r ca442200bc8a -r cffa64d79a8b main.cpp
--- a/main.cpp Wed Jul 22 09:41:02 2015 +0000
+++ b/main.cpp Thu Jul 30 02:31:11 2015 +0000
@@ -2,16 +2,44 @@
#include "EthernetInterface.h"
#include "HTTPServer.h"
#include "mbed_rpc.h"
+#include "DHT.h"
+
+RpcDigitalOut led1(D9,"led1");
+RpcDigitalOut led2(D10,"led2");
+RpcDigitalOut led3(D11,"led3");
-RpcDigitalOut led1(LED1,"led1");
+//RPCVarialbe<float> RPCTemperature(&GetTemperature, "Temperature");
+//RPCVarialbe<float> RPCHumidity(&GetHumidity, "Humidity");
+void Get_Temp_and_Humidity(Arguments * input, Reply * output);
+
+RPCFunction Temp_and_Humidity_Finder(&Get_Temp_and_Humidity, "Temp_and_Humidity_Finder");
EthernetInterface eth;
HTTPServer svr;
+DHT sensor(D4, DHT11);
+
+void Get_Temp_and_Humidity(Arguments * input, Reply *output){
+ int error = 0;
+ float h = 0.0f, c = 0.0f;
+ char arg[100];
+
+ error = sensor.readData();
+ if (0 == error) {
+ c = sensor.ReadTemperature(CELCIUS);
+ h = sensor.ReadHumidity();
+ sprintf(arg,"Temperature in Celcius: %4.2f, Humidity is %4.2f",c, h);
+
+ output->putData(arg);
+ }
+}
+
int main() {
//Turn the LEDs off
- uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x00, 0x00};
- led1.write(1);
+ uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x32, 0x23, 0x42};
+ led1.write(0);
+ led2.write(0);
+ led3.write(0);
RPC::add_rpc_class<RpcDigitalOut>();
@@ -23,13 +51,11 @@
printf("Error %d in setup.\n", ethErr);
return -1;
}
-
svr.addHandler<HTTPRpcRequestHandler>("/rpc");
//attach server to port 80
+ printf("Listening...\n");
svr.start(80, ð);
-
- printf("Listening...\n");
Timer tm;
tm.start();
@@ -42,4 +68,4 @@
tm.start();
}
}
-}
\ No newline at end of file
+}