Created
November 21, 2021 01:30
-
-
Save nandenjin/58305da7ea01859ae771223258f8ec92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <WiFiUdp.h> | |
#define START_ADDR 1 | |
#define SSID "***" | |
#define PASSWORD "***" | |
#define ART_NET_PORT 6454 | |
#define ART_NET_ID "Art-Net\0" | |
#define ART_DMX_START 18 | |
#define ART_DMX 0x5000 | |
#define MAX_BUFFER_ARTNET 1024 | |
static WiFiUDP Udp; | |
uint8_t artnetPacket[MAX_BUFFER_ARTNET]; | |
uint16_t incomingUniverse; | |
uint16_t dmxDataLength; | |
uint8_t values[32]; | |
void setup() { | |
Serial.begin(115200); | |
Serial.setTimeout(100); | |
Serial1.begin(250000, SERIAL_8N2); | |
// WiFi.config(ip, gateway, subnet); | |
WiFi.begin(SSID, PASSWORD); | |
while ( WiFi.status() != WL_CONNECTED ) { | |
delay(100); | |
delay(100); | |
} | |
Udp.begin(ART_NET_PORT); | |
Serial.println(WiFi.localIP()); | |
} | |
void loop() { | |
if ( WiFi.status() != WL_CONNECTED ) { | |
delay(100); | |
ESP.restart(); | |
} | |
if (readArtnet() == ART_DMX) | |
{ | |
// print out our data | |
Serial.print("DMX data: "); | |
for (int i = 0; i < 32; i++) | |
{ | |
//Serial.print(artnet.getDmxFrame()[i]); | |
values[i] = ( artnetPacket + ART_DMX_START )[i + START_ADDR - 1]; | |
Serial.print( values[i] ); | |
Serial.print(" "); | |
} | |
Serial.println(); | |
Serial.println(); | |
} | |
delay(10); | |
Serial1.flush(); | |
Serial1.begin(90000, SERIAL_8N2); | |
while (Serial1.available()) Serial1.read(); | |
// send the break as a "slow" byte | |
Serial1.write(0); | |
// switch back to the original baud rate | |
Serial1.flush(); | |
Serial1.begin(250000, SERIAL_8N2); | |
while (Serial1.available()) Serial1.read(); | |
Serial1.write(0); // Start Code | |
for (int i = 0; i < 32; i++) Serial1.write(values[i]); | |
} | |
uint16_t readArtnet() { | |
uint16_t packetSize = Udp.parsePacket(); | |
if (packetSize <= MAX_BUFFER_ARTNET && packetSize > 0) | |
{ | |
Udp.read(artnetPacket, MAX_BUFFER_ARTNET); | |
// Check that packetID is "Art-Net" else ignore | |
for (byte i = 0 ; i < 9 ; i++) | |
{ | |
if (artnetPacket[i] != ART_NET_ID[i]) | |
return 0; | |
} | |
uint16_t 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; | |
return ART_DMX; | |
} | |
} | |
else | |
{ | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment