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 monitor_speed = 115200
board_build.filesystem_size = 1m board_build.filesystem_size = 1m
board_build.f_cpu = 133000000L board_build.f_cpu = 133000000L
; board_flags = -DWIFICC=CYW43_COUNTRY_USA build_flags = -O3
lib_deps = ; board_flags = -DWIFICC=CYW43_COUNTRY_USA
fastled/FastLED@^3.6.0 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 "e131.h"
#include <string.h> #include <string.h>
/* E1.17 ACN Packet Identifier */ /* E1.17 ACN Packet Identifier */
#ifdef ARDUINO_ARCH_AVR #ifdef ARDUINO_ARCH_AVR
const PROGMEM byte E131::ACN_ID[12] = { 0x41, 0x53, 0x43, 0x2d, 0x45, 0x31, 0x2e, 0x31, 0x37, 0x00, 0x00, 0x00 }; 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; int retval = 0;
if (Serial) { if (Serial) {
Serial.println(""); if(ETH_MODE == "staticip") {
Serial.println(F("Requesting Address via DHCP")); Serial.println("");
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.setRX(16);
SPI.setCS(17); SPI.setCS(17);
SPI.setSCK(18); SPI.setSCK(18);
SPI.setTX(19); SPI.setTX(19);
//eth.setSPISpeed(30000000); eth.setSPISpeed(ETH_SPI_SPD);
//lwipPollingPeriod(3); lwipPollingPeriod(3);
eth.setHostname(HOSTNAME);
if (!eth.begin()) { if (!eth.begin()) {
Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring."); Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
return false; return false;
} }
while (!eth.connected()) { while (!eth.connected()) {
Serial.print("."); Serial.print(".");
delay(500); delay(500);

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

@ -7,47 +7,9 @@
#include <WebServer.h> #include <WebServer.h>
#include "e131.h" #include "e131.h"
#include <FastLED.h> #include <FastLED.h>
#include "config.h"
// User configurable int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
//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};
// Begin code // Begin code
#ifdef DEBUG #ifdef DEBUG
@ -114,53 +76,84 @@ template <class T> T println(T in) {
void write_universe(int universe, uint8_t data[]) { void write_universe(int universe, uint8_t data[]) {
// universe starts at 0 // universe starts at 0
PRINTFUNC("Universe: "); //PRINTFUNC("Universe: ");
PRINTLNFUNC(universe); //PRINTLNFUNC(universe);
int offset = calculate[universe]; int offset = calculate[universe];
PRINTFUNC("Offset: "); //PRINTFUNC("Offset: ");
PRINTLNFUNC(offset); //PRINTLNFUNC(offset);
int write_size = universes[universe]; int write_size = universes[universe];
PRINTFUNC("Length: "); //PRINTFUNC("Length: ");
PRINTLNFUNC(write_size); //PRINTLNFUNC(write_size);
status = 0; status = 0;
for (int i = 0; i < write_size; i++) { for (int i = 0; i < write_size; i++) {
int j = i * PIXEL_SIZE + (CHANNEL_START - 1); int j = i * PIXEL_SIZE + (CHANNEL_START - 1);
if(debug) { //if(debug) {
PRINTFUNC(data[j]); // PRINTFUNC(data[j]);
PRINTFUNC(" "); // PRINTFUNC(" ");
PRINTFUNC(data[j+1]); // PRINTFUNC(data[j+1]);
PRINTFUNC(" "); // PRINTFUNC(" ");
PRINTFUNC(data[j+2]); // PRINTFUNC(data[j+2]);
PRINTFUNC(" "); // PRINTFUNC(" ");
} //}
ledstrip[offset + i] = CRGB(data[j], data[j+1], data[j+2]); 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]); //ledstrip[strip].setPixelColor(i + offset, data[j], data[j+1], data[j+2]);
} }
status = 1; status = 1;
//FastLED.show(); //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() { void setup() {
pinMode(20, OUTPUT); pinMode(20, OUTPUT);
digitalWrite(20, LOW); // reset W5500 digitalWrite(20, LOW); // reset W5500 ethernet
delay(1); delay(1);
digitalWrite(20, HIGH); digitalWrite(20, HIGH);
SPI.setRX(16); SPI.setRX(16);
SPI.setCS(17); SPI.setCS(17);
SPI.setSCK(18); SPI.setSCK(18);
SPI.setTX(19); SPI.setTX(19);
pinMode(8, OUTPUT); pinMode(ENABLEPIN, OUTPUT);
digitalWrite(8, LOW); // Enable buffer output! digitalWrite(ENABLEPIN, LOW); // Enable buffer output!
//pinMode(0, OUTPUT); //pinMode(0, OUTPUT);
//digitalWrite(0, HIGH); //digitalWrite(0, HIGH);
Serial.begin(115200); Serial.begin(115200);
delay(3000); delay(3000);
PRINTLNFUNC("========= PicoLighter v1.0 Initializing ========="); println("========= PicoLighter v1.0 Initializing =========");
if (!e131.begin()) { if (!e131.begin()) {
PRINTFUNC("Connection failed. Retrying."); println("Connection failed. Retrying.");
rp2040.reboot(); rp2040.reboot();
} }
while (ready == 0) { while (ready == 0) {
@ -186,7 +179,7 @@ void setup() {
calculate[currentsize] = offsetcount; calculate[currentsize] = offsetcount;
PRINTFUNC(" Universe "); PRINTFUNC(" Universe ");
PRINTFUNC(currentsize + 1); PRINTFUNC(currentsize + 1 + START_UNIVERSE);
PRINTFUNC(", Light count "); PRINTFUNC(", Light count ");
PRINTFUNC(MAX_PIXELS_PER_UNIVERSE); PRINTFUNC(MAX_PIXELS_PER_UNIVERSE);
PRINTFUNC(", Size "); PRINTFUNC(", Size ");
@ -198,7 +191,7 @@ void setup() {
universes[currentsize] = tmp; universes[currentsize] = tmp;
calculate[currentsize] = offsetcount; calculate[currentsize] = offsetcount;
PRINTFUNC(" Universe "); PRINTFUNC(" Universe ");
PRINTFUNC(currentsize + 1); PRINTFUNC(currentsize + 1 + START_UNIVERSE);
PRINTFUNC(", Light count "); PRINTFUNC(", Light count ");
PRINTFUNC(tmp); PRINTFUNC(tmp);
PRINTFUNC(", Size "); PRINTFUNC(", Size ");
@ -206,7 +199,7 @@ void setup() {
offsetcount += tmp; offsetcount += tmp;
currentsize += 1; currentsize += 1;
} }
PRINTLNFUNC("========= PicoLighter v1.0 Initialized ========="); println("========= PicoLighter v1.0 Initialized =========");
initinfo += clientbuffer; initinfo += clientbuffer;
//e131.beginMulticast(ssid, passphrase, UNIVERSE); //e131.beginMulticast(ssid, passphrase, UNIVERSE);
ready = 0; ready = 0;
@ -251,42 +244,47 @@ void setup1() {
#endif #endif
// Test all lights // Test all lights
for (int i = 0; i < MAX_LEDS; i++) { for (int i = 0; i < MAX_LEDS; i++) {
ledstrip[i] = CRGB(50, 50, 50); ledstrip[i] = CRGB(0, 0, 50);
FastLED.show(); FastLED.show();
delay(30); delay(1);
ledstrip[i] = CRGB(0, 0, 0); ledstrip[i] = CRGB(0, 0, 0);
} }
FastLED.show(); FastLED.show();
delay(3000); //delay(3000);
// WiFi.noLowPowerMode(); #ifdef INT_WIFI
WiFi.noLowPowerMode();
#endif
ready = 1; ready = 1;
while (ready == 1) { while (ready == 1) {
delay(100); delay(100);
} }
PRINTLNFUNC("Starting mDNS client."); // If we get here, then network is good to go
println("Starting mDNS client.");
MDNS.begin(HOSTNAME); MDNS.begin(HOSTNAME);
httpUpdater.setup(&httpServer, update_path, update_username, update_password); httpUpdater.setup(&httpServer, update_path, update_username, update_password);
httpServer.begin(); httpServer.begin();
MDNS.addService("http", "tcp", 80); MDNS.addService("http", "tcp", 80);
PRINTFUNC("OTA Updates enabled. Open http://"); print("OTA Updates enabled. Open http://");
PRINTFUNC(HOSTNAME); print(HOSTNAME);
PRINTFUNC(update_path); print(update_path);
PRINTFUNC(" in your browser and login with username "); print(" in your browser and login with username ");
PRINTFUNC(update_username); print(update_username);
PRINTFUNC(" and password "); print(" and password ");
PRINTLNFUNC(update_password); println(update_password);
server.begin(); server.begin();
// If we get here, then WiFi is good to go
PRINTFUNC("Starting NTP client."); if(ENABLE_NTP) {
NTP.begin(ntpserver); println("Starting NTP client.");
NTP.waitSet([]() { PRINTFUNC("."); }, 15000); NTP.begin(ntpserver);
time_t now = time(nullptr); NTP.waitSet([]() { print("."); }, 15000);
PRINTLNFUNC(""); time_t now = time(nullptr);
gmtime_r(&now, &timeinfo); println("");
PRINTFUNC("Current time: "); gmtime_r(&now, &timeinfo);
PRINTFUNC(asctime(&timeinfo)); print("Current time: ");
println(asctime(&timeinfo));
}
//rp2040.wdt_begin(8000); //rp2040.wdt_begin(8000);
} }
@ -295,7 +293,9 @@ void setup1() {
void loop() { void loop() {
/* Parse a packet and update pixels */ /* Parse a packet and update pixels */
if(e131.parsePacket()) { 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) { else if (blankcount > 1000) {
status = 0; status = 0;
@ -322,7 +322,7 @@ void loop1() {
//delay(50); //delay(50);
float temp = analogReadTemp(); float temp = analogReadTemp();
if (temp > 50.0) { if (temp > 50.0) {
PRINTLNFUNC("ERROR: Overtemperature triggered!"); println("ERROR: Overtemperature triggered!");
rp2040.reboot(); rp2040.reboot();
} }
WiFiClient client = server.available(); WiFiClient client = server.available();
@ -349,7 +349,7 @@ void loop1() {
//delay(50); //delay(50);
float temp = analogReadTemp(); // read temp in celsius float temp = analogReadTemp(); // read temp in celsius
if (temp > 50.0) { if (temp > 50.0) {
PRINTLNFUNC("ERROR: Overtemperature triggered!"); println("ERROR: Overtemperature triggered!");
rp2040.reboot(); rp2040.reboot();
} }
if(clientbuffer != (String) "") { if(clientbuffer != (String) "") {

Loading…
Cancel
Save