Skip to content

Commit

Permalink
Many small updates to get both web interface and neopixels running sm…
Browse files Browse the repository at this point in the history
…oothly. Tested on 12, 16 and 24 pixel version and all work fine.
  • Loading branch information
robertoostenveld committed Jan 15, 2017
1 parent 9d8d5d0 commit eb89d85
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 73 deletions.
2 changes: 1 addition & 1 deletion esp8266_artnet_neopixel/README.txt
Expand Up @@ -2,7 +2,7 @@ Updating the firmware on the Wemos D1 mini board using the Arduino IDE requires

The Neopixel and Art-Net settings can be updated on the fly like this

curl -X PUT -d '{"universe":1,"offset":0,"length":24,"leds":4,"white":0,"brightness":100,"hsv":0,"mode":10,"speed":8,"position":1,"reverse":0}' 192.168.1.14/json
curl -X PUT -d '{"universe":1,"offset":0,"pixels":24,"leds":4,"white":0,"brightness":100,"hsv":0,"mode":10,"speed":8,"position":1,"reverse":0}' artnet.local/json

mode 0: individual pixel control
channel 1 = pixel 1 red
Expand Down
5 changes: 3 additions & 2 deletions esp8266_artnet_neopixel/data/index.html
Expand Up @@ -9,8 +9,9 @@
<body>
<a href="/monitor">Monitor</a></br>
<a href="/settings">Change settings</a></br>
<a href="/wifi">Reconfigure WiFi</a></br>
<a href="/reset">Reset to factory defaults</a></br>
<a href="/reconnect">Reconnect WiFi</a></br>
<a href="/reset">Reset hardware</a></br>
<a href="/defaults">Factory defaults</a></br>
<a href="/update">Update firmware</a></br>
</body>
</html>
14 changes: 10 additions & 4 deletions esp8266_artnet_neopixel/data/monitor.html
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
<!--try to load jQuery from google CDN-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!--fall back to a local copy when not connected to internet-->
<script>
window.jQuery || document.write('<script language="javascript" type="text/javascript" src="jquery-3.1.1.min.js"><\/script>');
Expand All @@ -16,11 +16,17 @@

<h1>Monitor</h1>

Firmware version:
<div id="version" name="version">?</div>

Uptime:
<div id="uptime" name"uptime">?</div>

Packets received:
<div id="packets">?</div>
<div id="packets" name="packets">?</div>

Temperature:
<div id="temperature">?</div>
Frames per second:
<div id="fps" name="fps">?</div>

<script language="javascript" type="text/javascript" src="monitor.js"></script>

Expand Down
5 changes: 4 additions & 1 deletion esp8266_artnet_neopixel/data/monitor.js
Expand Up @@ -8,8 +8,11 @@ $.getJSON( "json", function() {
//alert( "success" );
})
.done(function(data) {
console.log(data);
$.each(data, function(key, value) {
document.getElementById(key).innerHTML = value;
elem = document.getElementById(key);
if (elem)
elem.innerHTML = value;
});
//alert( "done" );
})
Expand Down
7 changes: 3 additions & 4 deletions esp8266_artnet_neopixel/data/settings.html
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
<!--try to load jQuery from google CDN-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!--fall back to a local copy when not connected to internet-->
<script>
window.jQuery || document.write('<script language="javascript" type="text/javascript" src="jquery-3.1.1.min.js"><\/script>');
Expand All @@ -16,7 +16,6 @@

<h1>Settings</h1>
<form id="settings-form" method="post" action="json">

<div class="field">
<label for="name">universe:</label>
<input type="text" id="universe" name="universe" value="?" required>
Expand All @@ -28,8 +27,8 @@ <h1>Settings</h1>
</div>

<div class="field">
<label for="name">length:</label>
<input type="text" id="length" name="length" value="?" required>
<label for="name">pixels:</label>
<input type="text" id="pixels" name="pixels" value="?" required>
</div>

<div class="field">
Expand Down
102 changes: 50 additions & 52 deletions esp8266_artnet_neopixel/esp8266_artnet_neopixel.ino
Expand Up @@ -6,12 +6,12 @@
https://github.com/adafruit/Adafruit_NeoPixel
*/

