mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +00:00
Merge pull request #3 from HendrikRauh/DMX-19
DMX-19 Basic config get endpoint
This commit is contained in:
commit
deb1e591cf
2 changed files with 41 additions and 58 deletions
|
@ -14,4 +14,5 @@ board = lolin_s2_mini
|
|||
framework = arduino
|
||||
lib_deps =
|
||||
hideakitai/ArtNet @ ^0.8.0
|
||||
ESP Async WebServer
|
||||
bblanchon/ArduinoJson @ ^7.2.0
|
||||
ESP Async WebServer
|
||||
|
|
96
src/main.cpp
96
src/main.cpp
|
@ -1,36 +1,40 @@
|
|||
#include <ArtnetWiFi.h>
|
||||
// #include <ArtnetEther.h>
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include "ESPDMX.h"
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <Preferences.h>
|
||||
|
||||
// WiFi stuff
|
||||
const char *ssid = "artnet";
|
||||
const char *pwd = "mbgmbgmbg";
|
||||
const IPAddress ip(192, 168, 1, 201);
|
||||
const IPAddress gateway(192, 168, 1, 1);
|
||||
const IPAddress subnet(255, 255, 255, 0);
|
||||
Preferences config;
|
||||
DMXESPSerial dmx;
|
||||
|
||||
AsyncWebServer server(80);
|
||||
|
||||
// Art-Net stuff
|
||||
ArtnetWiFi artnet;
|
||||
// const String target_ip = "192.168.1.200";
|
||||
uint8_t universe = 1; // 0 - 15
|
||||
const uint16_t size = 512;
|
||||
uint8_t data[size];
|
||||
uint8_t value = 0;
|
||||
|
||||
// DMX stuff
|
||||
DMXESPSerial dmx;
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
// Serial console
|
||||
Serial.begin(9600);
|
||||
|
||||
config.begin("dmx", false);
|
||||
|
||||
uint8_t universe = config.getUChar("universe", 1);
|
||||
|
||||
String ssid = config.getString("ssid", "artnet");
|
||||
String pwd = config.getString("pwd", "mbgmbgmbg");
|
||||
IPAddress defaultIp(192, 168, 1, 201);
|
||||
IPAddress ip = config.getUInt("ip", defaultIp);
|
||||
|
||||
IPAddress cidr = config.getUChar("cidr", 24);
|
||||
|
||||
// TODO: \/ Herleiten \/ @psxde
|
||||
const IPAddress gateway(192, 168, 1, 1);
|
||||
const IPAddress subnet(255, 255, 255, 0);
|
||||
|
||||
// WiFi stuff
|
||||
// WiFi.begin(ssid, pwd);
|
||||
WiFi.softAP(ssid, pwd);
|
||||
|
@ -52,44 +56,15 @@ void setup()
|
|||
// if Artnet packet comes to this universe, this function is called
|
||||
artnet.subscribeArtDmxUniverse(universe, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote)
|
||||
{
|
||||
/*Serial.print("lambda : artnet data from ");
|
||||
Serial.print(remote.ip);
|
||||
Serial.print(":");
|
||||
Serial.print(remote.port);
|
||||
Serial.print(", universe = ");
|
||||
Serial.print(universe);
|
||||
Serial.print(", size = ");
|
||||
Serial.print(size);
|
||||
Serial.print(") :");*/
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
dmx.write((i + 1), data[i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
dmx.write((i + 1), data[i]);
|
||||
// Serial.print(data[i]);
|
||||
// Serial.print(",");
|
||||
}
|
||||
// Serial.println();
|
||||
|
||||
dmx.update(); });
|
||||
dmx.update(); });
|
||||
|
||||
// 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)
|
||||
{
|
||||
/*Serial.print("received ArtNet data from ");
|
||||
Serial.print(remote.ip);
|
||||
Serial.print(":");
|
||||
Serial.print(remote.port);
|
||||
Serial.print(", net = ");
|
||||
Serial.print(metadata.net);
|
||||
Serial.print(", subnet = ");
|
||||
Serial.print(metadata.subnet);
|
||||
Serial.print(", universe = ");
|
||||
Serial.print(metadata.universe);
|
||||
Serial.print(", sequence = ");
|
||||
Serial.print(metadata.sequence);
|
||||
Serial.print(", size = ");
|
||||
Serial.print(size);
|
||||
Serial.println(")");*/ });
|
||||
artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) {});
|
||||
|
||||
if (!SPIFFS.begin(true))
|
||||
{
|
||||
|
@ -99,6 +74,20 @@ void setup()
|
|||
|
||||
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");
|
||||
|
||||
server.on("/config", HTTP_GET, [&, defaultIp, ssid, pwd, universe](AsyncWebServerRequest *request)
|
||||
{
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
doc["ssid"] = ssid;
|
||||
doc["pwd"] = pwd;
|
||||
doc["ip"] = defaultIp;
|
||||
doc["universe"] = universe;
|
||||
|
||||
String jsonString;
|
||||
serializeJson(doc, jsonString);
|
||||
|
||||
request->send(200, "application/json", jsonString); });
|
||||
delay(1000);
|
||||
server.begin();
|
||||
Serial.println("Server started!");
|
||||
}
|
||||
|
@ -106,11 +95,4 @@ void setup()
|
|||
void loop()
|
||||
{
|
||||
artnet.parse(); // check if artnet packet has come and execute callback
|
||||
|
||||
/*value = (millis() / 4) % 256;
|
||||
memset(data, value, size);
|
||||
|
||||
artnet.setArtDmxData(data, size);
|
||||
artnet.streamArtDmxTo(target_ip, universe); // automatically send set data in 40fps
|
||||
// artnet.streamArtDmxTo(target_ip, net, subnet, univ); // or you can set net, subnet, and universe */
|
||||
}
|
Loading…
Add table
Reference in a new issue