Merge pull request #37 from HendrikRauh/DMX-5-switch-connection

Dmx 5 switch connection
This commit is contained in:
Raffael Wolf 2024-12-13 20:21:35 +01:00 committed by GitHub
commit 3c5d605b67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 453 additions and 75 deletions

6
.gitmodules vendored Normal file
View file

@ -0,0 +1,6 @@
[submodule "lib/ArtNet"]
path = lib/ArtNet
url = https://github.com/psxde/ArtNet.git
[submodule "lib/AsyncWebServer_ESP32_W5500"]
path = lib/AsyncWebServer_ESP32_W5500
url = https://github.com/psxde/AsyncWebServer_ESP32_W5500.git

1
data/icons/refresh.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFF"><path d="M480-160q-134 0-227-93t-93-227q0-134 93-227t227-93q69 0 132 28.5T720-690v-110h80v280H520v-80h168q-32-56-87.5-88T480-720q-100 0-170 70t-70 170q0 100 70 170t170 70q77 0 139-44t87-116h84q-28 106-114 173t-196 67Z"/></svg>

After

Width:  |  Height:  |  Size: 330 B

View file

@ -8,6 +8,7 @@
<script type="module" src="/input-visibility.js" defer></script> <script type="module" src="/input-visibility.js" defer></script>
<script type="module" src="/loading-screen.js" defer></script> <script type="module" src="/loading-screen.js" defer></script>
<script type="module" src="/load-data.js" defer></script> <script type="module" src="/load-data.js" defer></script>
<script type="module" src="/networks.js" defer></script>
<script type="module" src="/submit.js" defer></script> <script type="module" src="/submit.js" defer></script>
<script type="module" src="/reset.js" defer></script> <script type="module" src="/reset.js" defer></script>
</head> </head>
@ -32,8 +33,8 @@
<h1>Konfiguration</h1> <h1>Konfiguration</h1>
<fieldset> <fieldset>
<legend>Verbindung</legend> <legend>Verbindung</legend>
<label for="ip-method" <label>
>IP-Zuweisung: <span>IP-Zuweisung:</span>
<select <select
name="ip-method" name="ip-method"
id="input-ip-method" id="input-ip-method"
@ -45,7 +46,7 @@
</label> </label>
<div data-field="input-ip-method" data-values="0"> <div data-field="input-ip-method" data-values="0">
<label> <label>
IP-Adresse: <span>IP-Adresse:</span>
<input <input
type="text" type="text"
name="ip" name="ip"
@ -54,7 +55,7 @@
/> />
</label> </label>
<label> <label>
Subnetzmaske: <span>Subnetzmaske:</span>
<input <input
type="text" type="text"
name="subnet" name="subnet"
@ -63,7 +64,7 @@
/> />
</label> </label>
<label> <label>
Gateway: <span>Gateway:</span>
<input <input
type="text" type="text"
name="gateway" name="gateway"
@ -73,20 +74,20 @@
</label> </label>
</div> </div>
<label> <label>
Verbindungsmethode: <span>Verbindungsmethode:</span>
<select <select
name="connection" name="connection"
id="input-connection" id="input-connection"
title="Verbindung" title="Verbindung"
> >
<option value="0">WiFi-AccessPoint</option> <option value="0">WiFi-Station</option>
<option value="1">WiFi-Station</option> <option value="1">WiFi-AccessPoint</option>
<option value="2">Ethernet</option> <option value="2">Ethernet</option>
</select> </select>
</label> </label>
<div data-field="input-connection" data-values="0"> <div data-field="input-connection" data-values="1">
<label> <label>
SSID: <span>SSID:</span>
<input <input
type="text" type="text"
name="ssid" name="ssid"
@ -95,19 +96,26 @@
/> />
</label> </label>
</div> </div>
<div data-field="input-connection" data-values="1"> <div data-field="input-connection" data-values="0">
<label> <label>
Netzwerk: <span>Netzwerk:</span>
<select <select
name="ssid" name="ssid"
id="input-network" id="select-network"
title="Netzwerk" title="Netzwerk"
></select> ></select>
<button
type="button"
id="refresh-networks"
class="icon-button"
>
<img src="/icons/refresh.svg" alt="Neu laden" />
</button>
</label> </label>
</div> </div>
<div data-field="input-connection" data-values="0|1"> <div data-field="input-connection" data-values="0|1">
<label> <label>
Password: <span>Password:</span>
<input <input
type="password" type="password"
name="password" name="password"

