Add static IP config, prepare for web config support

simple-crash-test
Cole Deck 10 months ago
parent c6f8fdd9a2
commit 064bfbc346

@ -17,6 +17,7 @@ upload_port = /run/media/amelia/RPI-RP2/
monitor_speed = 115200
board_build.filesystem_size = 1m
board_build.f_cpu = 133000000L
; board_flags = -DWIFICC=CYW43_COUNTRY_USA
lib_deps =
fastled/FastLED@^3.6.0
build_flags = -O3
; board_flags = -DWIFICC=CYW43_COUNTRY_USA
lib_deps =
https://github.com/FastLED/FastLED

@ -0,0 +1,61 @@
#pragma once
// User configurable settings
#define DEBUG
// Amount of color channels per pixel - i.e. RGB = 3, RGBW = 4
#define PIXEL_SIZE 3
// Total LED count
// set to 128*8 for 4 channel, 170*8 for 3 channel
#define MAX_LEDS 170*8
// LED driver chip model - depends on strip
#define LED_TYPE WS2811
// RGB pin ordering - RGB, BGR, GBR, etc
#define RGB_ORDER GBR
// Max number of LED strips connected
// 8 for ARGB Controller PCB
#define LED_STRIPS 8
// Define the data pin connection to each strip
// 0-7 for ARGB Controller PCB
#define STRIP1 0
#define STRIP2 1
#define STRIP3 2
#define STRIP4 3
#define STRIP5 4
#define STRIP6 5
#define STRIP7 6
#define STRIP8 7
// enable pin, if any
// 8 on ARGB controller
#define ENABLEPIN 8
// define how many LEDs / zones are in each strip
#define ENABLE_NTP false
#define ntpserver "pool.ntp.org" // Address of NTP server. Example: pool.ntp.org
// ethernet (w5500) or wifi (pico W cyw43)
#define INT_ETHERNET
//#define INT_WIFI
#define ETH_SPI_SPD 10000000
// Temporary: network and universe settings
// Will be replaced with WebUI + EEPROM config
// to allow for changing settings without recompiling
#define HOSTNAME "Lighting.1"
#define ETH_MODE "staticip" // comment out for DHCP
#define IP_ADDR IPAddress(192,168,50,2)
#define update_path "/update"
#define update_username "admin"
#define update_password "Password@123"
#define START_UNIVERSE 1