#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <ESP8266WiFi.h> // https://github.com/esp8266/Arduino
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <WiFiClient.h>
#include <ArtnetWifi.h>
#include <ArtnetWifi.h> // https://github.com/rstephan/ArtnetWifi
#include <Adafruit_NeoPixel.h>
#include <FS.h>

Expand All @@ -21,7 +21,8 @@
Config config;
ESP8266WebServer server(80);
const char* host = "ARTNET";
float temperature = 0;
const char* version = __DATE__ " / " __TIME__;
float temperature = 0, fps = 0;

// Neopixel settings
const byte dataPin = D2;
Expand All @@ -45,9 +46,7 @@ void (*mode[]) (uint16_t, uint16_t, uint8_t, uint8_t *) {
};

// keep the timing of the function calls
long tic_loop = 0;
long tic_fps = 0;
long tic_packet = 0;
long tic_loop = 0, tic_fps = 0, tic_packet = 0, tic_web = 0;
long frameCounter = 0;

//this will be called for each UDP packet received
Expand All @@ -57,10 +56,11 @@ void onDmxPacket(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *
Serial.print(packetCounter++);
if ((millis() - tic_fps) > 1000 && frameCounter > 100) {
// don't estimate the FPS too quickly
Serial.print(", FPS = ");
Serial.print(1000 * frameCounter / (millis() - tic_fps));
fps = 1000 * frameCounter / (millis() - tic_fps);
tic_fps = millis();
frameCounter = 0;
Serial.print(", FPS = ");
Serial.print(fps);
}
Serial.println();

Expand All @@ -75,7 +75,7 @@ void onDmxPacket(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t *

void updateNeopixelStrip(void) {
// update the neopixel strip configuration
strip.updateLength(config.length);
strip.updateLength(config.pixels);
strip.setBrightness(config.brightness);
if (config.leds == 3)
strip.updateType(NEO_GRB + NEO_KHZ800);
Expand All @@ -87,51 +87,43 @@ void updateNeopixelStrip(void) {

void setup() {
Serial.begin(115200);
Serial.println("setup");
while (!Serial) {
;
}
Serial.println("setup starting");

global.universe = 0;
global.sequence = 0;
global.length = 512;
global.data = (uint8_t *)malloc(512);

SPIFFS.begin();
loadConfig();

// Serial.print("universe = ");
// Serial.println(config.universe);
// Serial.print("offset = ");
// Serial.println(config.offset);
// Serial.print("length = ");
// Serial.println(config.length);
// Serial.print("leds = ");
// Serial.println(config.leds);
// Serial.print("white = ");
// Serial.println(config.white);
// Serial.print("brightness = ");
// Serial.println(config.brightness);
// Serial.print("hsv = ");
// Serial.println(config.hsv);
// Serial.print("mode = ");
// Serial.println(config.mode);
// Serial.print("reverse = ");
// Serial.println(config.reverse);
// Serial.print("speed = ");
// Serial.println(config.speed);
// Serial.print("position = ");
// Serial.println(config.position);
initialConfig();

strip.begin();
updateNeopixelStrip();
strip.setBrightness(255);
singleYellow();
delay(1000);

SPIFFS.begin();
if (loadConfig()) {
singleYellow();
delay(1000);
}
else {
singleRed();
delay(1000);
}

WiFiManager wifiManager;
// wifiManager.resetSettings();
wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0));
wifiManager.autoConnect(host);
Serial.println("connected");

if (WiFi.status() == WL_CONNECTED)
singleGreen();

// this serves all URIs that can be resolved to a file on the SPIFFS filesystem
server.onNotFound(handleNotFound);

Expand All @@ -143,9 +135,10 @@ void setup() {
handleStaticFile("/index.html");
});

server.on("/wifi", HTTP_GET, []() {
server.on("/reconnect", HTTP_GET, []() {
handleStaticFile("/reload_success.html");
Serial.println("handleWifi");
delay(2000);
Serial.println("handleReconnect");
Serial.flush();
WiFiManager wifiManager;
wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 1, 1), IPAddress(192, 168, 1, 1), IPAddress(255, 255, 255, 0));
Expand All @@ -155,15 +148,12 @@ void setup() {

server.on("/reset", HTTP_GET, []() {
handleStaticFile("/reload_success.html");
delay(2000);
Serial.println("handleReset");
Serial.flush();
WiFiManager wifiManager;
wifiManager.resetSettings();
ESP.restart();
});

server.on("/dir", HTTP_GET, handleDirList);

server.on("/monitor", HTTP_GET, [] {
handleStaticFile("/monitor.html");
});
Expand All @@ -176,16 +166,18 @@ void setup() {
handleStaticFile("/settings.html");
});

server.on("/dir", HTTP_GET, handleDirList);

server.on("/json", HTTP_PUT, handleJSON);

server.on("/json", HTTP_POST, handleJSON);

server.on("/json", HTTP_GET, [] {
StaticJsonBuffer<200> jsonBuffer;
StaticJsonBuffer<300> jsonBuffer;
JsonObject& root = jsonBuffer.createObject();
CONFIG_TO_JSON(universe, "universe");
CONFIG_TO_JSON(offset, "offset");
CONFIG_TO_JSON(length, "length");
CONFIG_TO_JSON(pixels, "pixels");
CONFIG_TO_JSON(leds, "leds");
CONFIG_TO_JSON(white, "white");
CONFIG_TO_JSON(brightness, "brightness");
Expand All @@ -194,8 +186,10 @@ void setup() {
CONFIG_TO_JSON(reverse, "reverse");
CONFIG_TO_JSON(speed, "speed");
CONFIG_TO_JSON(position, "position");
root["packets"] = packetCounter; // this is dynamic
root["temperature"] = temperature; // this is dynamic
root["version"] = version;
root["uptime"] = long(millis() / 1000);
root["packets"] = packetCounter;
root["fps"] = fps;
String str;
root.printTo(str);
server.send(200, "application/json", str);
Expand All @@ -207,33 +201,35 @@ void setup() {

server.on("/update", HTTP_POST, handleUpdate1, handleUpdate2);

// start the web server
server.begin();

// announce the hostname and web server through zeroconf
MDNS.begin(host);
MDNS.addService("http", "tcp", 80);

if (WiFi.status() == WL_CONNECTED)
singleGreen();

artnet.begin();
artnet.setArtDmxCallback(onDmxPacket);

// initialize all timers
tic_loop = millis();
tic_packet = millis();
tic_fps = millis();
tic_web = millis();

Serial.println("setup done");
} // setup

void loop() {
server.handleClient();
artnet.read();

// this section gets executed at a maximum rate of around 10Hz
if ((millis() - tic_loop) > 99)
// this section gets executed at a maximum rate of around 1Hz
if ((millis() - tic_web) > 5000 && (millis() - tic_loop) > 999)
updateNeopixelStrip();

// this section gets executed at a maximum rate of around 100Hz
if ((millis() - tic_loop) > 9) {
if ((millis() - tic_web) > 5000 && (millis() - tic_loop) > 9) {
if (WiFi.status() != WL_CONNECTED) {
// show the WiFi status
singleRed();
Expand All @@ -245,6 +241,8 @@ void loop() {
(*mode[config.mode]) (global.universe, global.length, global.sequence, global.data);
}
}

delay(1);
} // loop


2 changes: 1 addition & 1 deletion esp8266_artnet_neopixel/neopixel_mode.cpp
Expand Up @@ -920,7 +920,7 @@ void singleGreen() {
singleLed(0, 128, 0, 0);
}
void singleBlue() {
singleLed(128, 0, 0, 0);
singleLed(0, 0, 128, 0);
}
void singleYellow() {
singleLed(128, 128, 0, 0);
Expand Down
2 changes: 2 additions & 0 deletions esp8266_artnet_neopixel/neopixel_mode.h
Expand Up @@ -27,6 +27,8 @@ void singleRed();
void singleGreen();
void singleBlue();
void singleYellow();
void singleMagenta();
void singleCyan();
void singleWhite();
void fullBlack();

Expand Down

0 comments on commit eb89d85

Please sign in to comment.