60
data/networks.js Normal file
View file

@ -0,0 +1,60 @@
const networkDropdown = document.querySelector("#select-network");
const refreshButton = document.querySelector("#refresh-networks");
const refreshIcon = refreshButton.querySelector("img");
let isLoading = false;
refreshButton.addEventListener("click", async () => {
updateNetworks();
});
function insertNetworks(networks) {
networks.unshift(""); // add empty option
networkDropdown.textContent = ""; // clear dropdown
for (const ssid of networks) {
const option = document.createElement("option");
option.value = ssid;
option.innerText = ssid;
networkDropdown.appendChild(option);
}
}
async function loadNetworks() {
if (isLoading) return;
isLoading = true;
refreshButton.classList.remove("error-bg");
refreshIcon.classList.add("spinning");
try {
const res = await fetch("/networks", {
method: "GET",
});
if (!res.ok) {
throw Error(`response status: ${res.status}`);
}
const networks = await res.json();
refreshIcon.classList.remove("spinning");
isLoading = false;
// remove duplicate values
return Array.from(new Set(networks));
} catch (e) {
refreshIcon.classList.remove("spinning");
refreshButton.classList.add("error-bg");
isLoading = false;
return [];
}
}
async function updateNetworks() {
const networks = await loadNetworks();
if (networks) {
insertNetworks(networks);
}
}
updateNetworks();

View file

@ -3,6 +3,7 @@
--color-on-primary: white; --color-on-primary: white;
--color-background: #222; --color-background: #222;
--color-danger: #fa2b58; --color-danger: #fa2b58;
--icon-button-size: 2.5rem;
} }
body { body {
@ -38,11 +39,16 @@ fieldset {
label { label {
display: block; display: block;
display: flex; display: flex;
gap: 8px;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
flex-wrap: wrap; flex-wrap: wrap;
} }
label span {
flex-grow: 1;
}
input, input,
select { select {
width: clamp(200px, 100%, 400px); width: clamp(200px, 100%, 400px);
@ -60,6 +66,10 @@ select:focus {
border-color: var(--color-primary); border-color: var(--color-primary);
} }
select:has(+ .icon-button) {
width: calc(clamp(200px, 100%, 400px) - var(--icon-button-size) - 8px);
}
button { button {
border: none; border: none;
inset: none; inset: none;
@ -143,10 +153,14 @@ label.switch input:checked + .slider::before {
justify-content: center; justify-content: center;
} }
h2.error { .error {
color: var(--color-danger); color: var(--color-danger);
} }
.error-bg {
background-color: var(--color-danger) !important;
}
button.reload { button.reload {
display: block; display: block;
margin: 0 auto; margin: 0 auto;
@ -195,3 +209,17 @@ button.reload {
transform: rotate(360deg); transform: rotate(360deg);
} }
} }
.icon-button {
padding: 8px;
font-size: 0;
width: var(--icon-button-size);
height: var(--icon-button-size);
}
.spinning {
animation-name: spin;
animation-duration: 0.5s;
animation-iteration-count: infinite;
animation-timing-function: linear;
}

1
lib/ArtNet Submodule

@ -0,0 +1 @@
Subproject commit 5d9c42b531404ccfbcb14106d6312b03a166868a

@ -0,0 +1 @@
Subproject commit 38de6ac248c7f270ca3b77ba38512ba39919aed8

View file

@ -18,7 +18,5 @@ board_build.filesystem = littlefs
[env:lolin_s2_mini] [env:lolin_s2_mini]
platform = espressif32 platform = espressif32
board = lolin_s2_mini board = lolin_s2_mini
lib_deps = lib_deps =
hideakitai/ArtNet @ ^0.8.0
bblanchon/ArduinoJson @ ^7.2.0 bblanchon/ArduinoJson @ ^7.2.0
me-no-dev/ESP Async WebServer

View file

@ -7,11 +7,16 @@
// uint8_t dmxDataStores[MAX_IDS][DMXCHANNELS + 1]; // uint8_t dmxDataStores[MAX_IDS][DMXCHANNELS + 1];
// Set up the DMX-Protocol // Set up the DMX-Protocol
void DMXESPSerial::init(int pinSend = 19, int pinRecv = -1) void DMXESPSerial::init(int pinSend = DMX_DEFAULT_TX, int pinRecv = DMX_DEFAULT_RX, HardwareSerial& port = DMX_DEFAULT_PORT)
{ {
sendPin = pinSend; sendPin = pinSend;
recvPin = pinRecv; recvPin = pinRecv;
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin); _Serial = &port;
_Serial->begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
Serial.print("Init DMX with pins (TX/RX): ");
Serial.print(sendPin);
Serial.print("/");
Serial.println(recvPin);
pinMode(sendPin, OUTPUT); pinMode(sendPin, OUTPUT);
dmxStarted = true; dmxStarted = true;
} }
@ -28,6 +33,14 @@ uint8_t DMXESPSerial::read(int channel)
channel = DMXCHANNELS; channel = DMXCHANNELS;
return (dmxDataStore[channel]); return (dmxDataStore[channel]);
} }
uint8_t* DMXESPSerial::readAll()
{
if (dmxStarted == false)
init();
return (&dmxDataStore[1]);
}
// Function to send DMX data // Function to send DMX data
void DMXESPSerial::write(int channel, uint8_t value) void DMXESPSerial::write(int channel, uint8_t value)
@ -40,17 +53,13 @@ void DMXESPSerial::write(int channel, uint8_t value)
channel = 1; channel = 1;
if (channel > DMXCHANNELS) if (channel > DMXCHANNELS)
channel = DMXCHANNELS; channel = DMXCHANNELS;
if (value < 0)
value = 0;
if (value > 255)
value = 255;
dmxDataStore[channel] = value; dmxDataStore[channel] = value;
} }
void DMXESPSerial::end() void DMXESPSerial::end()
{ {
SERIALPORT.end(); _Serial->end();
} }
// Function to update the DMX bus // Function to update the DMX bus
@ -58,17 +67,17 @@ void DMXESPSerial::update()
{ {
// Send break // Send break
digitalWrite(sendPin, HIGH); digitalWrite(sendPin, HIGH);
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin, sendPin); _Serial->begin(BREAKSPEED, BREAKFORMAT, recvPin, sendPin);
SERIALPORT.write(0); _Serial->write(0);
SERIALPORT.flush(); _Serial->flush();
delay(1); delay(1);
SERIALPORT.end(); _Serial->end();
// send data // send data
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin); _Serial->begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
digitalWrite(sendPin, LOW); digitalWrite(sendPin, LOW);
SERIALPORT.write(dmxDataStore, DMXCHANNELS); _Serial->write(dmxDataStore, DMXCHANNELS);
SERIALPORT.flush(); _Serial->flush();
delay(1); delay(1);
SERIALPORT.end(); _Serial->end();
} }

