Skip to content

Instantly share code, notes, and snippets.

@bobbrez
Last active September 3, 2019 13:09
Show Gist options
  • Save bobbrez/367a1be3619aafc2f15256d4fe463a50 to your computer and use it in GitHub Desktop.
Save bobbrez/367a1be3619aafc2f15256d4fe463a50 to your computer and use it in GitHub Desktop.
ESP32 + ArtNet

Problem

  • The sketch above will respond to ArtNet "find nodes" and display for a short (1-5 minutes) before no longer receiving ArtNet requests. After reaching that state, memory does not seem to increase and Heartbeats are still displayed in the serial console.
  • Using Lightkey I have a simple cycle of colors running at 40hHz.

Software

  • Artnet-test.ino on device
  • Lightkey on separate machine

Hardware

Dependencies

#include <WiFi.h>
#include <WiFiUdp.h>
#include <FastLED.h>
#include <Artnet.h>
#include "common.h"
#define DMX_ID "test-03"
#define DMX_LONGNAME "TEST 03"
#define DMX_SHORTNAME DMX_ID
#define DMX_UNIVERSE 1
#define DMX_ADDRESS 7
#define NUM_LEDS 15
#define LED_PIN 21
#define LED_TYPE WS2812B
const char* ssid = "xxx";
const char* password = "yyy";
Artnet artnet;
CRGB leds[NUM_LEDS];
CRGB currentColor;
unsigned long lastHB = 0;
byte broadcast[] = {255, 255, 255, 255};
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
LEDS.addLeds<LED_TYPE, LED_PIN, GRB>(leds, NUM_LEDS);
artnet.setBroadcast(broadcast);
artnet.setArtDmxCallback(onDmxFrame);
artnet.begin();
}
void loop() {
if(lastHB + 5000 < millis()) {
lastHB = millis();
Serial.println("Heartbeat");
}
artnet.read();
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = currentColor;
}
FastLED.show();
FastLED.delay(10);
}
void onDmxFrame(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data, IPAddress remoteIP) {
Serial.println(universe, DEC);
if (universe != DMX_UNIVERSE) return;
if (length <= DMX_ADDRESS) return;
currentColor = CRGB(data[DMX_ADDRESS - 1], data[DMX_ADDRESS], data[DMX_ADDRESS + 1]);
}
08:57:13.518 -> ....
08:57:14.267 -> Connected to xxx
08:57:14.267 -> IP address: 192.168.0.183
08:57:17.970 -> POLL from 192.168.0.103 broadcast addr: 255.255.255.255
08:57:17.970 -> POLL from 192.168.0.103 broadcast addr: 255.255.255.255
08:57:18.076 -> Heartbeat
08:57:21.732 -> POLL from 192.168.0.103 broadcast addr: 255.255.255.255
08:57:21.877 -> 1
08:57:21.877 -> 1
08:57:21.877 -> 1
08:57:21.910 -> 1
08:57:21.948 -> 1
08:57:21.948 -> 1
08:57:21.983 -> 1
08:57:22.017 -> 1
08:57:22.055 -> 1
08:57:22.088 -> 1
08:57:22.088 -> 1
08:57:22.126 -> 1
08:57:22.160 -> 1
08:57:22.196 -> 1
08:57:22.231 -> 1
08:57:22.231 -> 1
08:57:22.266 -> 1
08:57:22.304 -> 1
08:57:22.339 -> 1
08:57:22.339 -> 1
08:57:22.377 -> 1
08:57:22.414 -> 1
08:57:22.447 -> 1
08:57:22.482 -> 1
08:57:22.519 -> 1
08:57:22.519 -> 1
08:57:22.555 -> 1
08:57:22.661 -> POLL from 192.168.0.103 broadcast addr: 255.255.255.255
08:57:23.094 -> Heartbeat
08:57:23.676 -> 1
08:57:23.710 -> 1
08:57:23.710 -> 1
08:57:23.710 -> 1
08:57:23.746 -> 1
08:57:23.746 -> 1
08:57:23.780 -> 1
08:57:23.816 -> 1
08:57:23.816 -> 1
08:57:23.853 -> 1
08:57:23.891 -> 1
08:57:23.891 -> 1
08:57:23.927 -> 1
08:57:23.964 -> 1
08:57:23.999 -> 1
08:57:23.999 -> 1
08:57:24.032 -> 1
08:57:24.066 -> 1
08:57:24.104 -> 1
08:57:24.104 -> 1
08:57:24.139 -> 1
08:57:24.176 -> 1
08:57:24.210 -> 1
08:57:24.210 -> 1
08:57:24.246 -> 1
08:57:24.279 -> 1
08:57:24.279 -> 1
08:57:24.314 -> 1
08:57:24.349 -> 1
08:57:24.382 -> 1
08:57:24.416 -> 1
08:57:24.454 -> 1
08:57:24.454 -> 1
08:57:24.598 -> 1
08:57:24.598 -> 1
08:57:24.635 -> 1
08:57:24.635 -> 1
08:57:24.635 -> 1
08:57:24.670 -> 1
08:57:24.670 -> 1
08:57:24.670 -> 1
08:57:24.707 -> 1
08:57:24.707 -> 1
08:57:24.744 -> 1
08:57:24.782 -> 1
08:57:24.782 -> 1
08:57:24.818 -> 1
08:57:24.851 -> 1
08:57:24.886 -> 1
08:57:24.924 -> 1
08:57:24.924 -> 1
08:57:24.960 -> 1
08:57:24.998 -> 1
08:57:24.998 -> 1
08:57:25.032 -> 1
08:57:25.066 -> 1
08:57:25.103 -> 1
08:57:25.103 -> 1
08:57:25.141 -> 1
08:57:25.178 -> 1
08:57:25.212 -> 1
08:57:25.246 -> 1
08:57:25.246 -> 1
08:57:25.280 -> 1
08:57:25.318 -> 1
08:57:25.354 -> 1
08:57:25.354 -> 1
08:57:25.390 -> 1
08:57:25.429 -> 1
08:57:25.463 -> 1
08:57:25.463 -> 1
08:57:25.497 -> 1
08:57:25.535 -> 1
08:57:25.570 -> 1
08:57:25.606 -> 1
08:57:25.644 -> 1
08:57:25.644 -> 1
08:57:25.682 -> 1
08:57:25.718 -> 1
08:57:25.718 -> 1
08:57:25.754 -> 1
08:57:25.788 -> 1
08:57:25.826 -> 1
08:57:25.826 -> 1
08:57:25.859 -> 1
08:57:25.895 -> 1
08:57:25.932 -> 1
08:57:25.965 -> 1
08:57:25.965 -> 1
08:57:26.000 -> 1
08:57:26.037 -> 1
08:57:26.070 -> 1
08:57:26.105 -> 1
08:57:26.105 -> 1
08:57:26.217 -> 1
08:57:26.217 -> 1
08:57:26.217 -> 1
08:57:28.082 -> Heartbeat
08:57:33.112 -> Heartbeat
08:57:38.089 -> Heartbeat
08:57:43.102 -> Heartbeat
08:57:48.098 -> Heartbeat
08:57:53.118 -> Heartbeat
08:57:58.113 -> Heartbeat
08:58:03.104 -> Heartbeat
08:58:08.104 -> Heartbeat
08:58:13.132 -> Heartbeat
08:58:18.109 -> Heartbeat
08:58:23.099 -> Heartbeat
08:58:28.127 -> Heartbeat
08:58:33.116 -> Heartbeat
08:58:38.132 -> Heartbeat
08:58:43.120 -> Heartbeat
08:58:48.115 -> Heartbeat
08:58:53.127 -> Heartbeat
08:58:58.144 -> Heartbeat
08:59:03.142 -> Heartbeat
08:59:08.148 -> Heartbeat
08:59:13.126 -> Heartbeat
08:59:18.134 -> Heartbeat
08:59:23.144 -> Heartbeat
08:59:28.155 -> Heartbeat
08:59:33.150 -> Heartbeat
08:59:38.151 -> Heartbeat
08:59:43.145 -> Heartbeat
08:59:48.139 -> Heartbeat
08:59:53.141 -> Heartbeat
08:59:58.132 -> Heartbeat
09:00:03.145 -> Heartbeat
09:00:08.159 -> Heartbeat
09:00:13.145 -> Heartbeat
09:00:18.145 -> Heartbeat
09:00:23.149 -> Heartbeat
09:00:28.166 -> Heartbeat
09:00:33.156 -> Heartbeat
09:00:38.163 -> Heartbeat
09:00:43.159 -> Heartbeat
09:00:48.175 -> Heartbeat
09:00:53.181 -> Heartbeat
09:00:58.156 -> Heartbeat
09:01:03.182 -> Heartbeat
09:01:08.160 -> Heartbeat
09:01:13.184 -> Heartbeat
09:01:18.156 -> Heartbeat
09:01:23.176 -> Heartbeat
09:01:28.192 -> Heartbeat
09:01:33.179 -> Heartbeat
09:01:38.172 -> Heartbeat
09:01:43.173 -> Heartbeat
09:01:48.184 -> Heartbeat
09:01:53.189 -> Heartbeat
09:01:58.167 -> Heartbeat
09:02:03.199 -> Heartbeat
09:02:08.186 -> Heartbeat
09:02:13.205 -> Heartbeat
09:02:18.205 -> Heartbeat
09:02:23.191 -> Heartbeat
09:02:28.196 -> Heartbeat
09:02:33.211 -> Heartbeat
09:02:38.205 -> Heartbeat
09:02:43.201 -> Heartbeat
09:02:48.183 -> Heartbeat
09:02:53.210 -> Heartbeat
09:02:58.186 -> Heartbeat
09:03:03.196 -> Heartbeat
09:03:08.204 -> Heartbeat
09:03:13.213 -> Heartbeat
09:03:18.224 -> Heartbeat
09:03:23.226 -> Heartbeat
09:03:28.213 -> Heartbeat
09:03:33.215 -> Heartbeat
09:03:38.207 -> Heartbeat
09:03:43.223 -> Heartbeat
09:03:48.234 -> Heartbeat
09:03:53.236 -> Heartbeat
09:03:58.229 -> Heartbeat
09:04:03.238 -> Heartbeat
09:04:08.239 -> Heartbeat
09:04:13.226 -> Heartbeat
09:04:18.218 -> Heartbeat
09:04:23.244 -> Heartbeat
09:04:28.222 -> Heartbeat
09:04:33.239 -> Heartbeat
09:04:38.246 -> Heartbeat
09:04:43.227 -> Heartbeat
09:04:48.223 -> Heartbeat
09:04:53.238 -> Heartbeat
09:04:58.240 -> Heartbeat
09:05:03.229 -> Heartbeat
09:05:08.253 -> Heartbeat
09:05:13.236 -> Heartbeat
09:05:18.238 -> Heartbeat
09:05:23.260 -> Heartbeat
09:05:28.237 -> Heartbeat
09:05:33.269 -> Heartbeat
09:05:38.247 -> Heartbeat
09:05:43.265 -> Heartbeat
09:05:48.242 -> Heartbeat
09:05:53.272 -> Heartbeat
09:05:58.271 -> Heartbeat
09:06:03.247 -> Heartbeat
09:06:08.268 -> Heartbeat
09:06:13.256 -> Heartbeat
09:06:18.257 -> Heartbeat
09:06:23.268 -> Heartbeat
09:06:28.268 -> Heartbeat
09:06:33.267 -> Heartbeat
09:06:38.263 -> Heartbeat
09:06:43.292 -> Heartbeat
09:06:48.266 -> Heartbeat
09:06:53.283 -> Heartbeat
09:06:58.290 -> Heartbeat
09:07:03.296 -> Heartbeat
09:07:08.293 -> Heartbeat
09:07:13.282 -> Heartbeat
09:07:18.266 -> Heartbeat
09:07:23.280 -> Heartbeat
09:07:28.275 -> Heartbeat
09:07:33.298 -> Heartbeat
09:07:38.279 -> Heartbeat
09:07:43.299 -> Heartbeat
09:07:48.290 -> Heartbeat
09:07:53.288 -> Heartbeat
09:07:58.301 -> Heartbeat
09:08:03.284 -> Heartbeat
09:08:08.291 -> Heartbeat
09:08:13.308 -> Heartbeat
09:08:18.306 -> Heartbeat
09:08:23.296 -> Heartbeat
09:08:28.304 -> Heartbeat
09:08:33.306 -> Heartbeat
09:08:38.308 -> Heartbeat
09:08:43.301 -> Heartbeat
09:08:48.315 -> Heartbeat
09:08:53.313 -> Heartbeat
09:08:58.311 -> Heartbeat
09:09:03.324 -> Heartbeat
09:09:08.307 -> Heartbeat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment