Converting Python 3 UDP code

I would like to be able to control my LimitlessLED/MiLight LED lights from my Arduino UNO. The attached code runs successfully on my iMac but all my attempts at converting it have failed

import socket

UDP_IP = "xx.xx.xx.xx" # IP of the wifi bridge
UDP_PORT = 8899

sock = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)
sock.sendto(b'\x41\x00\x55', (UDP_IP, UDP_PORT))

Here is one of my many attempts to convert this

/*
MiLight.ino
 
 Send control data via UDP to control MiLight RGBW bulb
 
 */


#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0D, 0x9C, 0x24 };
IPAddress localIP(yy, yy, yy, yy);

unsigned int localPort = 8888;      // local port to listen on

// MiLight controller address
IPAddress remoteIP(xx, xx, xx, xx);
unsigned int remotePort = 8899;

char sendCode;
int incomingByte = 0;   // for incoming serial data
// codes for receiving and sending data
char allOn[] = "\42\0\55";
char allOff[] = "\41\0\55";

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,localIP);
  Udp.begin(localPort);

  Serial.begin(9600);
  Serial.println(remoteIP);
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();

    // say what you got:
    Serial.print("Action: ");

    sendCode = char(incomingByte);
    Serial.println(sendCode);
    // Zone 1
    if (sendCode == 'A') {
      Serial.print("All bulbs off: ");
      Serial.println(sendCode);
      Udp.beginPacket(remoteIP, remotePort);
      Udp.write(allOff);
      Udp.endPacket();
    }

    if (sendCode == 'B') {
      Serial.print("All bulbs on: ");
      Serial.println(sendCode);
      Udp.beginPacket(remoteIP, remotePort);
      Udp.write(allOn);
      Udp.endPacket();
    }
  }
}

I will be extremely grateful for any help on any aspect of the above.

Richard

Where have you declared (and populated) the variables allOn and allOff or are they meant to be strings, in which case should they not be in " "

Didn't read your code, I have however a tip. I assume it compiles and so on.

Attach your arduino directly to your mac, install wireshark and look at the packets you get. You'll see if you get any, and is some field is incorrect. You cannot have a switch between your mac and adruino unless you have a destination address as broadcast. (0xFFFFFFFFFFFF)

Thank you for making me look at the allOn, allOff variables again. I have made some changes and now everything works.

I changed the char arrays to

// codes for receiving and sending data
char allOn[] = { 
  0x42, 0x0, 0x55 };
char allOff[] = { 
  0x41, 0x0, 0x55 };

and the Udp code to

      Udp.beginPacket(remoteIP, remotePort);
      Udp.write(allOff[0]);
      Udp.write(allOff[1]);
      Udp.write(allOff[2]);
      Udp.endPacket();

and

      Udp.beginPacket(remoteIP, remotePort);
      Udp.write(allOn[0]);
      Udp.write(allOn[1]);
      Udp.write(allOn[2]);
      Udp.endPacket();

Thank you for taking the time to help me out. I had given up trying to get my code to run on many occasions.

Richard

You are welcome.