From 7aab7678e995b2bdb5a51b3afed29c93268a7f7e Mon Sep 17 00:00:00 2001 From: Aled Date: Sat, 27 Feb 2021 09:05:30 +0000 Subject: [PATCH] Usermod for Artemis udp control enables use as a device within the artemisRGB software --- usermods/Artemis_reciever/readme.md | 5 ++ usermods/Artemis_reciever/usermod.cpp | 93 +++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 usermods/Artemis_reciever/readme.md create mode 100644 usermods/Artemis_reciever/usermod.cpp diff --git a/usermods/Artemis_reciever/readme.md b/usermods/Artemis_reciever/readme.md new file mode 100644 index 00000000..11b94908 --- /dev/null +++ b/usermods/Artemis_reciever/readme.md @@ -0,0 +1,5 @@ +Usermod to allow WLED to receive via UDP port from RGB.NET (and therefore add as a device to be controlled within artemis on PC) + +This is only a very simple code to support a single led strip, it does not support the full function of the RGB.NET sketch for esp8266 only what is needed to be used with Artemis. It will show as a ws281x device in artemis when you provide the correct hostname or ip. Artemis queries the number of LEDs via the web interface (/config) but communication to set the LEDs is all done via the UDP interface. + +To install, copy the usermod.cpp file to wled00 folder and recompile \ No newline at end of file diff --git a/usermods/Artemis_reciever/usermod.cpp b/usermods/Artemis_reciever/usermod.cpp new file mode 100644 index 00000000..22736852 --- /dev/null +++ b/usermods/Artemis_reciever/usermod.cpp @@ -0,0 +1,93 @@ +/* + * RGB.NET (artemis) receiver + * + * This works via the UDP, http is not supported apart from reporting LED count + * + * + */ +#include "wled.h" +#include + +WiFiUDP UDP; +const unsigned int RGBNET_localUdpPort = 1872; // local port to listen on +unsigned char RGBNET_packet[770]; +long lastTime = 0; +int delayMs = 10; +bool isRGBNETUDPEnabled; + +void RGBNET_readValues() { + + int RGBNET_packetSize = UDP.parsePacket(); + if (RGBNET_packetSize) { + // receive incoming UDP packets + int sequenceNumber = UDP.read(); + int channel = UDP.read(); + + //channel data is not used we only supports one channel + int len = UDP.read(RGBNET_packet, ledCount*3); + if(len==0){ + return; + } + + for (int i = 0; i < len; i=i+3) { + strip.setPixelColor(i/3, RGBNET_packet[i], RGBNET_packet[i+1], RGBNET_packet[i+2], 0); + } + //strip.show(); + } +} + +//update LED strip +void RGBNET_show() { + strip.show(); + lastTime = millis(); +} + +//This function provides a json with info on the number of LEDs connected +// it is needed by artemis to know how many LEDs to display on the surface +void handleConfig(AsyncWebServerRequest *request) +{ + String config = (String)"{\ + \"channels\": [\ + {\ + \"channel\": 1,\ + \"leds\": " + ledCount + "\ + },\ + {\ + \"channel\": 2,\ + \"leds\": " + "0" + "\ + },\ + {\ + \"channel\": 3,\ + \"leds\": " + "0" + "\ + },\ + {\ + \"channel\": 4,\ + \"leds\": " + "0" + "\ + }\ + ]\ +}"; + request->send(200, "application/json", config); +} + + +void userSetup() +{ + server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request){ + handleConfig(request); + }); +} + +void userConnected() +{ + // new wifi, who dis? + UDP.begin(RGBNET_localUdpPort); + isRGBNETUDPEnabled = true; +} + +void userLoop() +{ + RGBNET_readValues(); + if (millis()-lastTime > delayMs) { + RGBNET_show(); + } +} \ No newline at end of file