Hello,
I’m trying to build something like a remote controller for basic interface functions like moving axis, start/stop, frame, etc. The official one is way to expensive for what it does imo. The ACS / RMA app is okayish but not as nice as having a dedicated remote, so I’d like to build it myself.
I’m using an ESP-32 dev board to setup wifi connection to the AP which is connected to the DSP (the ACS app is working flawlessly btw.).
Now I’m stuck at the udp communication. According to this wiki you can use very basic udp commands on port 50207 to talk to the DSP but I have no luck with this.
My code:
#include WiFi.h>
#include WiFiUdp.h>
// network settings
const char* ssid = "**********";
const char* password = "*********";
const IPAddress controllerIP(192, 168, 11, 99);
const int udpSendPort = 50207; // Port for sending
const int udpAckPort = 40207; // Port for receiving
// pins
const int buttonPins[] = {2, 4, 5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25}; // 15 Taster
const int statusLedPin = 26; // LED status
const int wifiLedPin = 27; // LED wifi
const int buttonLedPin = 32; // LED button press
WiFiUDP udpSend;
WiFiUDP udpAck;
bool waitingForAck = false;
unsigned long lastCommandTime = 0;
const unsigned long ackTimeout = 1000; // Timeout for ACK
bool blinkWifiLed = false;
unsigned long blinkStartTime = 0;
const unsigned long blinkDuration = 50;
void setup() {
for (int i = 0; i < 15; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
pinMode(statusLedPin, OUTPUT);
pinMode(wifiLedPin, OUTPUT);
pinMode(buttonLedPin, OUTPUT);
digitalWrite(statusLedPin, HIGH);
//Wifi connection
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(wifiLedPin, HIGH);
delay(500);
digitalWrite(wifiLedPin, LOW);
delay(500);
}
digitalWrite(wifiLedPin, HIGH);
// UDP start
udpSend.begin(udpSendPort);
udpAck.begin(udpAckPort);
}
void loop() {
//check button press
for (int i = 0; i < 15; i++) {
if (digitalRead(buttonPins[i]) == LOW) { // pressed
sendCommand(i, false);
digitalWrite(buttonLedPin, HIGH);
while (digitalRead(buttonPins[i]) == LOW); // released
sendCommand(i, true);
digitalWrite(buttonLedPin, LOW);
}
}
checkForAck();
handleWifiLedBlink();
// send Keep-Alive-package
static unsigned long lastKeepAlive = 0;
if (millis() - lastKeepAlive > 1000) {
sendKeepAlive();
lastKeepAlive = millis();
}
}
void checkForAck() {
if (waitingForAck) {
// check for ACK package
int packetSize = udpAck.parsePacket();
if (packetSize) {
byte ack = udpAck.read();
if (ack == 0xCC) {
Serial.println("ACK received!");
waitingForAck = false;
startWifiLedBlink();
}
}
// check timeout
if (millis() - lastCommandTime > ackTimeout) {
Serial.println("no ACK received!");
waitingForAck = false;
}
}
}
void sendCommand(int buttonIndex, bool isStop) {
byte command[3] = {0xA5, 0x00, 0x00};
// start-command (0x50)
if (!isStop) {
command[1] = 0x50;
switch (buttonIndex) {
case 0: command[2] = 0x02; break; // +X Down
case 1: command[2] = 0x01; break; // -X Down
case 2: command[2] = 0x03; break; // +Y Down
case 3: command[2] = 0x04; break; // -Y Down
case 4: command[2] = 0x0A; break; // +Z Down
case 5: command[2] = 0x0B; break; // -Z Down
case 6: command[2] = 0x0C; break; // +U Down
case 7: command[2] = 0x0D; break; // -U Down
case 8: command[2] = 0x11; break; // Speed
case 9: command[2] = 0x06; break; // Start/Pause
case 10: command[2] = 0x09; break; // Stop
case 11: command[2] = 0x5A; break; // Reset
case 12: command[2] = 0x00; break; // Frame
case 13: command[2] = 0x08; break; // Origin
case 14: command[2] = 0x05; break; // Pulse
}
}
// stop-commands (0x51)
else {
command[1] = 0x51;
switch (buttonIndex) {
case 0: command[2] = 0x02; break; // +X Up
case 1: command[2] = 0x01; break; // -X Up
case 2: command[2] = 0x03; break; // +Y Up
case 3: command[2] = 0x04; break; // -Y Up
case 4: command[2] = 0x0A; break; // +Z Up
case 5: command[2] = 0x0B; break; // -Z Up
case 6: command[2] = 0x0C; break; // +U Up
case 7: command[2] = 0x0D; break; // -U Up
default: return;
}
}
udpSend.beginPacket(controllerIP, udpSendPort);
udpSend.write(command, 3);
udpSend.endPacket();
// start ACK-check
waitingForAck = true;
lastCommandTime = millis();
}
void startWifiLedBlink() {
blinkWifiLed = true;
blinkStartTime = millis();
digitalWrite(wifiLedPin, LOW);
}
void handleWifiLedBlink() {
if (blinkWifiLed) {
if (millis() - blinkStartTime >= blinkDuration) {
digitalWrite(wifiLedPin, HIGH);
blinkWifiLed = false;
}
}
}
void sendKeepAlive() {
byte keepAlive = 0xCE;
udpSend.beginPacket(controllerIP, udpSendPort);
udpSend.write(&keepAlive, 1);
udpSend.endPacket();
}
Wifi is connecting without a problem but I can’t seem to get any commands to the DSP. Do I have to use the 50200/40200 ports and the rd file payload or am I doing something wrong? Any ideas?