Trigger HTTP req feature added
Pre NTP-reimplementation
This commit is contained in:
parent
a321edfebf
commit
369c00bbff
@ -54,6 +54,7 @@ Add one or multiple of the following parameters after the base url to change val
|
||||
"&R=<0-255>" set LED red value (red slider)
|
||||
"&G=<0-255>" set LED green value (green slider)
|
||||
"&B=<0-255>" set LED blue value (blue slider)
|
||||
"&T=<0 or 1 or 2-255>" 0: switch off, on, toggle
|
||||
"&FX=<0-47>" set LED effect (refer to WS2812FX library)
|
||||
"&SX=<0-255>" set LED effect speed (refer to WS2812FX library)
|
||||
"&NR=<0 or 1>" receive notifications on or off
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "htmls01.h"
|
||||
|
||||
//to toggle usb serial debug (un)comment following line
|
||||
//#define DEBUG
|
||||
#define DEBUG
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINT(x) Serial.print (x)
|
||||
@ -123,7 +123,6 @@ uint8_t effectSpeed = 75;
|
||||
boolean udpConnected = false;
|
||||
byte udpIn[LEDCOUNT*4+2];
|
||||
IPAddress ntpIp;
|
||||
IPAddress ntpBackupIp(134,130,5,17);
|
||||
byte ntpBuffer[48];
|
||||
boolean ntpConnected = false;
|
||||
boolean ntpSyncNeeded = true;
|
||||
@ -148,7 +147,6 @@ boolean auxActive, auxActiveBefore;
|
||||
ESP8266WebServer server(80);
|
||||
ESP8266HTTPUpdateServer httpUpdater;
|
||||
WiFiUDP notifierUdp;
|
||||
WiFiUDP ntpUdp;
|
||||
|
||||
WS2812FX strip = WS2812FX(LEDCOUNT, 2, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
@ -223,6 +221,7 @@ void loop() {
|
||||
DEBUG_PRINTLN("---MODULE DEBUG INFO---");
|
||||
DEBUG_PRINT("Runtime: "); DEBUG_PRINTLN(millis());
|
||||
DEBUG_PRINT("Unix time: "); DEBUG_PRINTLN(now());
|
||||
DEBUG_PRINT("Free heap: "); DEBUG_PRINTLN(ESP.getFreeHeap());
|
||||
DEBUG_PRINT("Wifi state: "); DEBUG_PRINTLN(WiFi.status());
|
||||
if (WiFi.status() != lastWifiState)
|
||||
{
|
||||
|
@ -285,9 +285,25 @@ boolean handleSet(String req)
|
||||
}
|
||||
pos = req.indexOf("AX=");
|
||||
if (pos > 0) {
|
||||
auxTime = req.substring(pos + 3).toInt();
|
||||
auxActive = true;
|
||||
if (auxTime == 0) auxActive = false;
|
||||
auxTime = req.substring(pos + 3).toInt();
|
||||
auxActive = true;
|
||||
if (auxTime == 0) auxActive = false;
|
||||
}
|
||||
pos = req.indexOf("T=");
|
||||
if (pos > 0) {
|
||||
switch (req.substring(pos + 2).toInt())
|
||||
{
|
||||
case 0: if (bri != 0){bri_last = bri; bri = 0;} break; //off
|
||||
case 1: bri = bri_last; break; //on
|
||||
default: if (bri == 0) //toggle
|
||||
{
|
||||
bri = bri_last;
|
||||
} else
|
||||
{
|
||||
bri_last = bri;
|
||||
bri = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
XML_response();
|
||||
if (effectUpdated)
|
||||
|
@ -58,14 +58,10 @@ void wledInit()
|
||||
}
|
||||
DEBUG_PRINTLN("mDNS responder started");
|
||||
|
||||
if (udpPort > 0 && udpPort != 123)
|
||||
if (udpPort > 0)
|
||||
{
|
||||
udpConnected = notifierUdp.begin(udpPort);
|
||||
}
|
||||
if (ntpEnabled && !only_ap)
|
||||
{
|
||||
ntpConnected = ntpUdp.begin(123);
|
||||
}
|
||||
|
||||
//SERVER INIT
|
||||
//settings page
|
||||
|
@ -34,7 +34,7 @@ void setLedsStandard()
|
||||
|
||||
void colorUpdated(int callMode)
|
||||
{
|
||||
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (no not.)
|
||||
//call for notifier -> 0: init 1: direct change 2: button 3: notification 4: nightlight 5: other (no not.) 6: fx changed
|
||||
if (col[0] == col_it[0] && col[1] == col_it[1] && col[2] == col_it[2] && bri == bri_it)
|
||||
{
|
||||
if (callMode == 6) notify(6);
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
void handleNetworkTime()
|
||||
{
|
||||
if (ntpEnabled && ntpConnected)
|
||||
if (ntpEnabled && udpConnected)
|
||||
{
|
||||
if (ntpSyncNeeded)
|
||||
{
|
||||
@ -27,11 +27,6 @@ void handleNetworkTime()
|
||||
} else
|
||||
{
|
||||
WiFi.hostByName(ntpServerName, ntpIp);
|
||||
if (ntpIp[0] == 0)
|
||||
{
|
||||
DEBUG_PRINTLN("DNS f!");
|
||||
ntpIp = ntpBackupIp;
|
||||
}
|
||||
sendNTPpacket();
|
||||
ntpPacketSent = true;
|
||||
ntpPacketSentTime = millis();
|
||||
@ -45,8 +40,8 @@ void handleNetworkTime()
|
||||
|
||||
bool getNtpTime()
|
||||
{
|
||||
if (ntpUdp.parsePacket()) {
|
||||
ntpUdp.read(ntpBuffer, 48); // read packet into the buffer
|
||||
if (notifierUdp.parsePacket()) {
|
||||
notifierUdp.read(ntpBuffer, 48); // read packet into the buffer
|
||||
|
||||
#ifdef DEBUG
|
||||
int i= 0;
|
||||
@ -78,8 +73,8 @@ bool getNtpTime()
|
||||
|
||||
void sendNTPpacket()
|
||||
{
|
||||
while (ntpUdp.parsePacket()>0);
|
||||
ntpUdp.flush(); //discard old packets
|
||||
while (notifierUdp.parsePacket()>0);
|
||||
notifierUdp.flush(); //discard old packets
|
||||
DEBUG_PRINTLN("Sending NTP packet");
|
||||
memset(ntpBuffer, 0, 48);
|
||||
ntpBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
@ -90,9 +85,9 @@ void sendNTPpacket()
|
||||
ntpBuffer[13] = 0x4E;
|
||||
ntpBuffer[14] = 49;
|
||||
ntpBuffer[15] = 52;
|
||||
ntpUdp.beginPacket(ntpIp, 123); //NTP requests are to port 123
|
||||
ntpUdp.write(ntpBuffer, 48);
|
||||
ntpUdp.endPacket();
|
||||
notifierUdp.beginPacket(ntpIp, 123); //NTP requests are to port 123
|
||||
notifierUdp.write(ntpBuffer, 48);
|
||||
notifierUdp.endPacket();
|
||||
}
|
||||
|
||||
String getTimeString()
|
||||
|
Loading…
Reference in New Issue
Block a user