Skip to content

Commit 7aab767

Browse files
committed
Usermod for Artemis udp control
enables use as a device within the artemisRGB software
1 parent 76e269e commit 7aab767

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
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)
2+
3+
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.
4+
5+
To install, copy the usermod.cpp file to wled00 folder and recompile
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* RGB.NET (artemis) receiver
3+
*
4+
* This works via the UDP, http is not supported apart from reporting LED count
5+
*
6+
*
7+
*/
8+
#include "wled.h"
9+
#include <WiFiUdp.h>
10+
11+
WiFiUDP UDP;
12+
const unsigned int RGBNET_localUdpPort = 1872; // local port to listen on
13+
unsigned char RGBNET_packet[770];
14+
long lastTime = 0;
15+
int delayMs = 10;
16+
bool isRGBNETUDPEnabled;
17+
18+
void RGBNET_readValues() {
19+
20+
int RGBNET_packetSize = UDP.parsePacket();
21+
if (RGBNET_packetSize) {
22+
// receive incoming UDP packets
23+
int sequenceNumber = UDP.read();
24+
int channel = UDP.read();
25+
26+
//channel data is not used we only supports one channel
27+
int len = UDP.read(RGBNET_packet, ledCount*3);
28+
if(len==0){
29+
return;
30+
}
31+
32+
for (int i = 0; i < len; i=i+3) {
33+
strip.setPixelColor(i/3, RGBNET_packet[i], RGBNET_packet[i+1], RGBNET_packet[i+2], 0);
34+
}
35+
//strip.show();
36+
}
37+
}
38+
39+
//update LED strip
40+
void RGBNET_show() {
41+
strip.show();
42+
lastTime = millis();
43+
}
44+
45+
//This function provides a json with info on the number of LEDs connected
46+
// it is needed by artemis to know how many LEDs to display on the surface
47+
void handleConfig(AsyncWebServerRequest *request)
48+
{
49+
String config = (String)"{\
50+
\"channels\": [\
51+
{\
52+
\"channel\": 1,\
53+
\"leds\": " + ledCount + "\
54+
},\
55+
{\
56+
\"channel\": 2,\
57+
\"leds\": " + "0" + "\
58+
},\
59+
{\
60+
\"channel\": 3,\
61+
\"leds\": " + "0" + "\
62+
},\
63+
{\
64+
\"channel\": 4,\
65+
\"leds\": " + "0" + "\
66+
}\
67+
]\
68+
}";
69+
request->send(200, "application/json", config);
70+
}
71+
72+
73+
void userSetup()
74+
{
75+
server.on("/config", HTTP_GET, [](AsyncWebServerRequest *request){
76+
handleConfig(request);
77+
});
78+
}
79+
80+
void userConnected()
81+
{
82+
// new wifi, who dis?
83+
UDP.begin(RGBNET_localUdpPort);
84+
isRGBNETUDPEnabled = true;
85+
}
86+
87+
void userLoop()
88+
{
89+
RGBNET_readValues();
90+
if (millis()-lastTime > delayMs) {
91+
RGBNET_show();
92+
}
93+
}

0 commit comments

Comments
 (0)