@ -20,9 +20,11 @@
*
*/
#include "e131.h"
#include <string.h>
/* E1.17 ACN Packet Identifier */
#ifdef ARDUINO_ARCH_AVR
const PROGMEM byte E131::ACN_ID[12] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 };
@ -199,21 +201,33 @@ int E131::begin() {
int retval = 0;
if (Serial) {
Serial.println("");
Serial.println(F("Requesting Address via DHCP"));
Serial.println("");
if(ETH_MODE == "staticip") {
Serial.println("");
Serial.println("Setting static IP");
Serial.println("");
eth.config(IP_ADDR, INADDR_NONE);
}
else {
Serial.println("");
Serial.println(F("Requesting Address via DHCP"));
Serial.println("");
}
}
SPI.setRX(16);
SPI.setCS(17);
SPI.setSCK(18);
SPI.setTX(19);
//eth.setSPISpeed(30000000);
//lwipPollingPeriod(3);
eth.setSPISpeed(ETH_SPI_SPD);
lwipPollingPeriod(3);
eth.setHostname(HOSTNAME);
if (!eth.begin()) {
Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
return false;
}
while (!eth.connected()) {
Serial.print(".");
delay(500);

@ -24,16 +24,21 @@
#define E131_H_
#include "Arduino.h"
#include "config.h"
/* Network interface detection. WiFi for ESP8266 and Ethernet for AVR */
//# include <WiFi.h>
#ifdef INT_WIFI
#include <WiFi.h>
#endif
//# include <WiFiMulti.h>
//# include <WiFiUdp.h>
# include <W5500lwIP.h>
#ifdef INT_ETHERNET
#include <W5500lwIP.h>
#endif
# include <lwip/ip_addr.h>
# include <lwip/igmp.h>
# define _UDP WiFiUDP
# define INT_ETHERNET
//# define INT_ETHERNET
#define NO_DOUBLE_BUFFER 1

@ -7,47 +7,9 @@
#include <WebServer.h>
#include "e131.h"
#include <FastLED.h>
#include "config.h"
// User configurable
//const char* ssid = "iPhone 14"; // WiFi SSID
//const char* password = "givemewifi"; // WiFi Password
const char* ntpserver = "pool.ntp.org"; // Address of NTP server. Example: pool.ntp.org
const char* HOSTNAME = "lighttest";
const char* update_path = "/firmware";
const char* update_username = "admin";
const char* update_password = "pico-stripper";
//Wiznet5500lwIP eth(1);
//#define DEBUG
// Total LED count
#define MAX_LEDS 150
#define LED_TYPE WS2812B
// Amount of color channels per pixel - i.e. RGB = 3, RGBW = 4
#define PIXEL_SIZE 3
// Number of LED strips connected
#define LED_STRIPS 1
// Define the data pin connection to each strip
// Only uncomment the strips you use
#define STRIP1 0
//#define STRIP2 0
//#define STRIP3 2
//#define STRIP4 3
//#define STRIP5 4
//#define STRIP6 5
//#define STRIP7 6
//#define STRIP8 7
#define RGB_ORDER RGB
// define how many LEDs / zones are in each strip
int strips[LED_STRIPS] = {150};
int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
// Begin code
#ifdef DEBUG
@ -114,53 +76,84 @@ template <class T> T println(T in) {
void write_universe(int universe, uint8_t data[]) {
// universe starts at 0
PRINTFUNC("Universe: ");
PRINTLNFUNC(universe);
//PRINTFUNC("Universe: ");
//PRINTLNFUNC(universe);
int offset = calculate[universe];
PRINTFUNC("Offset: ");
PRINTLNFUNC(offset);
//PRINTFUNC("Offset: ");
//PRINTLNFUNC(offset);
int write_size = universes[universe];
PRINTFUNC("Length: ");
PRINTLNFUNC(write_size);
//PRINTFUNC("Length: ");
//PRINTLNFUNC(write_size);
status = 0;
for (int i = 0; i < write_size; i++) {
int j = i * PIXEL_SIZE + (CHANNEL_START - 1);
if(debug) {
PRINTFUNC(data[j]);
PRINTFUNC(" ");
PRINTFUNC(data[j+1]);
PRINTFUNC(" ");
PRINTFUNC(data[j+2]);
PRINTFUNC(" ");
}
//if(debug) {
// PRINTFUNC(data[j]);
// PRINTFUNC(" ");
// PRINTFUNC(data[j+1]);
// PRINTFUNC(" ");
// PRINTFUNC(data[j+2]);
// PRINTFUNC(" ");
//}
ledstrip[offset + i] = CRGB(data[j], data[j+1], data[j+2]);
//ledstrip[strip].setPixelColor(i + offset, data[j], data[j+1], data[j+2]);
}
status = 1;
//FastLED.show();
PRINTLNFUNC("Done writing.");
//PRINTLNFUNC("Done writing.");
}
const char* PARAM_INPUT_1 = "ipaddr";
const char* PARAM_INPUT_2 = "hostname";
const char* PARAM_INPUT_3 = "universe";
// HTML web page to handle 3 input fields (input1, input2, input3)
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html><head>
<title>ESP Input Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head><body>
All settings below will save to EEPROM flash and won't get overridden by a firmware upgrade.
Settings will take effect after reboot.
<form action="/get">
ipaddr: <input type="text" name="IP Address">
<input type="submit" value="Submit">
</form><br>
<form action="/get">
hostname: <input type="text" name="Hostname">
<input type="submit" value="Submit">
</form><br>
<form action="/get">
universe: <input type="text" name="Start Universe">
<input type="submit" value="Submit">
</form>
</body></html>)rawliteral";
//void notFound(AsyncWebServerRequest *request) {
// request->send(404, "text/plain", "Not found");
//}
void setup() {
pinMode(20, OUTPUT);
digitalWrite(20, LOW); // reset W5500
digitalWrite(20, LOW); // reset W5500 ethernet
delay(1);
digitalWrite(20, HIGH);
SPI.setRX(16);
SPI.setCS(17);
SPI.setSCK(18);
SPI.setTX(19);
pinMode(8, OUTPUT);
digitalWrite(8, LOW); // Enable buffer output!
pinMode(ENABLEPIN, OUTPUT);
digitalWrite(ENABLEPIN, LOW); // Enable buffer output!
//pinMode(0, OUTPUT);
//digitalWrite(0, HIGH);
Serial.begin(115200);
delay(3000);
PRINTLNFUNC("========= PicoLighter v1.0 Initializing =========");
println("========= PicoLighter v1.0 Initializing =========");
if (!e131.begin()) {
PRINTFUNC("Connection failed. Retrying.");
println("Connection failed. Retrying.");
rp2040.reboot();
}
while (ready == 0) {
@ -186,7 +179,7 @@ void setup() {
calculate[currentsize] = offsetcount;
PRINTFUNC(" Universe ");
PRINTFUNC(currentsize + 1);
PRINTFUNC(currentsize + 1 + START_UNIVERSE);
PRINTFUNC(", Light count ");
PRINTFUNC(MAX_PIXELS_PER_UNIVERSE);
PRINTFUNC(", Size ");
@ -198,7 +191,7 @@ void setup() {
universes[currentsize] = tmp;
calculate[currentsize] = offsetcount;
PRINTFUNC(" Universe ");
PRINTFUNC(currentsize + 1);
PRINTFUNC(currentsize + 1 + START_UNIVERSE);
PRINTFUNC(", Light count ");
PRINTFUNC(tmp);
PRINTFUNC(", Size ");
@ -206,7 +199,7 @@ void setup() {
offsetcount += tmp;
currentsize += 1;
}
PRINTLNFUNC("========= PicoLighter v1.0 Initialized =========");
println("========= PicoLighter v1.0 Initialized =========");
initinfo += clientbuffer;
//e131.beginMulticast(ssid, passphrase, UNIVERSE);
ready = 0;
@ -251,42 +244,47 @@ void setup1() {
#endif
// Test all lights
for (int i = 0; i < MAX_LEDS; i++) {
ledstrip[i] = CRGB(50, 50, 50);
ledstrip[i] = CRGB(0, 0, 50);
FastLED.show();
delay(30);
delay(1);
ledstrip[i] = CRGB(0, 0, 0);
}
FastLED.show();
delay(3000);
// WiFi.noLowPowerMode();
//delay(3000);
#ifdef INT_WIFI
WiFi.noLowPowerMode();
#endif
ready = 1;
while (ready == 1) {
delay(100);
}
PRINTLNFUNC("Starting mDNS client.");
// If we get here, then network is good to go
println("Starting mDNS client.");
MDNS.begin(HOSTNAME);
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
httpServer.begin();
MDNS.addService("http", "tcp", 80);
PRINTFUNC("OTA Updates enabled. Open http://");
PRINTFUNC(HOSTNAME);
PRINTFUNC(update_path);
PRINTFUNC(" in your browser and login with username ");
PRINTFUNC(update_username);
PRINTFUNC(" and password ");
PRINTLNFUNC(update_password);
print("OTA Updates enabled. Open http://");
print(HOSTNAME);
print(update_path);
print(" in your browser and login with username ");
print(update_username);
print(" and password ");
println(update_password);
server.begin();
// If we get here, then WiFi is good to go
PRINTFUNC("Starting NTP client.");
NTP.begin(ntpserver);
NTP.waitSet([]() { PRINTFUNC("."); }, 15000);
time_t now = time(nullptr);
PRINTLNFUNC("");
gmtime_r(&now, &timeinfo);
PRINTFUNC("Current time: ");
PRINTFUNC(asctime(&timeinfo));
if(ENABLE_NTP) {
println("Starting NTP client.");
NTP.begin(ntpserver);
NTP.waitSet([]() { print("."); }, 15000);
time_t now = time(nullptr);
println("");
gmtime_r(&now, &timeinfo);
print("Current time: ");
println(asctime(&timeinfo));
}
//rp2040.wdt_begin(8000);
}
@ -295,7 +293,9 @@ void setup1() {
void loop() {
/* Parse a packet and update pixels */
if(e131.parsePacket()) {
write_universe(e131.universe - 1, e131.data);
// Offset by start universe
// as all local functions count from 0
write_universe(e131.universe - START_UNIVERSE, e131.data);
}
else if (blankcount > 1000) {
status = 0;
@ -322,7 +322,7 @@ void loop1() {
//delay(50);
float temp = analogReadTemp();
if (temp > 50.0) {
PRINTLNFUNC("ERROR: Overtemperature triggered!");
println("ERROR: Overtemperature triggered!");
rp2040.reboot();
}
WiFiClient client = server.available();
@ -349,7 +349,7 @@ void loop1() {
//delay(50);
float temp = analogReadTemp(); // read temp in celsius
if (temp > 50.0) {
PRINTLNFUNC("ERROR: Overtemperature triggered!");
println("ERROR: Overtemperature triggered!");
rp2040.reboot();
}
if(clientbuffer != (String) "") {

Loading…
Cancel
Save