Hola a todos.
Tengo conectado a un duemilanove un ethernet shield y un lcd de 16x2.
Con uno de los codigos de ejemplo algo modificado y simplificado, leo los paquetes UDP y los muestro en el monitor serie. A la vez en el lcd quisiera que apareciera "llegan datos" o "no llegan datos", segun haya o no paquetes disponibles. El caso es que siempre aparece no llegan datos, por que entiendo que entre paquete y paquete haya un espacio vacio y prevalece. Por eso se me ocurre que deberia añadir al condicional "si no llegan datos durante x segundos...". Como haria eso con millis?
El codigo:
/*
UDPSendReceive.pde:
This sketch receives UDP message strings, prints them to the serial port
and sends an "acknowledge" string back to the sender
A Processing sketch is included at the end of file that can be used to send
and received messages for testing with a computer.
created 21 Aug 2010
by Michael Margolis
This code is in the public domain.
*/
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);
unsigned int localPort = 9500; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
lcd.setCursor(0, 0);
lcd.print("Llegan datos");
}else{
lcd.setCursor(0, 0);
lcd.print("No llegan datos");
}
delay(10);
}