![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Page Web
Dependencies: mbed Serveur_web_capteur EthernetNetIf
HTTPServerExample.cpp@3:e851c29d398d, 2018-07-03 (annotated)
- Committer:
- sedid
- Date:
- Tue Jul 03 12:02:59 2018 +0000
- Revision:
- 3:e851c29d398d
- Parent:
- 1:114e347434c1
- Child:
- 6:df1059a12a34
Serveur web capteur programme + librairies;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0b1369ae8b74 | 1 | #include "mbed.h" |
donatien | 0:0b1369ae8b74 | 2 | #include "EthernetNetIf.h" |
donatien | 0:0b1369ae8b74 | 3 | #include "HTTPServer.h" |
donatien | 0:0b1369ae8b74 | 4 | |
donatien | 0:0b1369ae8b74 | 5 | DigitalOut led1(LED1, "led1"); |
donatien | 0:0b1369ae8b74 | 6 | DigitalOut led2(LED2, "led2"); |
donatien | 0:0b1369ae8b74 | 7 | DigitalOut led3(LED3, "led3"); |
donatien | 0:0b1369ae8b74 | 8 | DigitalOut led4(LED4, "led4"); |
sedid | 3:e851c29d398d | 9 | PwmOut venti(p21,"venti"); |
sedid | 3:e851c29d398d | 10 | AnalogIn pot(p18, "capteur_temp"); |
sedid | 3:e851c29d398d | 11 | |
donatien | 0:0b1369ae8b74 | 12 | |
donatien | 0:0b1369ae8b74 | 13 | LocalFileSystem fs("webfs"); |
donatien | 0:0b1369ae8b74 | 14 | |
donatien | 0:0b1369ae8b74 | 15 | EthernetNetIf eth; |
donatien | 0:0b1369ae8b74 | 16 | HTTPServer svr; |
donatien | 0:0b1369ae8b74 | 17 | |
donatien | 0:0b1369ae8b74 | 18 | int main() { |
sedid | 3:e851c29d398d | 19 | venti.period(0.001); |
donatien | 0:0b1369ae8b74 | 20 | Base::add_rpc_class<DigitalOut>(); |
sedid | 3:e851c29d398d | 21 | Base::add_rpc_class<DigitalIn>(); |
donatien | 0:0b1369ae8b74 | 22 | |
sedid | 3:e851c29d398d | 23 | printf("Setting up...\n\r"); |
donatien | 0:0b1369ae8b74 | 24 | EthernetErr ethErr = eth.setup(); |
donatien | 0:0b1369ae8b74 | 25 | if(ethErr) |
donatien | 0:0b1369ae8b74 | 26 | { |
sedid | 3:e851c29d398d | 27 | printf("Error %d in setup.\n\r", ethErr); |
donatien | 0:0b1369ae8b74 | 28 | return -1; |
donatien | 0:0b1369ae8b74 | 29 | } |
donatien | 0:0b1369ae8b74 | 30 | printf("Setup OK\n"); |
donatien | 0:0b1369ae8b74 | 31 | |
donatien | 0:0b1369ae8b74 | 32 | FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path |
donatien | 0:0b1369ae8b74 | 33 | FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path |
donatien | 0:0b1369ae8b74 | 34 | |
donatien | 0:0b1369ae8b74 | 35 | svr.addHandler<SimpleHandler>("/hello"); |
donatien | 0:0b1369ae8b74 | 36 | svr.addHandler<RPCHandler>("/rpc"); |
donatien | 0:0b1369ae8b74 | 37 | svr.addHandler<FSHandler>("/files"); |
sedid | 3:e851c29d398d | 38 | svr.addHandler<FSHandler>("/"); |
sedid | 3:e851c29d398d | 39 | svr.addHandler<MyOwnHandler>("/rw"); |
sedid | 3:e851c29d398d | 40 | |
donatien | 0:0b1369ae8b74 | 41 | |
donatien | 0:0b1369ae8b74 | 42 | svr.bind(80); |
donatien | 0:0b1369ae8b74 | 43 | |
sedid | 3:e851c29d398d | 44 | printf("Listening...\n\r"); |
donatien | 0:0b1369ae8b74 | 45 | |
donatien | 0:0b1369ae8b74 | 46 | Timer tm; |
donatien | 0:0b1369ae8b74 | 47 | tm.start(); |
donatien | 0:0b1369ae8b74 | 48 | while(true) |
donatien | 0:0b1369ae8b74 | 49 | { |
sedid | 3:e851c29d398d | 50 | x=pot.read(); //déclaration d'une variable X pour lire la valeur avec la requete RW (alternatif) |
donatien | 0:0b1369ae8b74 | 51 | Net::poll(); |
donatien | 0:0b1369ae8b74 | 52 | if(tm.read()>.5) |
donatien | 0:0b1369ae8b74 | 53 | { |
sedid | 3:e851c29d398d | 54 | led1=!led1 |
donatien | 0:0b1369ae8b74 | 55 | tm.start(); |
sedid | 3:e851c29d398d | 56 | if(x>10){ led2=1; |
sedid | 3:e851c29d398d | 57 | }else{ |
sedid | 3:e851c29d398d | 58 | led2=0; |
sedid | 3:e851c29d398d | 59 | } |
donatien | 0:0b1369ae8b74 | 60 | } |
donatien | 0:0b1369ae8b74 | 61 | } |
donatien | 0:0b1369ae8b74 | 62 | } |