Yasushi TAUCHI / Mbed 2 deprecated giken9_HTMLServer_Temp_Sample

Dependencies:   EthernetInterface HttpServer TextLCD expatlib mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Fork of giken9_HTMLServer_Sample by Yasushi TAUCHI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //#define DNS_SERVER_ADDRESS(ipaddr)        (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */
00002 #include "mbed.h"
00003 #include "rtos.h"
00004 #include "EthernetInterface.h"
00005 #include "HTTPServer.h"
00006 #include "mbed_rpc.h"
00007 #include "TextLCD.h"
00008 
00009 EthernetInterface eth;
00010 LocalFileSystem local("local");
00011 DigitalOut led4(LED4);
00012 
00013 DigitalOut led1(LED1);
00014 AnalogIn ain(p20);
00015 
00016 TextLCD lcd(p24, p26, p27, p28, p29, p30);
00017 
00018 float Temp;
00019 
00020 void LcdWrite(Arguments* arg, Reply* r);void LcdWrite(Arguments* arg, Reply* r);
00021 void aliveState(void const *args)
00022 {
00023     while (true) {
00024         led4 = !led4;
00025         Thread::wait(1000);
00026     }
00027 }
00028 
00029 void measure(void const *n)
00030 {
00031     Temp=ain.read()*3.3*100;
00032     led1=!led1;
00033 }
00034 
00035 int main()
00036 {
00037     printf("********* PROGRAM START ***********\r\n");
00038     Thread thread(aliveState);
00039     
00040     led1=0;
00041     RtosTimer measure_timer(measure);
00042     measure_timer.start(2000);
00043     
00044     lcd.cls();
00045     lcd.locate(0,0);
00046     
00047     printf("********* RPC Initialize ***********\r\n");
00048     RPC::add_rpc_class<RpcDigitalOut>();
00049     RPC::construct<RpcDigitalOut, PinName, const char*>(LED1, "led1");
00050     RPC::construct<RpcDigitalOut, PinName, const char*>(LED2, "led2");
00051     RPC::construct<RpcDigitalOut, PinName, const char*>(LED3, "led3");
00052     RPCFunction rpcFunc(LcdWrite, "LcdWrite"); 
00053     RPCVariable <float>rpcval(&Temp,"temp");
00054     printf("EthernetInterface Setting up...\r\n");
00055     if(eth.init()!=0) {                             //for DHCP Server
00056        // if(eth.init("133.11.168.23","255.255.255.0","133.11.168.1")!=0) { //for Static IP Address
00057         printf("EthernetInterface Initialize Error \r\n");
00058         return -1;
00059     }
00060     if(eth.connect()!=0) {
00061         printf("EthernetInterface Connect Error \r\n");
00062         return -1;
00063     }
00064     printf("IP Address is %s\r\n", eth.getIPAddress());
00065     printf("NetMask is %s\r\n", eth.getNetworkMask());
00066     printf("Gateway Address is %s\r\n", eth.getGateway());
00067     printf("Ethernet Setup OK\r\n");
00068 
00069     FSHandler::mount("/local","/");
00070     
00071     lcd.locate(0,0);
00072     lcd.printf("%s",eth.getIPAddress());
00073     HTTPServerStart(80);
00074 }
00075 
00076 void LcdWrite(Arguments* arg, Reply* r)  //RPC Call
00077 {
00078     lcd.locate(0,1);
00079     lcd.printf("%s",arg->argv[0]);
00080 }
00081