View file

@ -1,4 +1,5 @@
#include <inttypes.h> #include <inttypes.h>
#include <HardwareSerial.h>
#ifndef ESPDMX_h #ifndef ESPDMX_h
#define ESPDMX_h #define ESPDMX_h
@ -7,7 +8,9 @@
#define DMXFORMAT SERIAL_8N2 #define DMXFORMAT SERIAL_8N2
#define BREAKSPEED 83333 #define BREAKSPEED 83333
#define BREAKFORMAT SERIAL_8N1 #define BREAKFORMAT SERIAL_8N1
#define SERIALPORT Serial0 #define DMX_DEFAULT_PORT Serial0
#define DMX_DEFAULT_TX 21
#define DMX_DEFAULT_RX 33
#define DMXCHANNELS 512 #define DMXCHANNELS 512
class DMXESPSerial class DMXESPSerial
@ -15,14 +18,20 @@ class DMXESPSerial
public: public:
int sendPin; int sendPin;
int recvPin; int recvPin;
HardwareSerial *port;
bool dmxStarted; bool dmxStarted;
uint8_t dmxDataStore[DMXCHANNELS + 1]; uint8_t dmxDataStore[DMXCHANNELS + 1];
void init(int pinSend, int pinRecv); void init(int pinSend, int pinRecv, HardwareSerial& port);
uint8_t read(int Channel); uint8_t read(int channel);
uint8_t* readAll();
void write(int channel, uint8_t value); void write(int channel, uint8_t value);
void update(); void update();
void end(); void end();
private:
// Member variables
HardwareSerial* _Serial;
}; };
#endif #endif

View file

