Fixed /json with ESP core <2.5.0

This commit is contained in:
cschwinne 2019-03-11 17:57:06 +01:00
parent 898702346e
commit 202eb0d854
4 changed files with 38 additions and 27 deletions

View File

@ -89,7 +89,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1903111 #define VERSION 1903112
char versionString[] = "0.8.4-dev"; char versionString[] = "0.8.4-dev";

View File

@ -153,13 +153,13 @@ void sappends(char stype, char* key, char* val)
} }
} }
//get values for settings form in javascript //get values for settings form in javascript
void getSettingsJS(byte subPage) void getSettingsJS(byte subPage)
{ {
//0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec //0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec
DEBUG_PRINT("settings resp"); DEBUG_PRINT("settings resp");
DEBUG_PRINTLN(subPage); DEBUG_PRINTLN(subPage);
olen = 0; obuf[0] = 0; //clear buffer olen = 0; obuf[0] = 0; //clear buffer
if (subPage <1 || subPage >6) return; if (subPage <1 || subPage >6) return;
@ -324,7 +324,7 @@ void getSettingsJS(byte subPage)
sappend('c',"CF",!useAMPM); sappend('c',"CF",!useAMPM);
sappend('i',"TZ",currentTimezone); sappend('i',"TZ",currentTimezone);
sappend('v',"UO",utcOffsetSecs); sappend('v',"UO",utcOffsetSecs);
sappends('m',"(\"times\")[0]",(char*)getTimeString().c_str()); sappends('m',"(\"times\")[0]",getTimeString());
sappend('i',"OL",overlayCurrent); sappend('i',"OL",overlayCurrent);
sappend('v',"O1",overlayMin); sappend('v',"O1",overlayMin);
sappend('v',"O2",overlayMax); sappend('v',"O2",overlayMax);

View File

@ -73,22 +73,22 @@ void handleNetworkTime()
void sendNTPPacket() void sendNTPPacket()
{ {
WiFi.hostByName(ntpServerName, ntpServerIP); WiFi.hostByName(ntpServerName, ntpServerIP);
DEBUG_PRINTLN("send NTP packet"); DEBUG_PRINTLN("send NTP");
byte pbuf[NTP_PACKET_SIZE];
memset(pbuf, 0, NTP_PACKET_SIZE);
memset(obuf, 0, NTP_PACKET_SIZE); pbuf[0] = 0b11100011; // LI, Version, Mode
pbuf[1] = 0; // Stratum, or type of clock
obuf[0] = 0b11100011; // LI, Version, Mode pbuf[2] = 6; // Polling Interval
obuf[1] = 0; // Stratum, or type of clock pbuf[3] = 0xEC; // Peer Clock Precision
obuf[2] = 6; // Polling Interval
obuf[3] = 0xEC; // Peer Clock Precision
// 8 bytes of zero for Root Delay & Root Dispersion // 8 bytes of zero for Root Delay & Root Dispersion
obuf[12] = 49; pbuf[12] = 49;
obuf[13] = 0x4E; pbuf[13] = 0x4E;
obuf[14] = 49; pbuf[14] = 49;
obuf[15] = 52; pbuf[15] = 52;
ntpUdp.beginPacket(ntpServerIP, 123); //NTP requests are to port 123 ntpUdp.beginPacket(ntpServerIP, 123); //NTP requests are to port 123
ntpUdp.write((byte*)obuf, NTP_PACKET_SIZE); ntpUdp.write(pbuf, NTP_PACKET_SIZE);
ntpUdp.endPacket(); ntpUdp.endPacket();
} }
@ -96,13 +96,13 @@ bool checkNTPResponse()
{ {
int cb = ntpUdp.parsePacket(); int cb = ntpUdp.parsePacket();
if (cb) { if (cb) {
DEBUG_PRINT("packet received, l="); DEBUG_PRINT("NTP recv, l=");
DEBUG_PRINTLN(cb); DEBUG_PRINTLN(cb);
byte pbuf[NTP_PACKET_SIZE];
ntpUdp.read(pbuf, NTP_PACKET_SIZE); // read the packet into the buffer
ntpUdp.read(obuf, NTP_PACKET_SIZE); // read the packet into the buffer unsigned long highWord = word(pbuf[40], pbuf[41]);
unsigned long lowWord = word(pbuf[42], pbuf[43]);
unsigned long highWord = word(obuf[40], obuf[41]);
unsigned long lowWord = word(obuf[42], obuf[43]);
if (highWord == 0 && lowWord == 0) return false; if (highWord == 0 && lowWord == 0) return false;
unsigned long secsSince1900 = highWord << 16 | lowWord; unsigned long secsSince1900 = highWord << 16 | lowWord;
@ -123,14 +123,24 @@ void updateLocalTime()
local = timezones[currentTimezone]->toLocal(tmc); local = timezones[currentTimezone]->toLocal(tmc);
} }
String getTimeString() char* getTimeString()
{ {
updateLocalTime(); updateLocalTime();
String ret = monthStr(month(local)); char out[32];
ret = ret + " "; sprintf(out,"%i-%i-%i, %i:%s%i:%s%i",year(local), month(local), day(local),
(useAMPM)? hour(local)%12:hour(local),
(minute(local)<10)?"0":"",minute(local),
(second(local)<10)?"0":"",second(local));
if (useAMPM)
{
strcat(out,(hour(local) > 11)? " PM":" AM");
}
return out;
/*
String ret = year(local) + "-";
ret = ret + month(local);
ret = ret + "-";
ret = ret + day(local); ret = ret + day(local);
ret = ret + " ";
ret = ret + year(local);
ret = ret + ", "; ret = ret + ", ";
ret += (useAMPM)? hour(local)%12:hour(local); ret += (useAMPM)? hour(local)%12:hour(local);
ret = ret + ":"; ret = ret + ":";
@ -144,6 +154,7 @@ String getTimeString()
ret += (hour(local) > 11)? " PM":" AM"; ret += (hour(local) > 11)? " PM":" AM";
} }
return ret; return ret;
*/
} }
void setCountdown() void setCountdown()

View File

@ -248,8 +248,8 @@ void serveJson(AsyncWebServerRequest* request)
serializeState(state); serializeState(state);
JsonObject& info = doc.createNestedObject("info"); JsonObject& info = doc.createNestedObject("info");
serializeInfo(info); serializeInfo(info);
doc["effects"] = RawJson(JSON_mode_names); doc["effects"] = RawJson(String(JSON_mode_names));
doc["palettes"] = RawJson(JSON_palette_names); doc["palettes"] = RawJson(String(JSON_palette_names));
} }
response->setLength(); response->setLength();