Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Incluimos las librerías:
- #include <LiquidCrystal.h>
- #include <SPI.h>
- #include <Ethernet.h>
- #define max_he 255
- // Inicializamos la librería con los pines que utilizaremos
- LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- IPAddress ip(192,168,1,3); //direccion ip configurada para funcionar con el servidor local.
- // Inicializar la librería de servidor Ethernet
- // con la dirección IP y el puerto que desee utilizar
- // (puerto 80 es el predeterminado para HTTP):
- EthernetServer server(80);
- String Http = String(max_he);
- void setup() {
- // Inicializamos el LCD
- lcd.begin(16, 2);
- Http = "";
- // Iniciamos la conexión con el servidor
- Ethernet.begin(mac, ip);
- server.begin();
- Serial.begin(9600);
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- }
- void loop() {
- // LCD off
- lcd.noDisplay();
- delay(100);
- // LCD on
- lcd.display();
- delay(100);
- EthernetClient client = server.available();
- if (client) {
- Serial.println("new client");
- boolean currentLineIsBlank = true;
- while (client.connected()) {
- if (client.available()) {
- char c = client.read();
- if (Http.length() < max_he){
- Http += c;
- }
- if (c == '\n' && currentLineIsBlank) {
- client.println("HTTP/1.1 200 OK");
- client.println("Content-Type: text/html");
- client.println("Connection: close"); // la conexión se cierra después de la respuesta
- client.println("Refresh: 30"); // Refrescamos cada 30 segundos
- client.println();
- client.println("<!DOCTYPE HTML>");
- client.println("<html>");
- client.println("<form method=\"GET\">");
- client.println("<input type=\"text\" name=\"msg\" size=\"10\" />");
- client.println("<input type=\"submit\">");
- client.println("</form>");
- client.println("</html>");
- break;
- }
- if (c == '\n') {
- currentLineIsBlank = true;
- }
- else if (c != '\r') {
- currentLineIsBlank = false;
- }
- }
- }
- // tiempo al navegador para recibir los datos
- delay(1);
- int firstPos = Http.indexOf("?");
- if(firstPos > -1){
- int lastPos = Http.indexOf(" ", firstPos+5);
- String text = Http.substring(firstPos+5, lastPos);
- lcd.print(text);
- Http = "";
- }
- // Cerramos la conexión:
- client.stop();
- Serial.println("client disconnected");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement