imported from "final" folder

This commit is contained in:
2025-11-28 12:12:50 +01:00
parent f9288986cf
commit ff8e725b35
1061 changed files with 225150 additions and 96 deletions

View File

@@ -0,0 +1,23 @@
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
*~

View File

@@ -0,0 +1 @@
{"type": "library", "name": "ArtnetWifi", "version": "1.6.2", "spec": {"owner": "rstephan", "id": 6328, "name": "ArtnetWifi", "requirements": null, "uri": null}}

View File

@@ -0,0 +1,25 @@
The MIT License (MIT)
Copyright (c) 2014 Nathanaël Lécaudé
https://github.com/natcl/Artnet, http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811
Copyright (c) 2016 Stephan Ruloff
https://github.com/rstephan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,91 @@
# ArtnetWifi
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArtnetWifi.svg?)](https://www.ardu-badge.com/ArtnetWifi)
An Art-Net library for Wifi-Arduino's. Tested on ESP8266, ESP32, Pi Pico W, WiFi101 (e.g. MKR1000) and WiFiNINA (e.g. NANO 33 IoT) devices.
Note: this library assumes you are using a wifi module.
Based on https://github.com/natcl/Artnet [master](https://github.com/natcl/Artnet/archive/master.zip)
## Installation
### Arduino IDE
Navigate to **Sketch** -> **Include Library** -> **Manage Libraries...**,
then search for `ArtnetWifi` and the library will show up. Click **Install** and the library is ready to use.
### PlatformIO Core (CLI)
```
$ pio init --board nodemcuv2
$ pio lib install artnetwifi
```
### Manual
Place this in your `~/Documents/Arduino/libraries` folder.
## Examples
Different examples are provided, here is a summary of what each example does.
### ArtnetWifiDebug
Simple test for WiFi, serial and Art-Net.
Example output (Serial Monitor, 115200 Baud):
```
DMX: Univ: 0, Seq: 0, Data (48): 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
```
If this example is not working, don't try anything else!
### ArtnetWifiDebug2 (ArtnetWifiDebug with C++11 style)
See **ArtnetWifiDebug**.
**Note:** Not all controllers support this type of code!
### ArtnetWifiFastLED
This example will receive multiple universes via Art-Net and control a strip of WS2812 LEDs via the [FastLED library](https://github.com/FastLED/FastLED). It is similar to the NeoPixel example but it will work on the ESP32 and the ESP8266 controller as well.
### ArtnetWifiNeoPixel
This example will receive multiple universes via Art-Net and control a strip of WS2811 LEDs via Adafruit's [NeoPixel library](https://github.com/adafruit/Adafruit_NeoPixel).
### ArtnetWifiTransmit
This is a simple transmitter. Send 3 byte over into the Art-Net, to make a RGB light ramp-up in white.
### Notes
The examples `FastLED` and `NeoPixel` can utilize many universes to light up hundreds of LEDs.
Normaly Art-Net frame can handle 512 bytes. Divide this by 3 colors, so a single universe can
have 170.66 LEDs. For easy access, only 170 LEDs are used. The last 2 byte per universe are "lost".
**Example:** 240 LEDs, 720 Byte, 2 Universes
**Universe "1"**
|Byte | 1| 2| 3|...|508|509|510|511|512|
|:----|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|Color| R| G| B|...| R| G| B| x | x |
|LED | 1| 1| 1|...|170|170|170| | |
**Universe "2"**
|Byte | 1| 2| 3|...|208|209|210|
|:----|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
|Color| R| G| B|...| R| G| B|
|LED |171|171|171|...|240|240|240|
*You only have to send 510 byte DMX-data per frame. Extra byte(s) at the end will be ignored!*
# Art-Net
Art-Net(tm) is a trademark of Artistic Licence Holdings Ltd. The Art-Net protocol and associated documentation is copyright Artistic Licence Holdings Ltd.
[Art-Net](http://www.artisticlicence.com/WebSiteMaster/User%20Guides/art-net.pdf)

View File

@@ -0,0 +1,95 @@
/*
Example, transmit all received ArtNet messages (DMX) out of the serial port in plain text.
Stephan Ruloff 2016,2019
https://github.com/rstephan
*/
#include <ArtnetWifi.h>
#include <Arduino.h>
//Wifi settings
const char* ssid = "ssid";
const char* password = "pAsSwOrD";
WiFiUDP UdpSend;
ArtnetWifi artnet;
// connect to wifi returns true if successful or false if not
bool ConnectWifi(void)
{
bool state = true;
int i = 0;
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 20){
state = false;
break;
}
i++;
}
if (state) {
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(IPAddress(WiFi.localIP()));
} else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
{
bool tail = false;
Serial.print("DMX: Univ: ");
Serial.print(universe, DEC);
Serial.print(", Seq: ");
Serial.print(sequence, DEC);
Serial.print(", Data (");
Serial.print(length, DEC);
Serial.print("): ");
if (length > 16) {
length = 16;
tail = true;
}
// send out the buffer
for (uint16_t i = 0; i < length; i++)
{
Serial.print(data[i], HEX);
Serial.print(" ");
}
if (tail) {
Serial.print("...");
}
Serial.println();
}
void setup()
{
// set-up serial for debug output
Serial.begin(115200);
ConnectWifi();
// this will be called for each packet received
artnet.setArtDmxCallback(onDmxFrame);
artnet.begin();
}
void loop()
{
// we call the read function inside the loop
artnet.read();
}

View File

@@ -0,0 +1,96 @@
/*
Example, transmit all received ArtNet messages (Op-Code DMX) out of the
serial port in plain text.
Function pointer with the C++11 function-object "std::function".
Stephan Ruloff 2019
https://github.com/rstephan/ArtnetWifi
*/
#if defined(ARDUINO_AVR_UNO_WIFI_REV2)
#error "No C++11 support! Use a more powerful controller or the other 'ArtnetWifiDebug' example, sorry."
#endif
#include <ArtnetWifi.h>
#include <Arduino.h>
//Wifi settings
const char* ssid = "ssid";
const char* password = "pAsSwOrD";
WiFiUDP UdpSend;
ArtnetWifi artnet;
// connect to wifi returns true if successful or false if not
bool ConnectWifi(void)
{
bool state = true;
int i = 0;
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 20){
state = false;
break;
}
i++;
}
if (state) {
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
void setup()
{
// set-up serial for debug output
Serial.begin(115200);
ConnectWifi();
// this will be called for each packet received
artnet.setArtDmxFunc([](DMX_FUNC_PARAM){
bool tail = false;
Serial.print("DMX: Univ: ");
Serial.print(universe, DEC);
Serial.print(", Seq: ");
Serial.print(sequence, DEC);
Serial.print(", Data (");
Serial.print(length, DEC);
Serial.print("): ");
if (length > 16) {
length = 16;
tail = true;
}
// send out the buffer
for (uint16_t i = 0; i < length; i++) {
Serial.print(data[i], HEX);
Serial.print(" ");
}
if (tail) {
Serial.print("...");
}
Serial.println();
});
artnet.begin();
}
void loop()
{
// we call the read function inside the loop
artnet.read();
}

View File

@@ -0,0 +1,165 @@
/*
This example will receive multiple universes via Art-Net and control a strip of
WS2812 LEDs via the FastLED library: https://github.com/FastLED/FastLED
This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/
#include <ArtnetWifi.h>
#include <Arduino.h>
#include <FastLED.h>
// Wifi settings
const char* ssid = "ssid";
const char* password = "pAsSwOrD";
// LED settings
const int numLeds = 8; // CHANGE FOR YOUR SETUP
const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
const byte dataPin = 2;
CRGB leds[numLeds];
// Art-Net settings
ArtnetWifi artnet;
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
// Check if we got all universes
const int maxUniverses = numberOfChannels / 510 + ((numberOfChannels % 510) ? 1 : 0);
bool universesReceived[maxUniverses];
bool sendFrame = 1;
// connect to wifi returns true if successful or false if not
bool ConnectWifi(void)
{
bool state = true;
int i = 0;
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
if (i > 20)
{
state = false;
break;
}
i++;
}
if (state)
{
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
else
{
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
void initTest()
{
for (int i = 0 ; i < numLeds ; i++)
{
leds[i] = CRGB(127, 0, 0);
}
FastLED.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++)
{
leds[i] = CRGB(0, 127, 0);
}
FastLED.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++)
{
leds[i] = CRGB(0, 0, 127);
}
FastLED.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++)
{
leds[i] = CRGB(0, 0, 0);
}
FastLED.show();
}
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
{
sendFrame = 1;
// set brightness of the whole strip
if (universe == 15)
{
FastLED.setBrightness(data[0]);
FastLED.show();
}
// range check
if (universe < startUniverse)
{
return;
}
uint8_t index = universe - startUniverse;
if (index >= maxUniverses)
{
return;
}
// Store which universe has got in
universesReceived[index] = true;
for (int i = 0 ; i < maxUniverses ; i++)
{
if (!universesReceived[i])
{
sendFrame = 0;
break;
}
}
// read universe and put into the right part of the display buffer
for (int i = 0; i < length / 3; i++)
{
int led = i + (index * 170);
if (led < numLeds)
{
leds[led] = CRGB(data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
}
}
if (sendFrame)
{
FastLED.show();
// Reset universeReceived to 0
memset(universesReceived, 0, maxUniverses);
}
}
void setup()
{
Serial.begin(115200);
ConnectWifi();
artnet.begin();
FastLED.addLeds<WS2812, dataPin, GRB>(leds, numLeds);
initTest();
memset(universesReceived, 0, maxUniverses);
// this will be called for each packet received
artnet.setArtDmxCallback(onDmxFrame);
}
void loop()
{
// we call the read function inside the loop
artnet.read();
}

View File

@@ -0,0 +1,141 @@
/*
This example will receive multiple universes via Artnet and control a strip of ws2811 leds via
Adafruit's NeoPixel library: https://github.com/adafruit/Adafruit_NeoPixel
This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/
#include <ArtnetWifi.h>
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
//Wifi settings
const char* ssid = "ssid";
const char* password = "pAsSwOrD";
// Neopixel settings
const int numLeds = 240; // change for your setup
const int numberOfChannels = numLeds * 3; // Total number of channels you want to receive (1 led = 3 channels)
const byte dataPin = 2;
Adafruit_NeoPixel leds = Adafruit_NeoPixel(numLeds, dataPin, NEO_GRB + NEO_KHZ800);
// Artnet settings
ArtnetWifi artnet;
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
// Check if we got all universes
const int maxUniverses = numberOfChannels / 512 + ((numberOfChannels % 512) ? 1 : 0);
bool universesReceived[maxUniverses];
bool sendFrame = 1;
int previousDataLength = 0;
// connect to wifi returns true if successful or false if not
bool ConnectWifi(void)
{
bool state = true;
int i = 0;
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 20){
state = false;
break;
}
i++;
}
if (state){
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
void initTest()
{
for (int i = 0 ; i < numLeds ; i++)
leds.setPixelColor(i, 127, 0, 0);
leds.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++)
leds.setPixelColor(i, 0, 127, 0);
leds.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++)
leds.setPixelColor(i, 0, 0, 127);
leds.show();
delay(500);
for (int i = 0 ; i < numLeds ; i++)
leds.setPixelColor(i, 0, 0, 0);
leds.show();
}
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
{
sendFrame = 1;
// set brightness of the whole strip
if (universe == 15)
{
leds.setBrightness(data[0]);
leds.show();
}
// Store which universe has got in
if ((universe - startUniverse) < maxUniverses)
universesReceived[universe - startUniverse] = 1;
for (int i = 0 ; i < maxUniverses ; i++)
{
if (universesReceived[i] == 0)
{
//Serial.println("Broke");
sendFrame = 0;
break;
}
}
// read universe and put into the right part of the display buffer
for (int i = 0; i < length / 3; i++)
{
int led = i + (universe - startUniverse) * (previousDataLength / 3);
if (led < numLeds)
leds.setPixelColor(led, data[i * 3], data[i * 3 + 1], data[i * 3 + 2]);
}
previousDataLength = length;
if (sendFrame)
{
leds.show();
// Reset universeReceived to 0
memset(universesReceived, 0, maxUniverses);
}
}
void setup()
{
Serial.begin(115200);
ConnectWifi();
artnet.begin();
leds.begin();
initTest();
// this will be called for each packet received
artnet.setArtDmxCallback(onDmxFrame);
}
void loop()
{
// we call the read function inside the loop
artnet.read();
}

View File

@@ -0,0 +1,75 @@
/*
This example will transmit a universe via Art-Net into the Network.
This example may be copied under the terms of the MIT license, see the LICENSE file for details
*/
#include <ArtnetWifi.h>
#include <Arduino.h>
//Wifi settings
const char* ssid = "ssid"; // CHANGE FOR YOUR SETUP
const char* password = "pAsSwOrD"; // CHANGE FOR YOUR SETUP
// Artnet settings
ArtnetWifi artnet;
const int startUniverse = 0; // CHANGE FOR YOUR SETUP most software this is 1, some software send out artnet first universe as 0.
const char host[] = "2.1.1.1"; // CHANGE FOR YOUR SETUP your destination
// connect to wifi returns true if successful or false if not
bool ConnectWifi(void)
{
bool state = true;
int i = 0;
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (i > 20){
state = false;
break;
}
i++;
}
if (state){
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("");
Serial.println("Connection failed.");
}
return state;
}
void setup()
{
Serial.begin(115200);
ConnectWifi();
artnet.begin(host);
artnet.setLength(3);
artnet.setUniverse(startUniverse);
}
void loop()
{
uint8_t i;
uint8_t j;
// set the first 3 byte to all the same value. A RGB lamp will show a ramp-up white.
for (j = 0; j < 255; j++) {
for (i = 0; i < 3; i++) {
artnet.setByte(i, j);
}
// send out the Art-Net DMX data
artnet.write();
delay(100);
}
}

View File

@@ -0,0 +1,21 @@
# Datatypes
ArtnetWifi KEYWORD1
# Methods
begin KEYWORD2
read KEYWORD2
write KEYWORD2
setByte KEYWORD2
printPacketHeader KEYWORD2
printPacketContent KEYWORD2
getDmxFrame KEYWORD2
getOpcode KEYWORD2
getSequence KEYWORD2
getUniverse KEYWORD2
setUniverse KEYWORD2
setPhysical KEYWORD2
getLength KEYWORD2
setLength KEYWORD2
setArtDmxCallback KEYWORD2

View File

@@ -0,0 +1,9 @@
name=ArtnetWifi
version=1.6.2
author=Nathanaël Lécaudé,Stephan Ruloff
maintainer=Stephan Ruloff <stephan.ruloff@gmail.com>
sentence=ArtNet with the ESP8266, ESP32, RP2040 and more.
paragraph=Send and receive Art-Net frames using WiFi. Tested on ESP8266, ESP32, Pi Pico W, AmebaD, WiFi101 and WiFiNINA devices.
category=Communication
url=https://github.com/rstephan/ArtnetWifi
architectures=esp8266,esp32,samd,rp2040,megaavr,AmebaD

View File

@@ -0,0 +1,169 @@
/*The MIT License (MIT)
Copyright (c) 2014 Nathanaël Lécaudé
https://github.com/natcl/Artnet, http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811
Copyright (c) 2016,2019 Stephan Ruloff
https://github.com/rstephan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <ArtnetWifi.h>
const char ArtnetWifi::artnetId[] = ART_NET_ID;
ArtnetWifi::ArtnetWifi() : artDmxCallback(nullptr) {}
void ArtnetWifi::begin(String hostname)
{
Udp.begin(ART_NET_PORT);
host = hostname;
sequence = 1;
physical = 0;
}
void ArtnetWifi::stop(void)
{
Udp.stop();
}
uint16_t ArtnetWifi::read(void)
{
packetSize = Udp.parsePacket();
if (packetSize <= MAX_BUFFER_ARTNET && packetSize > 0)
{
senderIp = Udp.remoteIP();
Udp.read(artnetPacket, MAX_BUFFER_ARTNET);
// Check that packetID is "Art-Net" else ignore
if (memcmp(artnetPacket, artnetId, sizeof(artnetId)) != 0) {
return 0;
}
opcode = artnetPacket[8] | artnetPacket[9] << 8;
if (opcode == ART_DMX)
{
sequence = artnetPacket[12];
incomingUniverse = artnetPacket[14] | artnetPacket[15] << 8;
dmxDataLength = artnetPacket[17] | artnetPacket[16] << 8;
if (artDmxCallback) (*artDmxCallback)(incomingUniverse, dmxDataLength, sequence, artnetPacket + ART_DMX_START);
#if !defined(ARDUINO_AVR_UNO_WIFI_REV2)
if (artDmxFunc) {
artDmxFunc(incomingUniverse, dmxDataLength, sequence, artnetPacket + ART_DMX_START);
}
#endif
return ART_DMX;
}
if (opcode == ART_POLL)
{
return ART_POLL;
}
if (opcode == ART_SYNC)
{
return ART_SYNC;
}
}
return 0;
}
uint16_t ArtnetWifi::makePacket(void)
{
uint16_t len;
uint16_t version;
memcpy(artnetPacket, artnetId, sizeof(artnetId));
opcode = ART_DMX;
artnetPacket[8] = opcode;
artnetPacket[9] = opcode >> 8;
version = 14;
artnetPacket[11] = version;
artnetPacket[10] = version >> 8;
artnetPacket[12] = sequence;
sequence++;
if (!sequence) {
sequence = 1;
}
artnetPacket[13] = physical;
artnetPacket[14] = outgoingUniverse;
artnetPacket[15] = outgoingUniverse >> 8;
len = dmxDataLength + (dmxDataLength % 2); // make a even number
artnetPacket[17] = len;
artnetPacket[16] = len >> 8;
return len;
}
int ArtnetWifi::write(void)
{
uint16_t len;
len = makePacket();
Udp.beginPacket(host.c_str(), ART_NET_PORT);
Udp.write(artnetPacket, ART_DMX_START + len);
return Udp.endPacket();
}
int ArtnetWifi::write(IPAddress ip)
{
uint16_t len;
len = makePacket();
Udp.beginPacket(ip, ART_NET_PORT);
Udp.write(artnetPacket, ART_DMX_START + len);
return Udp.endPacket();
}
void ArtnetWifi::setByte(uint16_t pos, uint8_t value)
{
if (pos > 512) {
return;
}
artnetPacket[ART_DMX_START + pos] = value;
}
void ArtnetWifi::printPacketHeader(void)
{
Serial.print("packet size = ");
Serial.print(packetSize);
Serial.print("\topcode = ");
Serial.print(opcode, HEX);
Serial.print("\tuniverse number = ");
Serial.print(incomingUniverse);
Serial.print("\tdata length = ");
Serial.print(dmxDataLength);
Serial.print("\tsequence n0. = ");
Serial.println(sequence);
}
void ArtnetWifi::printPacketContent(void)
{
for (uint16_t i = ART_DMX_START ; i < dmxDataLength ; i++){
Serial.print(artnetPacket[i], DEC);
Serial.print(" ");
}
Serial.println('\n');
}

View File

@@ -0,0 +1,173 @@
/*The MIT License (MIT)
Copyright (c) 2014 Nathanaël Lécaudé
https://github.com/natcl/Artnet, http://forum.pjrc.com/threads/24688-Artnet-to-OctoWS2811
Copyright (c) 2016,2019 Stephan Ruloff
https://github.com/rstephan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef ARTNET_WIFI_H
#define ARTNET_WIFI_H
#include <Arduino.h>
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_RASPBERRY_PI_PICO_2W)
#include <WiFi.h>
#include <functional>
#elif defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <functional>
#elif defined(ARDUINO_ARCH_SAMD)
#if defined(ARDUINO_SAMD_MKR1000)
#include <WiFi101.h>
#else
#include <WiFiNINA.h>
#endif
#include <functional>
#elif defined(ARDUINO_AVR_UNO_WIFI_REV2)
#include <WiFiNINA.h>
#elif defined(ARDUINO_ARCH_AMEBAD)
#include <WiFi.h>
#include <functional>
#else
#error "Architecture not supported!"
#endif
#include <WiFiUdp.h>
// UDP specific
#define ART_NET_PORT 6454
// Opcodes
#define ART_POLL 0x2000
#define ART_DMX 0x5000
#define ART_SYNC 0x5200
// Buffers
#define MAX_BUFFER_ARTNET 530
// Packet
#define ART_NET_ID "Art-Net"
#define ART_DMX_START 18
#define DMX_FUNC_PARAM uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data
#if !defined(ARDUINO_AVR_UNO_WIFI_REV2)
typedef std::function <void (DMX_FUNC_PARAM)> StdFuncDmx_t;
#endif
class ArtnetWifi
{
public:
ArtnetWifi();
void begin(String hostname = "");
uint16_t read(void);
/* returns 1 for Ok, or 0 on problem */
int write(void);
int write(IPAddress ip);
void setByte(uint16_t pos, uint8_t value);
void printPacketHeader(void);
void printPacketContent(void);
void stop(void);
// Return a pointer to the start of the DMX data
inline uint8_t* getDmxFrame(void)
{
return artnetPacket + ART_DMX_START;
}
inline uint16_t getOpcode(void)
{
return opcode;
}
inline uint8_t getSequence(void)
{
return sequence;
}
inline uint16_t getUniverse(void)
{
return incomingUniverse;
}
inline void setUniverse(uint16_t universe)
{
outgoingUniverse = universe;
}
inline void setPhysical(uint8_t port)
{
physical = port;
}
[[deprecated]]
inline void setPhisical(uint8_t port)
{
setPhysical(port);
}
inline uint16_t getLength(void)
{
return dmxDataLength;
}
inline void setLength(uint16_t len)
{
dmxDataLength = len;
}
inline void setArtDmxCallback(void (*fptr)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data))
{
artDmxCallback = fptr;
}
#if !defined(ARDUINO_AVR_UNO_WIFI_REV2)
inline void setArtDmxFunc(StdFuncDmx_t func)
{
artDmxFunc = func;
}
#endif
inline IPAddress& getSenderIp()
{
return senderIp;
}
private:
uint16_t makePacket(void);
WiFiUDP Udp;
String host;
uint8_t artnetPacket[MAX_BUFFER_ARTNET];
uint16_t packetSize;
uint16_t opcode;
uint8_t sequence;
uint8_t physical;
uint16_t incomingUniverse;
uint16_t outgoingUniverse;
uint16_t dmxDataLength;
void (*artDmxCallback)(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data);
#if !defined(ARDUINO_AVR_UNO_WIFI_REV2)
StdFuncDmx_t artDmxFunc;
#endif
static const char artnetId[];
IPAddress senderIp;
};
#endif