We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, i've made a sketch in processing to detect digiboard IP on instruments, so, i send UDP query in broadcast mode and instrument return datagram where i can show remote ip and i make connexion with TCP client to this remote on port 502 with specific data to making instrument action. It's work fine in processing but i wanted to make the same in arduino sketch with arduino library...
So please, help me to make the same code for arduino, see my code...
import hypermedia.net.*;
import processing.net.*;
UDP udp; // define the UDP object
Client myClient;
//START COMMANDE CI_3100:c1920000000601050001ff00
//STOP COMMANDE CI_3100+CI_X5X:c19200000006010500010000
//FIND IP COMMANDE CI_3100:304236384432324154454d494c4353444e414c444552303830343365393434363330633962343830343830303030303001707274013630303001636d640130017369640134313830372c373032343532363201
//FIND IP COMMANDE CI_X5X:323032314441424654454d494c4353444e414c444552303830343365393434363330633962343830343830305845303001707274013630303001636d640130017369640134313831372c373034363132303801
byte[] datadetect_CI3100 = new byte[]{(byte)0x30, (byte)0x42, (byte)0x36, (byte)0x38, (byte)0x44, (byte)0x32, (byte)0x32, (byte)0x41, (byte)0x54, (byte)0x45, (byte)0x4d, (byte)0x49, (byte)0x4c, (byte)0x43, (byte)0x53, (byte)0x44, (byte)0x4e, (byte)0x41, (byte)0x4c, (byte)0x44, (byte)0x45, (byte)0x52, (byte)0x30, (byte)0x38, (byte)0x30, (byte)0x34, (byte)0x33, (byte)0x65, (byte)0x39, (byte)0x34, (byte)0x34, (byte)0x36, (byte)0x33, (byte)0x30, (byte)0x63, (byte)0x39, (byte)0x62, (byte)0x34, (byte)0x38, (byte)0x30, (byte)0x34, (byte)0x38, (byte)0x30, (byte)0x30, (byte)0x30, (byte)0x30, (byte)0x30, (byte)0x30, (byte)0x01, (byte)0x70, (byte)0x72, (byte)0x74, (byte)0x01, (byte)0x36, (byte)0x30, (byte)0x30, (byte)0x30, (byte)0x01, (byte)0x63, (byte)0x6d, (byte)0x64, (byte)0x01, (byte)0x30, (byte)0x01, (byte)0x73, (byte)0x69, (byte)0x64, (byte)0x01, (byte)0x34, (byte)0x31, (byte)0x38, (byte)0x30, (byte)0x37, (byte)0x2c, (byte)0x37, (byte)0x30, (byte)0x32, (byte)0x34, (byte)0x35, (byte)0x32, (byte)0x36, (byte)0x32, (byte)0x01};
byte[] datadetect_CIX5X = new byte[]{(byte)0x32, (byte)0x30, (byte)0x32, (byte)0x31, (byte)0x44, (byte)0x41, (byte)0x42, (byte)0x46, (byte)0x54, (byte)0x45, (byte)0x4d, (byte)0x49, (byte)0x4c, (byte)0x43, (byte)0x53, (byte)0x44, (byte)0x4e, (byte)0x41, (byte)0x4c, (byte)0x44, (byte)0x45, (byte)0x52, (byte)0x30, (byte)0x38, (byte)0x30, (byte)0x34, (byte)0x33, (byte)0x65, (byte)0x39, (byte)0x34, (byte)0x34, (byte)0x36, (byte)0x33, (byte)0x30, (byte)0x63, (byte)0x39, (byte)0x62, (byte)0x34, (byte)0x38, (byte)0x30, (byte)0x34, (byte)0x38, (byte)0x30, (byte)0x30, (byte)0x58, (byte)0x45, (byte)0x30, (byte)0x30, (byte)0x01, (byte)0x70, (byte)0x72, (byte)0x74, (byte)0x01, (byte)0x36, (byte)0x30, (byte)0x30, (byte)0x30, (byte)0x01, (byte)0x63, (byte)0x6d, (byte)0x64, (byte)0x01, (byte)0x30, (byte)0x01, (byte)0x73, (byte)0x69, (byte)0x64, (byte)0x01, (byte)0x34, (byte)0x31, (byte)0x38, (byte)0x31, (byte)0x37, (byte)0x2c, (byte)0x37, (byte)0x30, (byte)0x34, (byte)0x36, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x38, (byte)0x01};
byte[] datastart = new byte[]{(byte)0xc1, (byte)0x92, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x01, (byte)0x05, (byte)0x00, (byte)0x01, (byte)0xff, (byte)0x00};
byte[] datastop = new byte[]{(byte)0xc1, (byte)0x92, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x01, (byte)0x05, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x00};
void setup() {
udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000
//udp.log( true ); // <-- printout the connection activity
udp.listen( true ); // and wait for incoming message
}
void draw()
{
}
void keyPressed() {
String ip = "255.255.255.255"; // the destination IP BROADCAST
int port = 5048; // the destination port
udp.send(datadetect_CI3100, ip, port ); // the message 1 to send
delay(1000);
udp.send(datadetect_CIX5X, ip, port ); // the message 2 to send
}
void receive( byte[] data ) { // <-- default handler
for(int i=0; i < data.length; i++){
String ipstart = str(char(data[i])) +""+ str(char(data[i+1]));
if (ipstart.equals("ip")==true) {
i=i+1;
ipstart =str(char(data[i+2]))+""+ str(char(data[i+3]))+""+ str(char(data[i+4]))+""+ str(char(data[i+5]))+""+ str(char(data[i+6]))+""+ str(char(data[i+7]))+""+ str(char(data[i+8]))+""+ str(char(data[i+9]));
//println(ipstart);
String strtest =str(char(data[i+10]));
if (strtest.equals("s")==true) {
ipstart =unhex("0"+char(data[i+2]))+"."+unhex(char(data[i+3])+""+char(data[i+4]))+"."+unhex(char(data[i+5])+""+char(data[i+6]))+"."+unhex(char(data[i+7])+""+char(data[i+8]));
println(ipstart);
}
else{
ipstart =unhex(char(data[i+2])+""+char(data[i+3]))+"."+unhex(char(data[i+4])+""+char(data[i+5]))+"."+unhex(char(data[i+6])+""+char(data[i+7]))+"."+unhex(char(data[i+8])+""+char(data[i+9]));
println(ipstart);
}
i=data.length;
myClient = new Client(this,ipstart , 502);
myClient.write(datastop);
delay(1000);
myClient.write(datastart);
delay(1000);
myClient.write(datastop);
}
}
}
Answers
no one can help me ?
i code the arduino udp part successfully ! my udp part code on arduino
I'm not able to make the code of the TCP client part i've made in processing... I just want to send packet on TCP with IP and port from the arduino in processing it's look like :
I have the same issue, I am struggling to send a broadcast UDP packet to all the devices on the network.