@ -1,77 +1,285 @@
#ifdef ESP32
#include <WiFi.h>
#include <AsyncTCP.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#endif
#include <AsyncWebServer_ESP32_W5500.h>
// #include "w5500/esp32_w5500.h"
// #include <ESPAsyncWebServer.h>
#include <ArtnetWiFi.h> #include <ArtnetWiFi.h>
// #include <ArtnetEther.h> #include <ArduinoJson.h>
#include "ESPDMX.h" #include "ESPDMX.h"
#include <ESPAsyncWebServer.h>
#include <LittleFS.h> #include <LittleFS.h>
#include "routes/config.h" #include "routes/config.h"
DMXESPSerial dmx1; DMXESPSerial dmx1;
DMXESPSerial dmx2; DMXESPSerial dmx2;
// Button
#define PIN_LED 7
#define PIN_BUTTON 5
uint8_t brightness_led = 20;
bool status_led;
hw_timer_t *timer = NULL; // H/W timer defining (Pointer to the Structure)
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR onTimer()
{ // Defining Inerrupt function with IRAM_ATTR for faster access
portENTER_CRITICAL_ISR(&timerMux);
status_led = !status_led;
if (!status_led)
{
analogWrite(PIN_LED, brightness_led);
}
else
{
analogWrite(PIN_LED, 0);
}
portEXIT_CRITICAL_ISR(&timerMux);
}
// Ethernet stuff
#define ETH_SCK 36
#define ETH_SS 34
#define ETH_MOSI 35
#define ETH_MISO 37
#define ETH_INT 38
#define ETH_SPI_HOST SPI2_HOST
#define ETH_SPI_CLOCK_MHZ 25
byte mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
AsyncWebServer server(80); AsyncWebServer server(80);
ArtnetWiFi artnet; ArtnetWiFi artnet;
DMXESPSerial dmx;
const uint16_t size = 512; String broadcastIp;
uint8_t data[size]; uint8_t universe1;
uint8_t universe2;
Direction direction1;
Direction direction2;
// const uint16_t size = 512;
// uint8_t data[DMXCHANNELS];
void ledBlink(int ms)
{
if (timer == NULL)
{
timer = timerBegin(0, 80, true); // timer 0, prescalar: 80, UP counting
timerAttachInterrupt(timer, &onTimer, true); // Attach interrupt
}
if (ms == 0)
{
timerAlarmDisable(timer);
analogWrite(PIN_LED, 0);
}
else if (ms == 1)
{
timerAlarmDisable(timer);
analogWrite(PIN_LED, brightness_led);
}
else
{
ms = ms * 1000;
timerAlarmWrite(timer, ms, true); // Match value= 1000000 for 1 sec. delay.
timerAlarmEnable(timer); // Enable Timer with interrupt (Alarm Enable)
}
}
void setup() void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
// Get ETH mac
esp_read_mac(mac, ESP_MAC_ETH);
// LED
analogWrite(PIN_LED, brightness_led);
// delay(5000);
ledBlink(500);
// Button
pinMode(PIN_BUTTON, INPUT_PULLUP);
if (digitalRead(PIN_BUTTON) == LOW)
{
ledBlink(100);
delay(2000);
Serial.println("Reset config");
config.begin("dmx", false);
config.clear();
config.end();
}
// wait for serial monitor
delay(5000);
Serial.println("Starting DMX-Interface...");
config.begin("dmx", true); config.begin("dmx", true);
uint8_t universe1 = config.getUChar("universe-1", 1); universe1 = config.getUInt("universe-1", 1);
uint8_t universe2 = config.getUChar("universe-2", 1); universe2 = config.getUInt("universe-2", 1);
Direction direction1 = static_cast<Direction>(config.getUInt("direction-1", 0)); direction1 = static_cast<Direction>(config.getUInt("direction-1", 0));
Direction direction2 = static_cast<Direction>(config.getUInt("direction-2", 1)); direction2 = static_cast<Direction>(config.getUInt("direction-2", 1));
Connection connection = static_cast<Connection>(config.getUInt("connection", WiFiSta)); Serial.print("Port A: Universe ");
IpMethod ipMethod = static_cast<IpMethod>(config.getUInt("ip-method"), Static); Serial.print(universe1);
Serial.print(" ");
Serial.println((direction1 == Input) ? "DMX -> Art-Net" : "Art-Net -> DMX");
String ssid = config.getString("ssid", "artnet"); Serial.print("Port B: Universe ");
Serial.print(universe2);
Serial.print(" ");
Serial.println((direction2 == Input) ? "DMX -> Art-Net" : "Art-Net -> DMX");
Connection connection = static_cast<Connection>(config.getUInt("connection", WiFiAP));
IpMethod ipMethod = static_cast<IpMethod>(config.getUInt("ip-method"), DHCP);
WiFi.macAddress(mac);
char hostname[30];
snprintf(hostname, sizeof(hostname), "ChaosDMX-%02X%02X", mac[4], mac[5]);
Serial.print("Hostname: ");
Serial.println(hostname);
String ssid = config.getString("ssid", hostname);
String pwd = config.getString("password", "mbgmbgmbg"); String pwd = config.getString("password", "mbgmbgmbg");
IPAddress defaultIp(192, 168, 1, 201);
// Default IP as defined in standard https://art-net.org.uk/downloads/art-net.pdf, page 13
IPAddress defaultIp(2, mac[3], mac[4], mac[5]);
IPAddress ip = config.getUInt("ip", defaultIp); IPAddress ip = config.getUInt("ip", defaultIp);
IPAddress defaultSubnet(255, 255, 255, 0); IPAddress defaultSubnet(255, 0, 0, 0);
IPAddress subnet = config.getUInt("subnet", defaultSubnet); IPAddress subnet = config.getUInt("subnet", defaultSubnet);
IPAddress defaultGateway(192, 168, 1, 1); IPAddress defaultGateway(2, 0, 0, 1);
IPAddress gateway = config.getUInt("gateway", defaultGateway); IPAddress gateway = config.getUInt("gateway", defaultGateway);
config.end(); config.end();
// WiFi stuff switch (connection)
// WiFi.begin(ssid, pwd); {
WiFi.softAP(ssid, pwd); case WiFiSta:
WiFi.softAPConfig(ip, gateway, subnet); Serial.println("Initialize as WiFi Station");
// WiFi.config(ip, gateway, subnet); WiFi.setHostname(hostname);
// while (WiFi.status() != WL_CONNECTED) { WiFi.begin(ssid, pwd);
// Serial.print("."); Serial.println("SSID: " + ssid + ", pwd: " + pwd);
delay(500); if (ipMethod == Static)
//} {
// Serial.print("WiFi connected, IP = "); WiFi.config(ip, gateway, subnet);
// Serial.println(WiFi.localIP()); Serial.println("IP: " + ip.toString() + ", gateway: " + gateway + ", subnet: " + subnet);
}
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
broadcastIp = String(WiFi.broadcastIP().toString().c_str());
Serial.println("");
Serial.print("WiFi connected, IP = ");
Serial.println(WiFi.localIP());
Serial.print("MAC address: ");
Serial.println(WiFi.macAddress());
break;
// Initialize Art-Net case Ethernet:
artnet.begin(); {
Serial.println("Initialize as ETH");
ESP32_W5500_onEvent();
if (ETH.begin(ETH_MISO, ETH_MOSI, ETH_SCK, ETH_SS, ETH_INT, ETH_SPI_CLOCK_MHZ, ETH_SPI_HOST, mac))
{ // Dynamic IP setup
}
else
{
Serial.println("Failed to configure Ethernet");
}
ETH.setHostname(hostname);
// ESP32_W5500_waitForConnect();
uint8_t timeout = 5; // in s
Serial.print("Wait for connect");
while (!ESP32_W5500_eth_connected && timeout > 0)
{
delay(1000);
timeout--;
Serial.print(".");
}
Serial.println();
if (ESP32_W5500_eth_connected)
{
Serial.println("DHCP OK!");
}
else
{
Serial.println("Set static IP");
ETH.config(ip, gateway, subnet);
}
broadcastIp = ETH.broadcastIP().toString();
Serial.print("Local IP : ");
Serial.println(ETH.localIP());
Serial.print("Subnet Mask : ");
Serial.println(ETH.subnetMask());
Serial.print("Gateway IP : ");
Serial.println(ETH.gatewayIP());
Serial.print("DNS Server : ");
Serial.println(ETH.dnsIP());
Serial.print("MAC address : ");
Serial.println(ETH.macAddress());
Serial.println("Ethernet Successfully Initialized");
break;
}
default:
Serial.println("Initialize as WiFi AccessPoint");
WiFi.softAPsetHostname(hostname);
WiFi.softAP(ssid, pwd);
// AP always with DHCP
// WiFi.softAPConfig(ip, gateway, subnet);
broadcastIp = WiFi.softAPBroadcastIP().toString();
Serial.print("WiFi AP enabled, IP = ");
Serial.println(WiFi.softAPIP());
Serial.print("MAC address: ");
Serial.println(WiFi.softAPmacAddress());
break;
}
// Initialize DMX ports // Initialize DMX ports
dmx1.init(19, -1); Serial.println("Initialize DMX...");
dmx1.init(21, 33, Serial0);
dmx2.init(17, 18, Serial1);
// Initialize Art-Net
Serial.println("Initialize Art-Net...");
artnet.begin();
// if Artnet packet comes to this universe, this function is called // if Artnet packet comes to this universe, this function is called
artnet.subscribeArtDmxUniverse(universe1, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) if (direction1 == Output)
{ {
for (size_t i = 0; i < size; ++i) artnet.subscribeArtDmxUniverse(universe1, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote)
{ {
dmx1.write((i + 1), data[i]); for (size_t i = 0; i < size; ++i)
} {
dmx1.write((i + 1), data[i]);
}
dmx1.update(); });
}
dmx1.update(); }); if (direction2 == Output)
{
artnet.subscribeArtDmxUniverse(universe2, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote)
{
for (size_t i = 0; i < size; ++i)
{
dmx2.write((i + 1), data[i]);
}
dmx2.update(); });
}
// if Artnet packet comes, this function is called to every universe // if Artnet packet comes, this function is called to every universe
artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) {}); // artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) {});
if (!LittleFS.begin(true)) if (!LittleFS.begin(true))
{ {
@ -94,19 +302,37 @@ void setup()
ESP.restart(); }); ESP.restart(); });
server.on("/networks", HTTP_GET, [](AsyncWebServerRequest *request)
{ onGetNetworks(request); });
server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
{ {
if (request->url() == "/config" && request->method() == HTTP_PUT) { if (request->url() == "/config" && request->method() == HTTP_PUT) {
onPutConfig(request, data, len, index, total); onPutConfig(request, data, len, index, total);
Serial.println("restarting ESP...");
ESP.restart(); ESP.restart();
} }); } });
delay(1000); delay(1000);
server.begin(); server.begin();
Serial.println("Server started!"); Serial.println("Server started!");
ledBlink(1);
} }
void loop() void loop()
{ {
artnet.parse(); // check if artnet packet has come and execute callback // check if artnet packet has come and execute callback
artnet.parse();
// Receive Callback/INT currently not implemented
/*if (direction1 == Input) {
artnet.setArtDmxData(dmx1.readAll(), DMXCHANNELS);
artnet.streamArtDmxTo(broadcastIp, universe1);
}
if (direction2 == Input) {
artnet.setArtDmxData(dmx2.readAll(), DMXCHANNELS);
artnet.streamArtDmxTo(broadcastIp, universe2);
}*/
} }

