I am trying to make an application to control DMX Channels. For this I have an ESP8266 which takes a String as an input like "2.255", where the first integer is the DMX Channel and the second integer the value.
For my PC I wrote a method that first builds the string and then sens it to the IP Address of the ESP8266 via a Socket.
for(DMXChannel c : list){
if(lastvalue.get(c.getChannelID() - 1) != c.getValue()){
try {
String msg = c.getChannelID() + "." + c.getValue();;
DatagramSocket clientSocket = new DatagramSocket();
InetAddress ipaddr = InetAddress.getByName(ip); //IP Address is "192.168.4.1"
byte[] sendData = new byte[1024];
sendData = msg.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, ipaddr, 8888);
clientSocket.send(sendPacket);
clientSocket.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
This works fine but I have a problem when I am trying to do a fade. The frequency of this piece of code seems to be too slow.
Does anyone have a "faster" solution?