Hallo liebe Leute,
ich versuche gerade DMX Packete die ich über einen Mega empfange über Wifi zu senden und scheitere leider daran.
Über Ethernet funktioniert alles einwandfrei, aber ESP ist mir noch neu.
Mein vorhaben ist die Daten die ich über ein Ethernet-Shield an einen Router und der weiter an das Empfangsgerät schickt, über einen ESP01 an den Router und an das Empfangsgerät schicke.
Habt ihr Ideen wie man das verwirklichen kann?
Bis jetzt hab ich am Mega an Serial 1 und 2 das DMX Signal anliegen und möchte die selben Daten die ich über Ethernet schicke über WiFi schicken und dachte mir ich verwende dazu Serial 3.
Der gedanke ist es wenn das Ethernet nicht verbunden ist, es über WiFi sendet.
Hier der Code des Mega:
#include <SPI.h>
#include <Ethernet.h>
#include <lib_dmx.h>
#define DMX512 (0) // (250 kbaud - 2 to 512 channels) Standard USITT DMX-512
byte destination_Ip[] = { 192, 168, 137, 210 }; // the ip to send data, 255,255,255,255 is broadcast sending
// art net parameters
unsigned int localPort = 6454; // artnet UDP port is by default 6454
const int DMX_Universe = 0; //universe is from 0 to 15, subnet is not used
const int number_of_channels = 512; //512 for 512 channels, MAX=512
byte ip[] = { 192, 168, 137, 220 };
byte mac[] = { 0xA8, 0x61, 0x0A, 0xAE, 0xAA, 0x39 };
IPAddress subnet(255, 255, 255, 0);
EthernetUDP UdpEthernet;
//ART-NET variables
char ArtNetHead[8] = "Art-Net";
const int art_net_header_size = 17;
short OpOutput = 0x5000; //output
//Artnet PACKET
byte ArtDmxBuffer[(art_net_header_size + number_of_channels) + 8 + 1];
void setup() {
// Init Artnet
Ethernet.begin(mac, ip);
Serial3.begin(115200);
UdpEthernet.begin(localPort);
//initialise artnet header
construct_arnet_packet1();
construct_arnet_packet2();
ArduinoDmx1.set_control_pin(24); // Arduino output pin for MAX485 input/output control (connect to MAX485-1 pins 2-3)
ArduinoDmx2.set_control_pin(26); // Arduino output pin for MAX485 input/output control (connect to MAX485-2 pins 2-3)
ArduinoDmx1.set_rx_address(1); // set rx1 start address
ArduinoDmx2.set_rx_address(1); // set rx2 start address
ArduinoDmx1.set_rx_channels(512); // 2 to 2048!! channels in DMX1000K (512 in standard mode) See lib_dmx.h
ArduinoDmx2.set_rx_channels(512); // 2 to 2048!! channels in DMX1000K (512 in standard mode) See lib_dmx.h
// New parameter needed: DMX Mode
ArduinoDmx1.init_rx(DMX512); // starts universe 1 as rx, standard DMX 512 - See lib_dmx.h, now support for DMX faster modes (DMX 1000K)
ArduinoDmx2.init_rx(DMX512); // starts universe 2 as rx, standard DMX 512 - See lib_dmx.h, now support for DMX faster modes (DMX 1000K)
} //end setup()
void loop() {
construct_arnet_packet1();
UdpEthernet.beginPacket(destination_Ip, localPort);
UdpEthernet.write(ArtDmxBuffer, (art_net_header_size + number_of_channels + 1)); // was Udp.sendPacket
UdpEthernet.endPacket();
Serial3.write(ArtDmxBuffer, (art_net_header_size + number_of_channels + 1));
construct_arnet_packet2();
UdpEthernet.beginPacket(destination_Ip, localPort);
UdpEthernet.write(ArtDmxBuffer, (art_net_header_size + number_of_channels + 1)); // was Udp.sendPacket
UdpEthernet.endPacket();
Serial3.write(ArtDmxBuffer, (art_net_header_size + number_of_channels + 1));
} //end loop()
void construct_arnet_packet1() {
//preparation pour tests
for (int i = 0; i < 7; i++) {
ArtDmxBuffer[i] = ArtNetHead[i];
}
//Operator code low byte first
ArtDmxBuffer[8] = OpOutput;
ArtDmxBuffer[9] = OpOutput >> 8;
//protocole
ArtDmxBuffer[10] = 0;
ArtDmxBuffer[11] = 14;
//sequence
ArtDmxBuffer[12] = 0;
//physical
ArtDmxBuffer[13] = 0;
// universe
ArtDmxBuffer[14] = DMX_Universe; //oder 1
ArtDmxBuffer[15] = DMX_Universe >> 8;
//data length
ArtDmxBuffer[16] = number_of_channels >> 8;
ArtDmxBuffer[17] = number_of_channels;
int t = 0;
while (t < 512) {
ArtDmxBuffer[t + art_net_header_size + 1] = ArduinoDmx1.RxBuffer[t];
t++;
}
}
void construct_arnet_packet2() {
//preparation pour tests
for (int i = 0; i < 7; i++) {
ArtDmxBuffer[i] = ArtNetHead[i];
}
//Operator code low byte first
ArtDmxBuffer[8] = OpOutput;
ArtDmxBuffer[9] = OpOutput >> 8;
//protocole
ArtDmxBuffer[10] = 0;
ArtDmxBuffer[11] = 14;
//sequence
ArtDmxBuffer[12] = 0;
//physical
ArtDmxBuffer[13] = 0;
// universe
ArtDmxBuffer[14] = 1; //oder 0
ArtDmxBuffer[15] = DMX_Universe >> 8;
//data length
ArtDmxBuffer[16] = number_of_channels >> 8;
ArtDmxBuffer[17] = number_of_channels;
int j = 0;
while (j < 512) {
ArtDmxBuffer[j + art_net_header_size + 1] = ArduinoDmx2.RxBuffer[j];
j++;
}
}
und hier der des ESP01:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#ifndef STASSID
#define STASSID "xxx"
#define STAPSK "xxx"
#endif
unsigned int localPort = 8888; // local port to listen on
unsigned int remoteIP = (192,168,137,210);
unsigned int destinationIP = (192,168,137,210);
// buffers for receiving and sending data
//char packetBuffer[UDP_TX_PACKET_MAX_SIZE + 1]; // buffer to hold incoming packet,
//char ReplyBuffer[] = "acknowledged\r\n"; // a string to send back
WiFiUDP Udp;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(STASSID, STAPSK);
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(500);
}
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
Serial.printf("UDP server on port %d\n", localPort);
Udp.begin(localPort);
}
void loop() {
Udp.beginPacket(Udp.destinationIP(), Udp.localPort());
// Udp.write(ReplyBuffer);
Udp.write(Serial.read());
Udp.endPacket();
}
Ich hoffe ihr könnt mir weiterhelfen
LG