udp or tcp ip message with ethernet shield 5100


hi
i have arduino mega 2560 , ethernet shield 5100. want send message server eg http://luk2009.dyndns.org, in there program listens port , archive messages.

the problem have not how send dyndns address, because allows me enter byte addresses.

i want know how change:
destinationip ipaddress (192,168,69,122);

by:
destinationip ipaddress (luk2009.dyndns.biz);


i used code:


code: [select]
#include <spi.h>         // needed arduino versions later 0018
#include <ethernet.h>
#include <ethernetudp.h>         // udp library from: bjoern@cs.stanford.edu 12/30/2008


// enter mac address , ip address controller below.
// ip address dependent on local network:
byte mac[] = { 
  0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };
ipaddress ip(192, 168, 69, 200);

//ipaddress remip(10, 0, 0, 2);
unsigned int localport = 5015;      // local port listen on
// buffers receiving , sending data
char packetbuffer[udp_tx_packet_max_size]; //buffer hold incoming packet,
char  replybuffer[] = "acknowledged";       // string send back

// ethernetudp instance let send , receive packets on udp
ethernetudp udp;

int pinsensor[]= {7,8};
const int pinled = 3;
const int sirena = 4;
int n=0;
int sonando;  // para estado del pin que monitorea la sirena de la alarma
char alarma[] ="30120001ba0";  //codigo ser enviado, solo dejando espacio para la zona


void setup(){
// start ethernet , udp:
  ethernet.begin(mac,ip);
  udp.begin(localport);
// udp.remoteip=(remip);
// udp.remoteport(rport);
  serial.begin(9600);

for (int i=0; i<2; i++){ 
pinmode(pinsensor[i],input);
}
pinmode(pinled,output);
pinmode(sirena,input);
digitalwrite(pinled,low);
}
void loop(){
ipaddress destinationip(192,168,69,122);  // address of target machine //  want change address address http://luk2009.dyndns.biz
unsigned int destinationport = 5003;      // puerto udp al que se envia el dato
sonando = digitalread(sirena);

if (sonando==low){

for (n=0;n<2;n++){
if (digitalread(pinsensor[n])==low) {
digitalwrite(pinled, high);// este led es solo para pruebas y saber que el sistema esta detectando los cambios
udp.beginpacket(destinationip, destinationport);
//udp.write(alarma);
udp.print(alarma);
udp.print(pinsensor[n]); // esto seria el equivalente la zona del sistema de alarmas
udp.endpacket();
delay (30000); // para controlar que no este enviando seƱales durante 4 minutos continuos, la idea es que revise todos los pines antes de hacer la pausa
}
else{
digitalwrite(pinled, low);  //led para pruebas solamente
}
}
}
}

here thd dhcpaddressprinter example sketch modified resolve dns requests. used google because neither of domain names listed resolve ip.
code: [select]
#include <spi.h>
#include <ethernet.h>
#include <dns.h>

byte mac[] = { 0x00, 0xaa, 0xbb, 0xcc, 0xde, 0x02 };

ethernetclient client;
dnsclient dnsclient;
ipaddress remote_addr;

void setup() {
 // start serial library:
 serial.begin(115200);

 pinmode(4,output);
 digitalwrite(4,high);

 serial.print("starting ethernet...");
 if (ethernet.begin(mac) == 0) {
   serial.println("failed");
   for(;;)
     ;
 }
 for (byte thisbyte = 0; thisbyte < 4; thisbyte++) {
   serial.print(ethernet.localip()[thisbyte], dec);
   serial.print(".");
 }
 serial.println();
 
 serial.print("google server ");
 dnsclient.begin(ethernet.dnsserverip());
 int rtnval = dnsclient.gethostbyname("www.google.com",remote_addr);
 if(rtnval == 1) serial.println(remote_addr);
  else serial.println("dns lookup failed");
}

void loop() {
}


edit added error checking dns request.


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > udp or tcp ip message with ethernet shield 5100


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support