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