Ir al contenido


Foto

Comunicador UPD o TCP-IP con arduino.


  • Por favor identifícate para responder
3 respuestas en este tema

#1 luk2009

luk2009

    Advanced Member

  • Moderadores
  • PipPipPip
  • 2.040 mensajes
  • LocationSanto Domingo

Escrito 27 enero 2014 - 09:30

Estoy Haciendo pruebas para crear una especie de comunicador via internet utilizando la tarjeta arduino.  La idea es recibir los mensajes enviados por medio de arduino al detectar ciertos cambios en los pines especificados en el programa. Estos mensajes serian recibidos en un programa escucha hecho en delphi, el cual guardaria los datos en una base de datos firebird.

Estoy probando hacerlo por medio de UDP, pero me gustaria hacerlo por medio de TCP-IP para poder confirmar que el envio fue hecho correctamente, aunque talvez lo pueda hacer por udp, haciendo que arduino espere una respuesta del programa hecho en delphi. 

Aqui les paso el codigo con el cual estoy haciendo las pruebas, por si alguno tiene alguna experiencia con este asunto:



delphi
  1. /*
  2.   UDPSendReceive.pde:
  3. This sketch receives UDP message strings, prints them to the serial port
  4. and sends an "acknowledge" string back to the sender
  5.  
  6. A Processing sketch is included at the end of file that can be used to send
  7. and received messages for testing with a computer.
  8.  
  9. created 21 Aug 2010
  10. by Michael Margolis
  11.  
  12. This code is in the public domain.
  13. */
  14.  
  15.  
  16. #include <SPI.h>        // needed for Arduino versions later than 0018
  17. #include <Ethernet.h>
  18. #include <EthernetUdp.h>        // UDP library from: bjoern@cs.stanford.edu 12/30/2008
  19.  
  20.  
  21.  
  22. // Enter a MAC address and IP address for your controller below.
  23. // The IP address will be dependent on your local network:
  24. byte mac[] =
  25.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  26. IPAddress ip(192, 168, 69, 200);
  27.  
  28. //IPAddress remip(10, 0, 0, 2);
  29. unsigned int localPort = 5015;      // local port to listen on
  30. int pulsador=7;  //antes era el 40
  31. int valor=(digitalRead(pulsador));
  32. //int rport =5000;
  33. // buffers for receiving and sending data
  34. char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
  35. char  ReplyBuffer[] = "acknowledged";      // a string to send back
  36.  
  37. // An EthernetUDP instance to let us send and receive packets over UDP
  38. EthernetUDP Udp;
  39.  
  40. void setup() {
  41.   // start the Ethernet and UDP:
  42.   Ethernet.begin(mac,ip);
  43.   Udp.begin(localPort);
  44.  // Udp.remoteIP=(remip);
  45. // Udp.remotePort(rport);
  46.   Serial.begin(9600);
  47.   pinMode(pulsador,INPUT);
  48. }
  49.  
  50. void loop() {
  51. if (digitalRead(pulsador)==LOW)
  52. {
  53. IPAddress destinationIP(10,0,0,2);  // Address of target machine
  54. unsigned int destinationPort = 5000;      // Port to send to
  55. Udp.beginPacket(destinationIP, destinationPort);
  56.  
  57.  if (digitalRead(pulsador) == HIGH) { 
  58.         Udp.write("ON");
  59.  
  60.         } else {
  61.         Udp.write("OFF");
  62.  
  63.         }
  64.  
  65. Udp.endPacket();
  66. }
  67. }



  • 0

#2 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4.945 mensajes
  • LocationMéxico

Escrito 28 enero 2014 - 10:17

Que interesante lo que haces amigo. Yo tengo mucha curiocidad por hacer algo con Andruino pero he tenido poco tiempo.
  • 0

#3 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 28 enero 2014 - 05:11

Que interesante lo que haces amigo. Yo tengo mucha curiocidad por hacer algo con Andruino pero he tenido poco tiempo.



Ya quisiera yo tener tiempo para terminar todos mis pendientes, pero el día sólo tiene 24 horas  :cry:

Saludos
  • 0

#4 genriquez

genriquez

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 539 mensajes
  • LocationCali, Colombia

Escrito 28 enero 2014 - 09:13

Te apoyo Egostar, lamentablemente el día es muy corto para tantas cosas que hay para hacer.  :(
  • 0




IP.Board spam blocked by CleanTalk.