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
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "HTTPServer.h" 00004 #include "mbed_rpc.h" 00005 #include "DHT.h" 00006 00007 RpcDigitalOut led1(D9,"led1"); 00008 RpcDigitalOut led2(D10,"led2"); 00009 RpcDigitalOut led3(D11,"led3"); 00010 00011 //RPCVarialbe<float> RPCTemperature(&GetTemperature, "Temperature"); 00012 //RPCVarialbe<float> RPCHumidity(&GetHumidity, "Humidity"); 00013 void Get_Temp_and_Humidity(Arguments * input, Reply * output); 00014 00015 RPCFunction Temp_and_Humidity_Finder(&Get_Temp_and_Humidity, "Temp_and_Humidity_Finder"); 00016 00017 EthernetInterface eth; 00018 HTTPServer svr; 00019 00020 DHT sensor(D4, DHT11); 00021 00022 void Get_Temp_and_Humidity(Arguments * input, Reply *output){ 00023 int error = 0; 00024 float h = 0.0f, c = 0.0f; 00025 char arg[100]; 00026 00027 error = sensor.readData(); 00028 if (0 == error) { 00029 c = sensor.ReadTemperature(CELCIUS); 00030 h = sensor.ReadHumidity(); 00031 sprintf(arg,"Temperature in Celcius: %4.2f, Humidity is %4.2f",c, h); 00032 00033 output->putData(arg); 00034 } 00035 } 00036 00037 int main() { 00038 //Turn the LEDs off 00039 uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x32, 0x23, 0x42}; 00040 led1.write(0); 00041 led2.write(0); 00042 led3.write(0); 00043 00044 RPC::add_rpc_class<RpcDigitalOut>(); 00045 00046 printf("Setting up...\n"); 00047 eth.init(mac_addr); 00048 int ethErr = eth.connect(); 00049 if(ethErr < 0) 00050 { 00051 printf("Error %d in setup.\n", ethErr); 00052 return -1; 00053 } 00054 svr.addHandler<HTTPRpcRequestHandler>("/rpc"); 00055 00056 //attach server to port 80 00057 printf("Listening...\n"); 00058 svr.start(80, ð); 00059 00060 Timer tm; 00061 tm.start(); 00062 //Listen indefinitely 00063 while(true) 00064 { 00065 svr.poll(); 00066 if(tm.read()>.5) 00067 { 00068 tm.start(); 00069 } 00070 } 00071 }
Generated on Tue Jul 26 2022 06:04:28 by
1.7.2