Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit fdfa441

Browse files
committed
Merge branch 'develop'
ESP32 compatible
2 parents 3bfe2aa + 9b75226 commit fdfa441

File tree

10 files changed

+176
-54
lines changed

10 files changed

+176
-54
lines changed

HyperionRGB/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
ConfigStatic.h
1+
ConfigStatic.h
2+
ConfigStatic.h-*

HyperionRGB/EnhancedThread.cpp

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1-
#include "EnhancedThread.h"
2-
3-
void EnhancedThread::run() {
4-
Thread::run();
5-
if (_runOnce)
6-
Thread::enabled = false;
7-
}
8-
9-
void EnhancedThread::runIfNeeded(void) {
10-
if(Thread::shouldRun())
11-
Thread::run();
12-
}
13-
14-
void EnhancedThread::reset(void) {
15-
Thread::enabled = true;
16-
Thread::runned();
17-
}
18-
19-
void EnhancedThread::setRunOnce(bool runOnce) {
20-
_runOnce = runOnce;
21-
}
22-
unsigned long EnhancedThread::getInterval(void) {
23-
return interval;
24-
}
25-
1+
//#include "EnhancedThread.h"
2+
/*
3+
* Put everything into the EnhancedThread.h to make it compatible with the ESP32
4+
* There seems to be a bug in the ArduinoThread lib
5+
*
6+
*/

HyperionRGB/EnhancedThread.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "BaseHeader.h"
55
#include <Thread.h>
66

