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: mbed HTTPServer EthernetNetIf RPCInterface
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 int nombre = 1 ; 00018 00019 RPCVariable<int> rpc_count(&count, "count"); 00020 RPCVariable<int> rpc_nombre(&nombre, "nombre"); 00021 00022 LocalFileSystem fs("webfs"); 00023 00024 EthernetNetIf eth; 00025 HTTPServer svr; 00026 00027 int main() { 00028 Base::add_rpc_class<DigitalOut>(); 00029 00030 printf("Setting up...\n"); 00031 00032 // modif LR config IP manuelle sinon dhcp ! 00033 EthernetNetIf eth( IpAddr(192,168,1,102), // IP 00034 IpAddr(255,255,255,0), // Subnet mask 00035 IpAddr(192,168,1,1), // Gateway 00036 IpAddr(192,168,1,1) ); // DNS 00037 00038 00039 EthernetErr ethErr = eth.setup(); 00040 if(ethErr) 00041 { 00042 printf("Error %d in setup.\n", ethErr); 00043 return -1; 00044 } 00045 printf("Setup OK\n"); 00046 // on définit où seront stockés les fichiers ! 00047 FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path 00048 FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path 00049 00050 svr.addHandler<SimpleHandler>("/hello"); // http://a.b.c.d/hello : hello world ! 00051 svr.addHandler<RPCHandler>("/rpc"); 00052 svr.addHandler<FSHandler>("/files"); 00053 svr.addHandler<FSHandler>("/"); //Default handler 00054 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm 00055 00056 svr.bind(80); 00057 00058 printf("Listening...\n"); 00059 00060 Timer tm; 00061 tm.start(); 00062 //Listen indefinitely 00063 while(true) 00064 { 00065 Net::poll(); 00066 // demi periode = 0.5*1/f 00067 if(tm.read()>(0.5/nombre)) 00068 { 00069 led1=!led1; //Show that we are alive 00070 count ++ ; 00071 tm.start(); 00072 } 00073 } 00074 00075 return 0; 00076 00077 } 00078 // http://192.168.1.102/rpc/pot1/read dans le navigateur permet de lire l'état du potard !
Generated on Mon Aug 22 2022 17:48:07 by
1.7.2