-
Notifications
You must be signed in to change notification settings - Fork 16
/
ESP8266_ArtNetNode_DMX.ino
160 lines (124 loc) · 4.15 KB
/
ESP8266_ArtNetNode_DMX.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
ESP8266_ArtNetNode_DMX
Copyright (c) 2016, Matthew Tong
https://github.com/mtongnz/ESP8266_ArtNetNode_DMX
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.gnu.org/licenses/
*/
#define FIRMWARE_VERSION "v1.2.0"
// Uncomment the following line to enable serial debug output on Serial0
//#define VERBOSE
// Uncomment the following line to reload the default settings. You need to comment out again to enable saving settings
//#define LOAD_DEFAULTS
// Define the pins for your status leds
#define LED1 12
#define LED2 13
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <FS.h>
#include <espDMX.h>
#include <pgmspace.h>
#include <string.h>
extern "C" {
#include "user_interface.h"
}
// Global variables and all that messy stuff is in this file
#include "globals.h"
/* setup()
* Initializes our EEPROM, serial debug output and dmx output.
* Starts our WiFi, UDP listener and WebServer.
* Send an ArtNet response to alert all devices to our presence.
*/
void setup() {
EEPROM.begin(512);
storeInit();
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
#ifdef VERBOSE
Serial.begin(115200);
Serial.println();
Serial.println("ArtnetDMX");
Serial.print("Firmware Version: ");
Serial.println(FIRMWARE_VERSION);
#endif
#ifdef LOAD_DEFAULTS
#ifdef VERBOSE
Serial.println("Load Default Settings:");
#endif
saveSettings();
startHotSpot();
#else
// If we cant load settings from EEPROM, start the hotspot
if (!loadSettings())
startHotSpot();
#endif
// Start hotspot if we're in standAlone mode otherwise we start the wifi
if (standAlone == 1)
startHotSpot();
else {
startWifi();
// Dont allow hotspot to run after this initial setup - must restart device to start it again
allowHotSpot = 0;
}
// Start WebServer
startWebServer();
// Start listening for UDP packets
eUDP.begin(ARTNET_PORT);
// Send ArtNet Reply
sendArtNetReply();
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
// Start DMX
dmxB.begin(LED2, 75);
#ifndef VERBOSE
dmxA.begin(LED1, 75);
#endif
}
/************************************************************************
The main loop checks WiFi connection. It will continuously try to reconnect if WiFi is dropped.
It then checks for and reads packets from UDP. When a packet is recieved, it is checked to see if it is
valid Art-Net and the artDMXReceived function is called, sending the DMX values to the output.
Then it checks when the last full DMX universe was sent. If it was more than 1 second, we transmit a full
universe.
The last thing we do is handle any web requests.
*************************************************************************/
void loop() {
// Check WiFi conection
if (standAlone != 1 && WiFi.status() != WL_CONNECTED) {
#ifdef VERBOSE
Serial.println("Wifi Connection Lost");
Serial.println("Reconnecting");
#endif
// Connect WiFi
startWifi();
}
// UDP packet
int packetSize = eUDP.parsePacket();
// If any packets are received
if( packetSize ) {
eUDP.read(packetBuffer,ARTNET_BUFFER_MAX);
int opcode = artNetOpCode(packetBuffer);
// If DMX then get data
if ( opcode == ARTNET_ARTDMX ) {
artDMXReceived(packetBuffer);
// If ArtPoll then send reply
} else if ( opcode == ARTNET_ARTPOLL ) {
#ifdef VERBOSE
Serial.println("Artnet Poll Received");
#endif
sendArtNetReply();
}
}
// Handle web requests
webServer.handleClient();
}