Published:

My own UDP client and Art-Net parser

First we use a tool like Resolume or LED Strip Studio

screenshot of the capturing process where Wireshark and LED Strip Studio are open

Then we capture UDP packets from the software with the following wireshark capture settings:

udp and src host 192.168.0.4 and port 6454

Wireshark saves packets in pcap format, then we will use pcap library to read them and then we need to parse Art-Net structures, make a few changes and send to LED controller. Yes, controller, not LED strip directly. It can be a specialized device like DMX King or Arduino board with Art-Net library like ArtneWifi

ArtneWifi

Udp.begin(ART_NET_PORT);

The Udp object implementation depends on what board is selected in Arduino IDE. For Wemos W1 theESP8266WiFi library is used. There in WiFiUdp.cpp we find implementation of the begin method.

uint8_t WiFiUDP::begin(uint16_t port)
{
  if (_ctx) {
    _ctx->unref();
    _ctx = 0;
  }

  _ctx = new UdpContext;
  _ctx->ref();
  return (_ctx->listen(IPAddress(), port)) ? 1 : 0;
}

where the listen function is defined in UdpContext.h

bool listen(const IPAddress& addr, uint16_t port)
{
  udp_recv(_pcb, &_s_recv, (void *) this);
  err_t err = udp_bind(_pcb, addr, port);
  return err == ERR_OK;
}

The udp_ functions seem to come from lwip (mirror)

Compare it with implementation of UDP.begin for another board:

uint8_t WiFiUDP::begin(uint16_t port)
{
	struct sockaddr_in addr;
	uint32 u32EnableCallbacks = 0;

	_sndSize = 0;
	_parsedPacketSize = 0;

	// Initialize socket address structure.
	addr.sin_family = AF_INET;
	addr.sin_port = _htons(port);
	addr.sin_addr.s_addr = 0;

	if (_socket != -1 && WiFiSocket.bound(_socket)) {
		WiFiSocket.close(_socket);
		_socket = -1;
	}

	// Open UDP server socket.
	if ((_socket = WiFiSocket.create(AF_INET, SOCK_DGRAM, 0)) < 0) {
		return 0;
	}

	WiFiSocket.setopt(_socket, SOL_SOCKET, SO_SET_UDP_SEND_CALLBACK, &u32EnableCallbacks, 0);

	// Bind socket:
	if (!WiFiSocket.bind(_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in))) {
		WiFiSocket.close(_socket);
		_socket = -1;
		return 0;
	}

	return 1;
}

https://learn.adafruit.com/sipping-power-with-neopixels/putting-it-all-together

DMX512

Send/receive DMX on Arduino

ArtNet

Send/receive Art-Net on Arduino

UDP

PCAP

python is so easy https://gist.github.com/gerkey/bf749775e6bc600368b97ce3d9f113e5 IP Adress from string https://github.com/arduino/ArduinoCore-API/blob/master/api/IPAddress.cpp

UDP broadcast

255.255.255.255 would be considered the phsyical layer broadcast address while 192.168.1.255 would be considered the network layer broadcast address.

c++ udp send broadcast permission denied

As a service

I'm going to add a TCP client socket to my PCAP reader/UDP sender which will add it to the mesh of services. I use zmq library for that, specifically a C++ wrapper

Rate this page