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: EthernetNetIf HTTPServer RPCInterface mbed
Fork of HTTPServerExample by
HTTPServerExample.cpp
00001 #include "mbed.h" 00002 #include "EthernetNetIf.h" 00003 #include "HTTPServer.h" 00004 #include "SerialRPCInterface.h" 00005 00006 // LR 2/2/17 00007 // sur ce fichier j'ai rajouté une variable RPC count que je peux lire à distance 00008 // adresse/rpc/count/read/ 00009 00010 DigitalOut led1(LED1, "led1"); 00011 DigitalOut led2(LED2, "led2"); 00012 DigitalOut led3(LED3, "led3"); 00013 DigitalOut led4(LED4, "led4"); 00014 AnalogIn Pot1(p19, "pot1"); 00015 00016 int count = 0 ; 00017 RPCVariable<int> rpc_count(&count, "count"); 00018 00019 LocalFileSystem fs("webfs"); 00020 00021 EthernetNetIf eth; 00022 HTTPServer svr; 00023 00024 int main() { 00025 Base::add_rpc_class<DigitalOut>(); 00026 00027 printf("Setting up...\n"); 00028 00029 // modif LR config IP manuelle sinon dhcp ! 00030 EthernetNetIf eth( IpAddr(192,168,1,102), // IP 00031 IpAddr(255,255,255,0), // Subnet mask 00032 IpAddr(192,168,1,1), // Gateway 00033 IpAddr(192,168,1,1) ); // DNS 00034 00035 00036 EthernetErr ethErr = eth.setup(); 00037 if(ethErr) 00038 { 00039 printf("Error %d in setup.\n", ethErr); 00040 return -1; 00041 } 00042 printf("Setup OK\n"); 00043 // on définit où seront stockés les fichiers ! 00044 FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path 00045 FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path 00046 00047 svr.addHandler<SimpleHandler>("/hello"); // http://a.b.c.d/hello : hello world ! 00048 svr.addHandler<RPCHandler>("/rpc"); 00049 svr.addHandler<FSHandler>("/files"); 00050 svr.addHandler<FSHandler>("/"); //Default handler 00051 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm 00052 00053 svr.bind(80); 00054 00055 printf("Listening...\n"); 00056 00057 Timer tm; 00058 tm.start(); 00059 //Listen indefinitely 00060 while(true) 00061 { 00062 Net::poll(); 00063 if(tm.read()>.5) 00064 { 00065 led1=!led1; //Show that we are alive 00066 count ++ ; 00067 tm.start(); 00068 } 00069 } 00070 00071 return 0; 00072 00073 } 00074 // http://192.168.1.102/rpc/pot1/read dans le navigateur permet de lire l'état du potard !
Generated on Wed Jul 27 2022 08:16:54 by
1.7.2
