Projekt na płytce k64f
Dependencies: EthernetInterface mbed-rtos mbed
Fork of Ethernet_UDP_server by
main.cpp
- Committer:
- majster
- Date:
- 2018-09-15
- Revision:
- 1:bc203220ef47
- Parent:
- 0:9108b822f763
File content as of revision 1:bc203220ef47:
#include "mbed.h" #include "EthernetInterface.h" const int PORT = 80; //port static const char* SERVER_IP = "192.168.1.101"; //IP serwera static const char* MASK = "255.255.255.0"; //maska static const char* GATEWAY = "192.168.1.1"; //gateway Serial pc(USBTX, USBRX); //PC interface DigitalOut RedLed(LED1); //DigitalOut GreenLed(LED2); DigitalOut BlueLed(LED3); InterruptIn Switch1(SW2); // przycisk lewo InterruptIn Switch2(SW3); // przycisk od prawy void init_usb(void); //init usb void init_eth(void); //init Ethernet void init_usb(void) { //pc.baud(9600); //baud } void blink() { RedLed=!RedLed; } void blink1() { BlueLed=!BlueLed; } int main(void) { char c; // int licznik; // licznik=0; // int a; // int b; //int d[2]={a,b}; //init_usb(); //init usb EthernetInterface eth; eth.init(SERVER_IP, MASK, GATEWAY); eth.connect(); pc.printf("\nIP Address is %s\n\r", eth.getIPAddress()); TCPSocketServer server; server.bind(PORT); server.listen(); // nasluch przychodzacych polaczen Switch1.fall(&blink); Switch2.fall(&blink1); while (true) //wykonuj caly czas { TCPSocketConnection client; server.accept(client); // akceptacja nowego polaczenia client.set_blocking(false, 1500); // timeout (1.5)s c=RedLed; switch(c) { case 0: if (BlueLed==0){ char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> LEDY </h1> <p><font color=""red"">Dioda Czerwona ON</font></p> oraz <p><font color=""blue"">Dioda Niebieska ON</font></p><form action=""demo_form.asp""></form></body> </html>"; client.send_all(http_cmd, sizeof(http_cmd)-1); // wyslij wszystko } else { char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> LEDY </h1> <p><font color=""red"">Dioda Czerwona ON</font></p> oraz <p><font color=""blue"">Dioda Niebieska OFF</font></p><form action=""demo_form.asp""></form></body> </html>"; client.send_all(http_cmd, sizeof(http_cmd)-1); // wyslij wszystko } break; case 1: if (BlueLed==1){ char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> LEDY </h1> <p><font color=""red"">Dioda Czerwona OFF</font></p> oraz <p><font color=""blue"">Dioda Niebieska OFF</font></p><form action=""demo_form.asp""></form></body> </html>"; client.send_all(http_cmd, sizeof(http_cmd)-1); // wyslij wszystko } else { char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> LEDY </h1> <p><font color=""red"">Dioda Czerwona OFF</font></p> oraz <p><font color=""blue"">Dioda Niebieska ON</font></p><form action=""demo_form.asp""></form></body> </html>"; client.send_all(http_cmd, sizeof(http_cmd)-1); // wyslij wszystko } } /* if (RedLed==0) { char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> Dioda Czerwona włączona </h1> <p> LED </p><form action=""demo_form.asp""><SELECT NAME=""LED_COLOUR""> <OPTION VALUE=""""> <OPTION VALUE=""GREEN"">GREEN <OPTION VALUE=""RED"">RED <input type=""submit"" value=""Submit""> </SELECT></form></body> </html>"; client.send_all(http_cmd, sizeof(http_cmd)-1); } else { char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> Dioda Czerwona wyłączona </h1> <p> LED </p><form action=""demo_form.asp""><SELECT NAME=""LED_COLOUR""> <OPTION VALUE=""""> <OPTION VALUE=""GREEN"">GREEN <OPTION VALUE=""RED"">RED <input type=""submit"" value=""Submit""> </SELECT></form></body> </html>"; client.send_all(http_cmd, sizeof(http_cmd)-1); } } if (RedBlue==0) { char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> Dioda Niebieska włączona </h1> <p> LED </p><form action=""demo_form.asp""><SELECT NAME=""LED_COLOUR""> <OPTION VALUE=""""> <OPTION VALUE=""GREEN"">GREEN <OPTION VALUE=""RED"">RED <input type=""submit"" value=""Submit""> </SELECT></form></body> </html>"; client.send_all(http_cmd, sizeof(http_cmd)-1); else { char http_cmd[] = "<!DOCTYPE html> <html> <head> <title> FRDM-K64F </title> </head> <body> <h1> Dioda Niebieska włączona </h1> <p> LED </p><form action=""demo_form.asp""><SELECT NAME=""LED_COLOUR""> <OPTION VALUE=""""> <OPTION VALUE=""GREEN"">GREEN <OPTION VALUE=""RED"">RED <input type=""submit"" value=""Submit""> </SELECT></form></body> </html>"; client.send_all(http_cmd, sizeof(http_cmd)-1); } } */ client.close(); pc.printf("\n\nClient closed\n\n\r"); } }