View file

@ -1,6 +1,7 @@
#include "config.h" #include "config.h"
#include <stdexcept> #include <stdexcept>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "WiFi.h"
Preferences config; Preferences config;
@ -161,3 +162,31 @@ void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size
request->send(400, "text/plain", e.what()); request->send(400, "text/plain", e.what());
} }
} }
void onGetNetworks(AsyncWebServerRequest *request)
{
JsonDocument doc;
JsonArray array = doc.to<JsonArray>();
int numberOfNetworks = WiFi.scanComplete();
if (numberOfNetworks == WIFI_SCAN_FAILED)
{
WiFi.scanNetworks(true);
}
else if (numberOfNetworks)
{
for (int i = 0; i < numberOfNetworks; ++i)
{
array.add(WiFi.SSID(i));
}
WiFi.scanDelete();
if (WiFi.scanComplete() == WIFI_SCAN_FAILED)
{
WiFi.scanNetworks(true);
}
}
String jsonString;
serializeJson(doc, jsonString);
request->send(200, "application/json", jsonString);
}

View file

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <ESPAsyncWebServer.h> #include <AsyncWebServer_ESP32_W5500.h>
#include <ESPDMX.h> #include <ESPDMX.h>
#include <Preferences.h> #include <Preferences.h>
@ -35,4 +35,6 @@ void onGetConfig(AsyncWebServerRequest *request);
void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total); void onPutConfig(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);
void onGetNetworks(AsyncWebServerRequest *request);
// #endif // #endif