7-
class EnhancedThread: public Thread {
7+
class EnhancedThread : public Thread {
88
public:
99
void
1010
run(void),
@@ -16,4 +16,27 @@ class EnhancedThread: public Thread {
1616
bool _runOnce;
1717
};
1818

19+
void EnhancedThread::run() {
20+
Thread::run();
21+
if (_runOnce)
22+
Thread::enabled = false;
23+
}
24+
25+
void EnhancedThread::runIfNeeded(void) {
26+
if(Thread::shouldRun())
27+
Thread::run();
28+
}
29+
30+
void EnhancedThread::reset(void) {
31+
Thread::enabled = true;
32+
Thread::runned();
33+
}
34+
35+
void EnhancedThread::setRunOnce(bool runOnce) {
36+
_runOnce = runOnce;
37+
}
38+
unsigned long EnhancedThread::getInterval(void) {
39+
return interval;
40+
}
41+
1942
#endif

HyperionRGB/HyperionRGB.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "WrapperWebconfig.h"
1717

18-
#define LED D0 // LED in NodeMCU at pin GPIO16 (D0).
18+
#define LED LED_BUILTIN // LED in NodeMCU at pin GPIO16 (D0) or LED_BUILTIN @Lolin32.
1919
int ledState = LOW;
2020

2121
LoggerInit loggerInit;

HyperionRGB/WrapperJsonServer.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ WrapperJsonServer::WrapperJsonServer(uint16_t ledCount, uint16_t tcpPort)
77
: _tcpServer(tcpPort) {
88
_ledCount = ledCount;
99
_tcpPort = tcpPort;
10+
_activeLedColor = new byte[3];
1011
}
1112

1213
void WrapperJsonServer::begin(void) {
@@ -48,14 +49,31 @@ void WrapperJsonServer::readData(void) {
4849
String command = root["command"].asString();
4950
if (command.equals("serverinfo")) {
5051
Log.info("serverinfo");
51-
_tcpClient.println("{\"info\":{\"effects\":["
52+
_tcpClient.print("{\"info\":{\"effects\":["
5253
"{\"args\":{\"speed\":1.0},\"name\":\"Hyperion UDP\",\"script\":\"hyperion_udp\"},"
5354
"{\"args\":{\"speed\":2.0},\"name\":\"Rainbow mood\",\"script\":\"rainbow\"},"
5455
"{\"args\":{\"speed\":62.5},\"name\":\"Fire2012\",\"script\":\"fire2012\"}"
5556
"],"
56-
"\"hostname\":\"ESP8266\","
57-
"\"priorities\":[],\"transform\":[{\"blacklevel\":[0.0,0.0,0.0],\"gamma\":[1.0,1.0,1.0],\"id\":\"default\",\"saturationGain\":1.0,\"threshold\":[0.0,0.0,0.0],\"valueGain\":1.0,\"whitelevel\":[1.0,1.0,1.0]}]},"
58-
"\"success\":true}");
57+
"\"activeLedColor\":[{\"RGB Value\":[");
58+
//Dirty hack, workaround for each leds state of newer hyperion versions
59+
/* "activeLedColor" : [
60+
{
61+
"HEX Value" : [ "0xFF0036" ],
62+
"HSL Value" : [ 347, 1.0, 0.50 ],
63+
"RGB Value" : [ 255, 0, 54 ]
64+
}
65+
], */
66+
_tcpClient.print(_activeLedColor[0]);
67+
_tcpClient.print(",");
68+
_tcpClient.print(_activeLedColor[1]);
69+
_tcpClient.print(",");
70+
_tcpClient.print(_activeLedColor[2]);
71+
72+
_tcpClient.print("]}],"
73+
"\"hostname\":\"ESP8266\","
74+
"\"priorities\":[],\"transform\":[{\"blacklevel\":[0.0,0.0,0.0],\"gamma\":[1.0,1.0,1.0],\"id\":\"default\",\"saturationGain\":1.0,\"threshold\":[0.0,0.0,0.0],\"valueGain\":1.0,\"whitelevel\":[1.0,1.0,1.0]}]},"
75+
"\"success\":true}");
76+
_tcpClient.println("");
5977
} else if (command.equals("color")) {
6078
int duration = root["duration"];
6179
ledColorWipe(root["color"][0], root["color"][1], root["color"][2]);
@@ -91,6 +109,9 @@ void WrapperJsonServer::onLedColorWipe(void(* function) (byte, byte, byte)) {
91109
ledColorWipePointer = function;
92110
}
93111
void WrapperJsonServer::ledColorWipe(byte r, byte g, byte b) {
112+
_activeLedColor[0] = r;
113+
_activeLedColor[1] = g;
114+
_activeLedColor[2] = b;
94115
if (ledColorWipePointer) {
95116
ledColorWipePointer(r, g, b);
96117
}
@@ -100,6 +121,9 @@ void WrapperJsonServer::onClearCmd(void(* function) (void)) {
100121
clearCmdPointer = function;
101122
}
102123
void WrapperJsonServer::clearCmd(void) {
124+
_activeLedColor[0] = 0;
125+
_activeLedColor[1] = 0;
126+
_activeLedColor[2] = 0;
103127
if (clearCmdPointer) {
104128
clearCmdPointer();
105129
}

HyperionRGB/WrapperJsonServer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class WrapperJsonServer {
4141

4242
uint16_t _ledCount;
4343
uint16_t _tcpPort;
44+
45+
byte* _activeLedColor;
4446
};
4547

4648
#endif

HyperionRGB/WrapperWebconfig.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
#include "WrapperWebconfig.h"
22

33
void WrapperWebconfig::begin() {
4-
_server.onNotFound([&](){ WrapperWebconfig::handleNotFound(); });
5-
_server.on("/", [&](){ WrapperWebconfig::handleRoot(); });
6-
_server.begin();
4+
_server->onNotFound([&](){ WrapperWebconfig::handleNotFound(); });
5+
_server->on("/", [&](){ WrapperWebconfig::handleRoot(); });
6+
_server->begin();
77
}
88

99
void WrapperWebconfig::handle(void) {
10-
_server.handleClient();
10+
_server->handleClient();
1111
}
1212

1313
void WrapperWebconfig::handleNotFound(void) {
1414
String message = "File Not Found\n\n";
1515
message += "URI: ";
16-
message += _server.uri();
16+
message += _server->uri();
1717
message += "\nMethod: ";
18-
message += (_server.method() == HTTP_GET)?"GET":"POST";
18+
message += (_server->method() == HTTP_GET)?"GET":"POST";
1919
message += "\nArguments: ";
20-
message += _server.args();
20+
message += _server->args();
2121
message += "\n";
22-
for (uint8_t i=0; i<_server.args(); i++){
23-
message += " " + _server.argName(i) + ": " + _server.arg(i) + "\n";
22+
for (uint8_t i=0; i<_server->args(); i++){
23+
message += " " + _server->argName(i) + ": " + _server->arg(i) + "\n";
2424
}
25-
_server.send(404, "text/plain", message);
25+
_server->send(404, "text/plain", message);
2626
}
2727

2828
void WrapperWebconfig::handleRoot(void) {
2929
Log.debug("Webconfig started HEAP=%i", ESP.getFreeHeap());
3030
initHelperVars();
3131
Log.debug("Webconfig initialized HEAP=%i", ESP.getFreeHeap());
32-
if (_server.method() == HTTP_POST) {
32+
if (_server->method() == HTTP_POST) {
3333
Log.debug("POST HEAP=%i", ESP.getFreeHeap());
3434
changeConfig();
3535
}
@@ -38,7 +38,7 @@ void WrapperWebconfig::handleRoot(void) {
3838
Log.debug("Webconfig max HEAP=%i", ESP.getFreeHeap());
3939

4040
//Log.debug("Webconfig cleared HEAP=%i", ESP.getFreeHeap());
41-
_server.send(200, "text/html", message);
41+
_server->send(200, "text/html", message);
4242
Log.debug("Webconfig sent HEAP=%i", ESP.getFreeHeap());
4343
}
4444

@@ -76,9 +76,9 @@ void WrapperWebconfig::changeConfig(void) {
7676
boolean restart = false;
7777
boolean loadStatic = false;
7878

79-
for (uint8_t i=0; i<_server.args(); i++){
80-
String argName = _server.argName(i);
81-
String argValue = _server.arg(i);
79+
for (uint8_t i=0; i<_server->args(); i++){
80+
String argName = _server->argName(i);
81+
String argValue = _server->arg(i);
8282

8383
Log.debug("Config: \"%s\":\"%s\"", argName.c_str(), argValue.c_str());
8484

HyperionRGB/WrapperWebconfig.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
#define WrapperWebconfig_h
33
#include "BaseHeader.h"
44

5-
#include <ESP8266WebServer.h>
5+
#if defined(ESP8266)
6+
#include <ESP8266WebServer.h>
7+
#elif defined(ESP32)
8+
#include <ESP32WebServer.h>
9+
#endif
610
#include <LinkedList.h>
711

812
class SelectEntryBase {
@@ -74,9 +78,13 @@ class WrapperWebconfig {
7478
template<typename T>
7579
T getSelectedEntry(String selectedEntryValue, LinkedList<SelectEntryBase*>* target);
7680

77-
LinkedList<SelectEntryBase*>* _idleModes;;
78-
79-
ESP8266WebServer _server = ESP8266WebServer(80);
81+
LinkedList<SelectEntryBase*>* _idleModes;
82+
83+
#if defined(ESP8266)
84+
ESP8266WebServer* _server = new ESP8266WebServer(80);
85+
#elif defined(ESP32)
86+
ESP32WebServer* _server = new ESP32WebServer(80);
87+
#endif
8088
};
8189

8290
#endif

HyperionRGB/WrapperWiFi.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
#define WrapperWiFi_h
33

44
#include "BaseHeader.h"
5-
#include <ESP8266WiFi.h>
6-
#include <ESP8266mDNS.h>
5+
6+
#if defined(ESP8266)
7+
#include <ESP8266WiFi.h>
8+
#include <ESP8266mDNS.h>
9+
#elif defined(ESP32)
10+
#include <WiFi.h>
11+
#include <ESPmDNS.h>
12+
#endif
713

814
class WrapperWiFi {
915
public:

README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
# ESP8266 Hyperion LED Controller
1+
# Hyperion LED Controller for ESP8266/ESP32
22

3+
<<<<<<< HEAD
34
This code allows you to use a ESP8266 with a fitting led strip as extension for [hyperion](https://github.com/hyperion-project) (ambilight clone).
5+
=======
6+
This code allows you to use a ESP8266/ESP32 with a fitting led strip as extension for [hyperion](https://github.com/hyperion-project) (ambilight clone).
7+
>>>>>>> develop
48
You need to configure hyperion to stream the leds as UDP to the esp.
59

610
German Tutorial:
711
https://forum-raspberrypi.de/forum/thread/25242-tutorial-esp8266-nodemcu-addon-wifi-led-controller-udp/
812

913
Tested with following following libraries (other versions may work):
1014
# IDE
15+
<<<<<<< HEAD
1116
a) Arduino IDE 1.6.12, 1.8.5
1217

1318
# Board Library
@@ -32,6 +37,23 @@ e) Logging https://github.com/SciLor/Arduino-logging-library - install manually:
3237
- You maydefine Wifi configuration but you can also change it from the Webinterface
3338
3. Open the `HyperionRGB.ino` the Arduino IDE
3439
4. Compile and upload to your board
40+
=======
41+
a) Arduino IDE 1.8.5
42+
43+
# Board Library
44+
a) esp8266 2.4.1
45+
46+
b) for esp32 https://github.com/espressif/arduino-esp32
47+
48+
http://arduino.esp8266.com/stable/package_esp8266com_index.json
49+
50+
add to board urls - Version 2.4.0 don't work (bug see https://github.com/esp8266/Arduino/issues/4085)
51+
52+
# Libraries
53+
a) ArduinoThread 2.1.1
54+
55+
b) ArduinoJSON 5.12.0
56+
>>>>>>> develop
3557
3658
# Configuration of Hyperion
3759
You need two running hyperion instances. The first grabs the data on e.g. a rasbperry pi and controls any local attached LED strips. This first instance is configured to forward its data to a second hyperion instance on the same machine. Be sure to only forward the UDP data:
@@ -67,5 +89,60 @@ The second hyperion instance is configured to use UDP as device so that it can t
6789
},
6890
```
6991

92+
<<<<<<< HEAD
93+
=======
94+
d) FastLED 3.1.6
95+
96+
e) Logging https://github.com/SciLor/Arduino-logging-library - install manually: Download zip from github and install via Arduino IDE, Sketch -> Include Library -> Add .ZIP Library
97+
98+
f) ESP32 Webserver https://github.com/nhatuan84/esp32-webserver - install manually (for esp32 only)
99+
100+
# Installation
101+
102+
# Configuration of the board
103+
1. Go to the `HyperionRGB` folder and create a copy of `ConfigStatic.h.example`. Remove the `.example` suffix
104+
2. Configure the `ConfigStatic.h` for your needs:
105+
- Select your LED chip type. All LEDs of the [FastLed](https://github.com/FastLED/FastLED) libraries are supported
106+
- Configure the used LED pins. You can also change the Pin Order. The NodeMCU order doesn't work sometimes to please also try the `RAW_PIN_ORDER``
107+
- Define the number of used LEDs
108+
- Define one of the standard modes which are active when your light is idle. Choose one from: OFF, HYPERION_UDP, STATIC_COLOR, RAINBOW, FIRE2012
109+
- You maydefine Wifi configuration but you can also change it from the Webinterface
110+
3. Open the `HyperionRGB.ino` the Arduino IDE
111+
4. Compile and upload to your board
112+
113+
# Configuration of Hyperion
114+
You need two running hyperion instances. The first grabs the data on e.g. a rasbperry pi and controls any local attached LED strips. This first instance is configured to forward its data to a second hyperion instance on the same machine. Be sure to only forward the UDP data:
115+
116+
```
117+
"forwarder" :
118+
{
119+
"proto" : [ "localhost:19447" ]
120+
},
121+
```
122+
123+
The second hyperion instance is configured to use UDP as device so that it can talk to the ESP directly. This second hyperion instance can run on the same machine as the first instance. Just make sure that you set the UDP ports, hostnames/IPs and LED number accordingly to the values you've configured for the ESP.
124+
125+
```
126+
{
127+
"colorOrder" : "rgb",
128+
"maxpacket" : 1450,
129+
"name" : "AmbiSZ-ESP8266",
130+
"output" : "ESP8266:19446", ///
131+
"protocol" : 0,
132+
"rate" : 250000,
133+
"type" : "udp"
134+
},
135+
136+
137+
"protoServer" :
138+
{
139+
"port" : 19447
140+
},
141+
"jsonServer" :
142+
{
143+
"port" : 19446
144+
},
145+
```
146+
>>>>>>> develop
70147
71148
There's a detailed instruction page for [controlling multiple devices](https://hyperion-project.org/wiki/Controlling-Multiple-Devices).

0 commit comments

Comments
 (0)