mirror of
https://github.com/bcomsugi/VSS_Rally_V3.git
synced 2026-01-09 18:02:38 +07:00
add Set Time Page
This commit is contained in:
parent
05c8b38e21
commit
702223dc58
@ -69,15 +69,15 @@ const char HTML_CONSTROW[] PROGMEM = R"rawliteral(
|
||||
<div class="col-1 "><label for="%dist%" class="col-form-label fs-4 ms-1 trip">%A%></label></div>
|
||||
<div class="col-2">
|
||||
<input type="number" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="%dist%" name="%dist%" class="form-control dist" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
id="%dist%" name="%dist%" class="form-control dist" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)" value="%distval%"></div>
|
||||
<div class="col-2 ">
|
||||
<input type="number" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="%speed%" name="%speed%" class="form-control speed" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
<input type="number" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="%speed%" name="%speed%" class="form-control speed" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)" value="%speedval%"></div>
|
||||
<div class="col-2">
|
||||
<input type="number" maxlength="5" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="%time%" name="%time%" class="form-control time" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
id="%time%" name="%time%" class="form-control time" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)" value="%timeval%"></div>
|
||||
<div class="col-2">
|
||||
<input type="time" id="%stime%" name="%stime%" class="form-control stime" onchange="chback(this)"></div>
|
||||
<input type="time" id="%stime%" name="%stime%" class="form-control stime" onchange="chback(this)" value="%stimeval%"></div>
|
||||
<div class="col-2">
|
||||
<button class="btn btn-primary fw-bold" id="myBtn" onclick="setConstanta(this)">SET %A%</button></div>
|
||||
</div>
|
||||
@ -125,7 +125,7 @@ const char HTML_CONSTEND[] PROGMEM = R"rawliteral(
|
||||
|
||||
// console.log(String.fromCharCode(i));
|
||||
// data = '{"req":"'+String.fromCharCode(i)+'"}'
|
||||
xhr.send(data);
|
||||
// xhr.send(data);
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
64
data/settime.html
Normal file
64
data/settime.html
Normal file
@ -0,0 +1,64 @@
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1 Set Main Time</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- Bootstrap CSS -->
|
||||
<!--
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
-->
|
||||
<link href="bootstrap.css" rel="stylesheet">
|
||||
<script type = "text/javascript">
|
||||
const ws = new WebSocket("ws://%serveripaddress%/wssettime");
|
||||
ws.onopen = function() {console.log("WebSocket Connected");};
|
||||
ws.onclose = function() {alert("WS Connection Closed");};
|
||||
ws.onmessage = function(event) {
|
||||
console.log(event.data);
|
||||
var data = JSON.parse(event.data);
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
document.getElementById("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("speed").innerHTML = data.curTripSpeed;
|
||||
document.getElementById("ntptime").innerHTML = data.NTPTime;
|
||||
// document.getElementById("calman").innerHTML = data.calman;
|
||||
// document.getElementById("calkm").innerHTML = data.calkm;
|
||||
// document.getElementById("calmeter").innerHTML = data.calmeter;
|
||||
// document.getElementById("calval").innerHTML = data.calval;
|
||||
};
|
||||
</script>
|
||||
</head><body>
|
||||
<!--
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
|
||||
-->
|
||||
<script src="bootstrap.bundle.min.js"></script>
|
||||
<div class=" bg-secondary text-white">
|
||||
<div class="row">
|
||||
<div class="col-2 mt-1"><h2><span id="counter">12345</span></h2></div>
|
||||
<div class="col-3 mt-1"><h2>TRACK <span id="currenttrack">A</span></h2></div>
|
||||
<div class="col mt-1"><h2 class="text-center">Time: <span id="currenttime">00:00:00</span></h2></div>
|
||||
<div class="col-3 mt-1 text-end"><h2><span id="speed">123.4</span>Km/h</h2></div>
|
||||
<hr>
|
||||
</div>
|
||||
<!--//Calibration Menu-->
|
||||
<div class="row">
|
||||
<div class="col text-end"><h3>Set Time (NTP Time:<span id="ntptime">9</span>)-></h3></div>
|
||||
<div class="col text-start"><h3>
|
||||
<input type="time" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="settime" name="settime" size="4">
|
||||
<button class="btn btn-primary mb-2 fw-bold" onclick="setTime(0)">SET Time</button>
|
||||
<button class="btn btn-primary mb-2 fw-bold" onclick="setTime(1)">Use NTP</button>
|
||||
</h3></div>
|
||||
</div>
|
||||
<button ondblclick="location.href='/menu';" class="btn btn-primary fw-bold btn-sm mt-2 mb-2 ms-3">Back to Menu</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function setTime(e){
|
||||
let setTime;
|
||||
if (e) setTime = "NTP";
|
||||
else setTime = document.getElementById("settime").value;
|
||||
var full_data='{"setTime":"'+setTime+'"}';
|
||||
console.log(full_data);
|
||||
ws.send(full_data);
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
@ -70,15 +70,15 @@ const char HTML_CONSTROW[] PROGMEM = R"rawliteral(
|
||||
<div class="col-1 "><label for="%dist%" class="col-form-label fs-4 ms-1 trip">%A%></label></div>
|
||||
<div class="col-2">
|
||||
<input type="number" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="%dist%" name="%dist%" class="form-control dist" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
id="%dist%" name="%dist%" class="form-control dist" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)" value="%distval%"></div>
|
||||
<div class="col-2 ">
|
||||
<input type="number" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="%speed%" name="%speed%" class="form-control speed" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
<input type="number" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="%speed%" name="%speed%" class="form-control speed" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)" value="%speedval%"></div>
|
||||
<div class="col-2">
|
||||
<input type="number" maxlength="5" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="%time%" name="%time%" class="form-control time" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
id="%time%" name="%time%" class="form-control time" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)" value="%timeval%"></div>
|
||||
<div class="col-2">
|
||||
<input type="time" id="%stime%" name="%stime%" class="form-control stime" onchange="chback(this)"></div>
|
||||
<input type="time" id="%stime%" name="%stime%" class="form-control stime" onchange="chback(this)" value="%stimeval%"></div>
|
||||
<div class="col-2">
|
||||
<button class="btn btn-primary fw-bold" id="myBtn" onclick="setConstanta(this)">SET %A%</button></div>
|
||||
</div>
|
||||
@ -126,7 +126,7 @@ const char HTML_CONSTEND[] PROGMEM = R"rawliteral(
|
||||
|
||||
// console.log(String.fromCharCode(i));
|
||||
// data = '{"req":"'+String.fromCharCode(i)+'"}'
|
||||
xhr.send(data);
|
||||
// xhr.send(data);
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
70
src/index.h
70
src/index.h
@ -429,4 +429,74 @@ const char HTML_CALIBRATION[] PROGMEM = R"rawliteral(
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
)rawliteral";
|
||||
|
||||
|
||||
|
||||
|
||||
const char HTML_SETTIME[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1 Set Main Time</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<!-- Bootstrap CSS -->
|
||||
<!--
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
-->
|
||||
<link href="bootstrap.css" rel="stylesheet">
|
||||
<script type = "text/javascript">
|
||||
const ws = new WebSocket("ws://%serveripaddress%/wssettime");
|
||||
ws.onopen = function() {console.log("WebSocket Connected");};
|
||||
ws.onclose = function() {alert("WS Connection Closed");};
|
||||
ws.onmessage = function(event) {
|
||||
console.log(event.data);
|
||||
var data = JSON.parse(event.data);
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
document.getElementById("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("speed").innerHTML = data.curTripSpeed;
|
||||
document.getElementById("ntptime").innerHTML = data.NTPTime;
|
||||
// document.getElementById("calman").innerHTML = data.calman;
|
||||
// document.getElementById("calkm").innerHTML = data.calkm;
|
||||
// document.getElementById("calmeter").innerHTML = data.calmeter;
|
||||
// document.getElementById("calval").innerHTML = data.calval;
|
||||
};
|
||||
</script>
|
||||
</head><body>
|
||||
<!--
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
|
||||
-->
|
||||
<script src="bootstrap.bundle.min.js"></script>
|
||||
<div class=" bg-secondary text-white">
|
||||
<div class="row">
|
||||
<div class="col-2 mt-1"><h2><span id="counter">12345</span></h2></div>
|
||||
<div class="col-3 mt-1"><h2>TRACK <span id="currenttrack">A</span></h2></div>
|
||||
<div class="col mt-1"><h2 class="text-center">Time: <span id="currenttime">00:00:00</span></h2></div>
|
||||
<div class="col-3 mt-1 text-end"><h2><span id="speed">123.4</span>Km/h</h2></div>
|
||||
<hr>
|
||||
</div>
|
||||
<!--//Calibration Menu-->
|
||||
<div class="row">
|
||||
<div class="col text-end"><h3>Set Time (NTP Time:<span id="ntptime">9</span>)-></h3></div>
|
||||
<div class="col text-start"><h3>
|
||||
<input type="time" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="settime" name="settime" size="4">
|
||||
<button class="btn btn-primary mb-2 fw-bold" onclick="setTime(0)">SET Time</button>
|
||||
<button class="btn btn-primary mb-2 fw-bold" onclick="setTime(1)">Use NTP</button>
|
||||
</h3></div>
|
||||
</div>
|
||||
<button ondblclick="location.href='/menu';" class="btn btn-primary fw-bold btn-sm mt-2 mb-2 ms-3">Back to Menu</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function setTime(e){
|
||||
let setTime;
|
||||
if (e) setTime = "NTP";
|
||||
else setTime = document.getElementById("settime").value;
|
||||
var full_data='{"setTime":"'+setTime+'"}';
|
||||
console.log(full_data);
|
||||
ws.send(full_data);
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
)rawliteral";
|
||||
602
src/main.cpp
602
src/main.cpp
@ -35,6 +35,7 @@
|
||||
AsyncWebServer server(80);
|
||||
AsyncWebSocket ws("/ws");
|
||||
AsyncWebSocket wscal("/wscal");
|
||||
AsyncWebSocket wssettime("/wssettime");
|
||||
//WiFiManager wifiManager;
|
||||
|
||||
// REPLACE WITH YOUR NETWORK CREDENTIALS
|
||||
@ -63,10 +64,12 @@ const int daylightOffset_sec = 0;
|
||||
uint8_t STATE, dircount1, dircount2; //The current state machine state
|
||||
|
||||
//volatile DynamicJsonDocument getRally(200);
|
||||
String getRallyJson="{\"counter\":0}";
|
||||
String getCalibJson="{\"counter\":0}";
|
||||
String strRallyJson="{\"counter\":0}";
|
||||
String strCalibJson="{\"counter\":0}";
|
||||
String strSetTimeJson="{\"counter\":0}";
|
||||
int globalClientRally=0;
|
||||
int globalClientCalib=0;
|
||||
int globalClientSetTime=0;
|
||||
|
||||
#define REQUESTCOUNT 3
|
||||
AsyncWebServerRequest *gRequest[REQUESTCOUNT];
|
||||
@ -74,7 +77,7 @@ JsonVariant gJson[REQUESTCOUNT];
|
||||
uint8_t gReqCount=0;
|
||||
bool gGotRequest[REQUESTCOUNT];
|
||||
boolean grequestIsFull=false;
|
||||
|
||||
boolean semaphoreS = true;
|
||||
|
||||
|
||||
AsyncWebServerRequest *gRequestConstHTML[REQUESTCOUNT];
|
||||
@ -174,7 +177,7 @@ unsigned int recv_size = 0;
|
||||
unsigned long prevsettime, intervalsettime = 250;
|
||||
unsigned long prevtempint, tempinterval=60000;
|
||||
unsigned long prevtemprally, tempintervalrally=333;
|
||||
unsigned long prevCalculatingRallyMillis, calculatingRallyMillis=333;
|
||||
unsigned long prevCalculatingRallyMillis, calculatingRallyMillis=1000;
|
||||
unsigned long prevcalibrationtime, calibrationtimeinterval = 200;
|
||||
unsigned long updatecounttime=0;
|
||||
float temperature;
|
||||
@ -192,7 +195,8 @@ byte y;
|
||||
unsigned long startmillis, startVSSCount;
|
||||
unsigned long startsavemillis;
|
||||
unsigned long broadcastwebsocket;
|
||||
unsigned long broadcastwebsocketcalib;
|
||||
unsigned long timerWebsocketCalibration;
|
||||
unsigned long timerWebsocketSetTime;
|
||||
volatile unsigned long howLongInMillis;
|
||||
|
||||
//#include <Button.h> //https://github.com/JChristensen/Button //from <Button.h> change to <JC_Button.h>
|
||||
@ -400,7 +404,7 @@ String processor(const String& var){
|
||||
// }
|
||||
return String();
|
||||
}
|
||||
String procConst(const String& var){
|
||||
String processorConstant(const String& var){
|
||||
Serial.print("proConst->");
|
||||
Serial.print(var);
|
||||
return String();
|
||||
@ -678,7 +682,7 @@ String getsTime(uint8_t getsTimecurtrip){
|
||||
char sTime[6];
|
||||
// if (sTimeHour<10){
|
||||
sprintf(sTime, "%02d:%02d", sTimeHour, sTimeMin);
|
||||
Serial.print(getsTimecurtrip);Serial.print("getsTime:");Serial.print(sTimeHour);Serial.print(":");Serial.print(sTimeMin);Serial.print(";");Serial.println(sTime);
|
||||
// Serial.print(getsTimecurtrip);Serial.print("getsTime:");Serial.print(sTimeHour);Serial.print(":");Serial.print(sTimeMin);Serial.print(";");Serial.println(sTime);
|
||||
// }
|
||||
return sTime;
|
||||
}
|
||||
@ -690,7 +694,7 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
|
||||
Serial.println("Websocket client connection received");
|
||||
Serial.print("Rally Client=");Serial.println(globalClientRally);
|
||||
Serial.print("IPAdd client:"); Serial.println(client->remoteIP());
|
||||
client->text(getRallyJson);
|
||||
client->text(strRallyJson);
|
||||
} else if(type == WS_EVT_DISCONNECT){
|
||||
globalClientRally--;
|
||||
Serial.println("Client disconnected");
|
||||
@ -808,13 +812,13 @@ void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventT
|
||||
}
|
||||
}
|
||||
|
||||
void onWsEvent2(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
void onWsEventCalibration(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
if(type == WS_EVT_CONNECT){
|
||||
globalClientCalib++;
|
||||
Serial.println("wscal Websocket client connection received");
|
||||
Serial.print("Calib Client=");Serial.println(globalClientCalib);
|
||||
Serial.print("IPAdd client:"); Serial.println(client->remoteIP());
|
||||
client->text(getCalibJson);
|
||||
client->text(strCalibJson);
|
||||
} else if(type == WS_EVT_DISCONNECT){
|
||||
globalClientCalib--;
|
||||
Serial.println("wscal Client disconnected");
|
||||
@ -878,6 +882,72 @@ void onWsEvent2(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEvent
|
||||
}
|
||||
}
|
||||
|
||||
void onWsEventSetTime(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
if(type == WS_EVT_CONNECT){
|
||||
globalClientSetTime++;
|
||||
Serial.println("wssettime Websocket client connection received");
|
||||
Serial.print("SetTime Client=");Serial.println(globalClientSetTime);
|
||||
Serial.print("IPAdd client:");Serial.println(client->remoteIP());
|
||||
client->text(strSetTimeJson);
|
||||
} else if(type == WS_EVT_DISCONNECT){
|
||||
globalClientSetTime--;
|
||||
Serial.println("wssettime Client disconnected");
|
||||
Serial.print("SetTime Client=");Serial.println(globalClientSetTime);
|
||||
Serial.print("IPAdd client:"); Serial.println(client->remoteIP());
|
||||
} else if(type == WS_EVT_DATA){
|
||||
Serial.print("wssettime IPAdd client:"); Serial.println(client->remoteIP());
|
||||
Serial.printf("[%u] get Text: %s\n", len, data);
|
||||
String message = String((char*)( data));
|
||||
Serial.println(message);
|
||||
|
||||
DynamicJsonDocument doc(32);
|
||||
// Deserialize the data
|
||||
DeserializationError error = deserializeJson(doc, message);
|
||||
// parse the parameters we expect to receive (TO-DO: error handling)
|
||||
// test if parsing succeeds
|
||||
if (error){
|
||||
Serial.print("wssettime deserialiseJson() failed: ");
|
||||
Serial.println(error.c_str());
|
||||
client->text(error.c_str());
|
||||
return;
|
||||
}
|
||||
// String setTime=doc["setTime"];
|
||||
const char* setTime = doc["setTime"].as<const char*>();
|
||||
Serial.print("setTime=");Serial.println(setTime);
|
||||
struct ts mts;
|
||||
struct tm mtm;
|
||||
if (setTime!=NULL){
|
||||
if (isShortTime(setTime)){
|
||||
String x = getSplitValue(setTime, ':', 0);
|
||||
uint8_t xHourVal=(uint8_t)(x.toInt());
|
||||
String y = getSplitValue(setTime, ':', 1);
|
||||
int yMinVal=(uint8_t)(y.toInt());
|
||||
Serial.print("x=");Serial.println(xHourVal);
|
||||
Serial.print("y=");Serial.println(yMinVal);
|
||||
DS3231_get(&mts);
|
||||
mts.sec=0;
|
||||
mts.min=yMinVal;
|
||||
mts.hour=xHourVal;
|
||||
DS3231_set(mts);
|
||||
Serial.println("Manual Time Saved");
|
||||
// } else if(setTime=="NTP") { //save NTP Time to DS3231
|
||||
} else if(strcmp(setTime, "NTP") == 0) { //save NTP Time to DS3231
|
||||
if(!getLocalTime(&mtm)){
|
||||
Serial.println("Failed to obtain NTP time");
|
||||
// return;
|
||||
}
|
||||
mts.hour = mtm.tm_hour;
|
||||
mts.min = mtm.tm_min;
|
||||
mts.sec = mtm.tm_sec;
|
||||
mts.mday = mtm.tm_mday;
|
||||
mts.mon = mtm.tm_mon;
|
||||
mts.year = mtm.tm_year;
|
||||
DS3231_set(mts);
|
||||
Serial.println("NTP Saved");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
// Serial.println("Entered config mode");
|
||||
// Serial.println(WiFi.softAPIP());
|
||||
@ -1225,6 +1295,41 @@ String runningtimeforESP32(byte x1,byte y1)
|
||||
// Serial.print("runningtimeforesp:");Serial.println(runningTIME);
|
||||
return runningTIME;
|
||||
}
|
||||
|
||||
String runningtimeforESP32(struct tm *mt)
|
||||
{
|
||||
String runningTIME;
|
||||
// lcd.setCursor(x1,y1); //Go to second line of the LCD Screen
|
||||
if(mt->tm_hour<10)
|
||||
{
|
||||
// lcd.print("0");
|
||||
runningTIME="0";
|
||||
}
|
||||
// lcd.print(t.hour);
|
||||
// lcd.print(":");
|
||||
runningTIME+=mt->tm_hour;
|
||||
runningTIME+=":";
|
||||
if(mt->tm_min<10)
|
||||
{
|
||||
// lcd.print("0");
|
||||
runningTIME+="0";
|
||||
}
|
||||
// lcd.print(t.min);
|
||||
// lcd.print(":");
|
||||
runningTIME+=mt->tm_min;
|
||||
runningTIME+=":";
|
||||
if(mt->tm_sec<10)
|
||||
{
|
||||
// lcd.print("0");
|
||||
runningTIME+="0";
|
||||
}
|
||||
// lcd.print(t.sec);
|
||||
runningTIME+=mt->tm_sec;
|
||||
// Serial.print("t.hour:");Serial.println(t.hour);
|
||||
// Serial.print("runningtimeforesp:");Serial.println(runningTIME);
|
||||
return runningTIME;
|
||||
}
|
||||
|
||||
String runningtimeforESP32test1(byte x1,byte y1)
|
||||
{
|
||||
// String runningTIME;
|
||||
@ -1481,7 +1586,7 @@ void redrawcalibrationMenu()
|
||||
void redrawcalibrationMenuForESP32()
|
||||
{
|
||||
DynamicJsonDocument getCalib(512);
|
||||
deserializeJson(getCalib, getCalibJson);
|
||||
deserializeJson(getCalib, strCalibJson);
|
||||
float distance;
|
||||
Calibrationcount = Calibrationcount + (VSSCount-Calibrationtime);
|
||||
distance = (float)Calibrationcount/((float)Calibration);
|
||||
@ -1510,10 +1615,34 @@ void redrawcalibrationMenuForESP32()
|
||||
getCalib["calmeter"]=String(float(Calibration)/1000,3);
|
||||
getCalib["calval"]= Calibration;
|
||||
|
||||
getCalibJson = "";
|
||||
serializeJson(getCalib, getCalibJson);
|
||||
strCalibJson = "";
|
||||
serializeJson(getCalib, strCalibJson);
|
||||
}
|
||||
|
||||
void fillSetTimeJsonForESP32()
|
||||
{
|
||||
DynamicJsonDocument docSetTime(512);
|
||||
deserializeJson(docSetTime, strSetTimeJson);
|
||||
|
||||
docSetTime["counter"]=VSSCount; /////
|
||||
docSetTime["curTrip"]=String(Trip[curTrip].sub); /////
|
||||
docSetTime["curTripSpeed"]=String(Trip[curTrip].speed); /////
|
||||
DS3231_get(&t);
|
||||
struct tm NTPTimeInfo;
|
||||
if(!getLocalTime(&NTPTimeInfo)){
|
||||
Serial.println("Failed to obtain NTP time");
|
||||
// return;
|
||||
}
|
||||
gcurTime = runningtimeforESP32(6,0);
|
||||
String NTPTime;
|
||||
NTPTime = runningtimeforESP32(&NTPTimeInfo);
|
||||
docSetTime["curTime"]=gcurTime;
|
||||
|
||||
docSetTime["NTPTime"]=NTPTime;
|
||||
|
||||
strSetTimeJson = "";
|
||||
serializeJson(docSetTime, strSetTimeJson);
|
||||
}
|
||||
|
||||
// // char digitClock(int v){
|
||||
// // if (v < 10)
|
||||
@ -1754,7 +1883,7 @@ void redrawrallyMenu()
|
||||
void calculationRally_BACKUP() //calculation only ESP32
|
||||
{
|
||||
DynamicJsonDocument getRally(1024);
|
||||
deserializeJson(getRally, getRallyJson);
|
||||
deserializeJson(getRally, strRallyJson);
|
||||
DS3231_get(&t); //Get time
|
||||
// Serial.println("startCRal");
|
||||
updateCount();
|
||||
@ -1936,8 +2065,8 @@ void calculationRally_BACKUP() //calculation only ESP32
|
||||
|
||||
// lcd.setCursor(x,y);
|
||||
getRally["counter"]=VSSCount;
|
||||
getRallyJson="";
|
||||
serializeJson(getRally, getRallyJson);
|
||||
strRallyJson="";
|
||||
serializeJson(getRally, strRallyJson);
|
||||
// Serial.println("ENDCRal");
|
||||
} ///// calculation only for esp32
|
||||
|
||||
@ -1948,16 +2077,17 @@ void calculationRally() //calculation only ESP32
|
||||
// Serial.println("startCRal");
|
||||
updateCount();
|
||||
|
||||
distance1 = (float)count1/((float)Calibration); // * 1);
|
||||
distance2 = (float)count2/((float)Calibration);
|
||||
|
||||
float speed1=0;
|
||||
distance2 = (float)count2/((float)Calibration);
|
||||
distance1 = (float)count1/((float)Calibration); // * 1);
|
||||
|
||||
if ((distance1 - startdistance) > 0) {
|
||||
speed1 = (distance1-startdistance)/(millis()-startspeed)*3600000;
|
||||
}
|
||||
|
||||
startdistance = distance1;
|
||||
startspeed = millis(); //startspeed is only one no startspeed2
|
||||
startdistance = distance1;
|
||||
|
||||
|
||||
if ((millis()-startsavemillis)>0) {
|
||||
|
||||
@ -1973,7 +2103,7 @@ void calculationRally() //calculation only ESP32
|
||||
startsavemillis=millis()+2500;
|
||||
}
|
||||
// Serial.print(Trip[curTrip].sub);Serial.print(Trip[curTrip].speed);Serial.print(";");Serial.println(Trip[curTrip].startHour);
|
||||
|
||||
delay(1);
|
||||
gcurTime = runningtimeforESP32(6,0);
|
||||
|
||||
sprintf(gcur_speed_str, "%3d.%01d", (int)speed1, (int)((speed1 - (int)speed1)*10));
|
||||
@ -1997,7 +2127,7 @@ void calculationRally() //calculation only ESP32
|
||||
else {
|
||||
sprintf(gcur_distance2_str, "%03d.%01d", (int)distance2, (int)((distance2 - (int)distance2)*10));
|
||||
}
|
||||
|
||||
delay(1);
|
||||
float distancetime1 = distance1 * 60 / constanta;
|
||||
float distancetime2 = distance2 * 60 / constanta;
|
||||
|
||||
@ -2028,6 +2158,7 @@ void calculationRally() //calculation only ESP32
|
||||
tottime1 = totcurrentsecs - tottime1;
|
||||
}
|
||||
}
|
||||
delay(1);
|
||||
//Serial.print(negatifsign);Serial.print(";"); Serial.println(tottime1);
|
||||
hours1 = ((int)(tottime1 / 3600))%24;
|
||||
mins1 = (int)((tottime1 % 3600)/60);
|
||||
@ -2040,7 +2171,7 @@ void calculationRally() //calculation only ESP32
|
||||
if (hours1<10) sprintf(gcur_time1_str, " %s%01d:%02d:%02d", (negatifsign?"-":" "), hours1, mins1, secs1);
|
||||
else sprintf(gcur_time1_str, "%s%02d:%02d:%02d", (negatifsign?"-":" "), hours1, mins1, secs1);
|
||||
}
|
||||
|
||||
delay(1);
|
||||
// Print Second TIME
|
||||
int secs2, mins2, hours2;
|
||||
|
||||
@ -2061,7 +2192,7 @@ void calculationRally() //calculation only ESP32
|
||||
tottime2 = totcurrentsecs - tottime2 ;
|
||||
}
|
||||
}
|
||||
|
||||
delay(1);
|
||||
hours2 = ((int)(tottime2 / 3600))%24;
|
||||
mins2 = (int)((tottime2 % 3600)/60);
|
||||
secs2 = (tottime2 % 60);
|
||||
@ -2078,7 +2209,7 @@ void calculationRally() //calculation only ESP32
|
||||
|
||||
void fillRallyJsonWithData() {
|
||||
DynamicJsonDocument getRally(1024);
|
||||
deserializeJson(getRally, getRallyJson);
|
||||
deserializeJson(getRally, strRallyJson);
|
||||
getRally["Trip"]=String(Trip[curTrip].sub);
|
||||
getRally["TSpeed"]=String(Trip[curTrip].speed);
|
||||
sprintf(gcurTripStartTime, "%02u:%02u:%02u", Trip[curTrip].startHour, Trip[curTrip].startMin, Trip[curTrip].startSec);
|
||||
@ -2099,8 +2230,8 @@ void fillRallyJsonWithData() {
|
||||
getRally["counter"]=String(gVSSCountDiff);
|
||||
if (showTIME) getRally["TDiff"]="Time"; //add 1 space
|
||||
else getRally["TDiff"]="TDiff";
|
||||
getRallyJson="";
|
||||
serializeJson(getRally, getRallyJson);
|
||||
strRallyJson="";
|
||||
serializeJson(getRally, strRallyJson);
|
||||
}
|
||||
|
||||
void fillRallyLCDScreen() {
|
||||
@ -2315,10 +2446,155 @@ void handelSetWifi(AsyncWebServerRequest *request){
|
||||
// Serial.println("ini /setwifi aja");Serial.println(inputMessage);
|
||||
request->send(200, "text/text", inputMessage);
|
||||
}
|
||||
|
||||
|
||||
void handleloadConst(AsyncWebServerRequest *request, JsonVariant &json) {
|
||||
// Serial.print("ptr hloadconst:");Serial.println((unsigned int)request,HEX);
|
||||
// isloadingConst=true;
|
||||
String constTrip;
|
||||
String tempTrip;
|
||||
tempTrip.reserve(100);
|
||||
String tripload;
|
||||
|
||||
tripload = "{\"alltrip\":";
|
||||
tripload+="[";
|
||||
uint8_t maxI=81;
|
||||
DynamicJsonDocument doc(256);
|
||||
float speedinconstanta;
|
||||
// unsigned long sTimeinconstanta;
|
||||
String tempSpeed;
|
||||
tempSpeed.reserve(10);
|
||||
String tempsTime;
|
||||
tempsTime.reserve(10);
|
||||
for(uint8_t i=65; i<TRIPSIZE+65; i++){
|
||||
constTrip = String(char(i));
|
||||
tempTrip=readFile(SPIFFS, String("/trip" + constTrip).c_str());
|
||||
// Serial.print(tempTrip.length()); Serial.print(";");Serial.println(tempTrip);
|
||||
deserializeJson(doc, tempTrip);
|
||||
speedinconstanta = getMemSpeedInConstanta(i-65);
|
||||
// sTimeinconstanta = getMemStime(i-65);
|
||||
tempsTime = getsTime(i-65);
|
||||
tempSpeed=String(speedinconstanta,5);
|
||||
tempSpeed.remove(6);
|
||||
// Serial.print(tempSpeed);Serial.println(speedinconstanta,3);
|
||||
// Serial.println(tempsTime);
|
||||
if (tempTrip==""){
|
||||
doc["trip"]=String(char(i));
|
||||
doc["dist"]=String("");
|
||||
doc["time"]=String("");
|
||||
}
|
||||
doc["speed"]=String(tempSpeed);
|
||||
doc["stime"]=String(tempsTime);
|
||||
tempTrip="";
|
||||
tempSpeed="";
|
||||
tempsTime="";
|
||||
serializeJson(doc, tempTrip);
|
||||
// Serial.print(char(i));Serial.print(tempTrip.length()); Serial.print(";(AFTER)");Serial.println(tempTrip);
|
||||
if (tempTrip!=""){
|
||||
tripload+=tempTrip;
|
||||
tripload+=",";
|
||||
}
|
||||
}
|
||||
tripload.remove(tripload.length()-1,1);
|
||||
tripload+="]}";
|
||||
// tripload=readFile(SPIFFS, String("/trip" + trip).c_str());
|
||||
// Serial.println(tripload);
|
||||
// AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
// DynamicJsonDocument doc(1024);
|
||||
// deserializeJson(doc, tripload);
|
||||
// doc["ok"]=1;
|
||||
// serializeJson(doc, *response);
|
||||
request->send(200, "text/plain", tripload); // handle data and respond
|
||||
// request->send(tripload);
|
||||
// isloadingConst=false;
|
||||
Serial.print("constLoadTime=");Serial.println(millis()-howLongInMillis);
|
||||
}
|
||||
|
||||
char* unConstChar(const char* s) {
|
||||
if(!s)
|
||||
return NULL;
|
||||
int i;
|
||||
char* res = NULL;
|
||||
res = (char*) malloc(strlen(s)+1);
|
||||
if(!res){
|
||||
fprintf(stderr, "Memory Allocation Failed! Exiting...\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else{
|
||||
for (i = 0; s[i] != '\0'; i++) {
|
||||
res[i] = s[i];
|
||||
}
|
||||
res[i] = '\0';
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
char *temp2char;
|
||||
// char *charVal;
|
||||
char gsTime[10];
|
||||
char gSpeed[10];
|
||||
void getTripFromSPIFF(uint8_t charcurTrip, char *&pDist, char **pSpeed, char **pTime, char **psTime){
|
||||
// Serial.print((uint32_t) psTime);Serial.print(";");Serial.print((uint32_t) *psTime);Serial.print(";");Serial.println((uint32_t) **psTime);
|
||||
DynamicJsonDocument doc(200);
|
||||
char filename[7] = "/tripZ";
|
||||
filename[5]=charcurTrip;
|
||||
String tempTrip;
|
||||
tempTrip.reserve(128);
|
||||
String tempSpeed;
|
||||
tempSpeed.reserve(10);
|
||||
String tempsTime;
|
||||
tempsTime.reserve(10);
|
||||
// for(uint8_t i=65; i<TRIPSIZE+65; i++){
|
||||
tempTrip=readFile(SPIFFS, filename);
|
||||
// Serial.print(tempTrip.length()); Serial.print(";");Serial.println(tempTrip);
|
||||
deserializeJson(doc, tempTrip);
|
||||
// speedinconstanta = getMemSpeedInConstanta(i-65);
|
||||
// sTimeinconstanta = getMemStime(i-65);
|
||||
// *pDist = doc["dist"];
|
||||
// String xTemp1;
|
||||
// xTemp.reserve(10);
|
||||
// xTemp1=doc["dist"].as<String>();
|
||||
// *pDist = (char*)xTemp1.c_str();
|
||||
// char charVal[10];
|
||||
float speedinconstanta = getMemSpeedInConstanta(charcurTrip-65);
|
||||
tempsTime = getsTime(charcurTrip-65);
|
||||
// Serial.print(speedinconstanta);Serial.print(";");
|
||||
// Serial.print(tempsTime);Serial.println(";");
|
||||
pDist = unConstChar( doc["dist"].as<const char*>());
|
||||
// *pDist = "hi";
|
||||
// *pSpeed = (char*)doc["speed"].as<const char*>(); //take from the eeprom data
|
||||
*pTime = (char*)doc["time"].as<const char*>();
|
||||
// *psTime = (char*)doc["stime"].as<const char*>();
|
||||
// *pSpeed =(char*) (String(speedinconstanta,4).c_str()); //not working
|
||||
// char hsTime[10];
|
||||
char charVal[10];
|
||||
tempsTime.toCharArray(gsTime, 10);
|
||||
dtostrf(speedinconstanta,1,4,gSpeed);
|
||||
// Serial.println(gsTime);
|
||||
// const char *tempchar=tempsTime.c_str();
|
||||
// temp2char=(char*)tempchar;
|
||||
// Serial.println(tempchar);
|
||||
// Serial.println((char*)tempchar);
|
||||
// Serial.println(temp2char);
|
||||
// Serial.println((uint32_t) &temp2char);
|
||||
// Serial.println((uint32_t) temp2char);
|
||||
// *psTime = &(char*)tempchar;
|
||||
// *psTime = temp2char;
|
||||
// strncpy(charVal, tempsTime.c_str(), 6);
|
||||
*psTime = gsTime;
|
||||
// *psTime = charVal;
|
||||
*pSpeed = gSpeed;
|
||||
// Serial.println((uint32_t) gsTime);
|
||||
// Serial.println((uint32_t) *psTime);
|
||||
// dtostrf(speedinconstanta,1,4,charVal);
|
||||
// *pSpeed = charVal;
|
||||
// Serial.println(charVal);
|
||||
|
||||
}
|
||||
void handleConstantaHTML(AsyncWebServerRequest *request) {
|
||||
//PAGE.replace("%serveripaddress%", WiFi.localIP().toString());
|
||||
//request->send_P(200, "text/html", HTML_CALIBRATION, processor);
|
||||
// isloadingConst=true;
|
||||
// Serial.print("ptr hloadconstHTML:");Serial.println((unsigned int)request,HEX);
|
||||
howLongInMillis=millis();
|
||||
int pageZise;
|
||||
int pageZiseConstRow;
|
||||
@ -2330,25 +2606,45 @@ void handleConstantaHTML(AsyncWebServerRequest *request) {
|
||||
PAGEROW.reserve(pageZiseConstRow);
|
||||
|
||||
PAGE = FPSTR(HTML_CONSTHEADER);
|
||||
char *xDist;
|
||||
char *xSpeed;
|
||||
char *xTime;
|
||||
char *xsTime;
|
||||
for (uint8_t i=65; i<(TRIPSIZE+65); i++){
|
||||
PAGEROW = FPSTR(HTML_CONSTROW);
|
||||
PAGEROW.replace("%A%", String(char(i)));
|
||||
PAGEROW.replace("%speed%", "speed"+String(char(i)));
|
||||
PAGEROW.replace("%dist%", "dist"+String(char(i)));
|
||||
PAGEROW.replace("%speed%", "speed"+String(char(i)));
|
||||
PAGEROW.replace("%time%", "time"+String(char(i)));
|
||||
PAGEROW.replace("%stime%", "stime"+String(char(i)));
|
||||
// Serial.println(PAGEROW);
|
||||
// Fill with data
|
||||
// Serial.print((uint32_t) xsTime);Serial.print(";");Serial.print((uint32_t) *xsTime);Serial.print(";");Serial.println((uint32_t) &xsTime);
|
||||
getTripFromSPIFF(i, xDist, &xSpeed, &xTime, &xsTime);
|
||||
// Serial.print((uint32_t) xsTime);Serial.print(";");Serial.print((uint32_t) *xsTime);Serial.print(";");Serial.println((uint32_t) &xsTime);
|
||||
Serial.print(String(char(i)));Serial.print(";");
|
||||
Serial.print(xDist);Serial.print(";");
|
||||
Serial.print(xSpeed);Serial.print(";");
|
||||
Serial.print(xTime);Serial.print(";");
|
||||
Serial.print(xsTime);Serial.println(";");
|
||||
PAGEROW.replace("%distval%", xDist);
|
||||
PAGEROW.replace("%speedval%", xSpeed);
|
||||
PAGEROW.replace("%timeval%", xTime);
|
||||
PAGEROW.replace("%stimeval%", xsTime);
|
||||
PAGE += PAGEROW;
|
||||
}
|
||||
PAGE += FPSTR(HTML_CONSTEND);
|
||||
// Serial.println(PAGE);
|
||||
Serial.print(pageZise);
|
||||
Serial.print("PAGE Size:");
|
||||
Serial.println(PAGE.length());
|
||||
|
||||
request->send(200, "text/html", PAGE);
|
||||
// request->send(SPIFFS, "/constanta.html", String(), false, procConst); // read from spiif straight away
|
||||
// isloadingConst=false;
|
||||
Serial.println(millis());
|
||||
Serial.print("PAGE Size:");Serial.println(pageZise);
|
||||
Serial.print("Actual Size:");Serial.println(PAGE.length());
|
||||
}
|
||||
|
||||
|
||||
void handlesetConst(AsyncWebServerRequest *request, JsonVariant &json){
|
||||
isloadingConst=true;
|
||||
// JsonObject& jsonObj = json.as<JsonObject>();
|
||||
@ -2375,7 +2671,7 @@ void handlesetConst(AsyncWebServerRequest *request, JsonVariant &json){
|
||||
// const char* speed = data["speed"].as<const char*>();
|
||||
float speed = data["speed"].as<float>();
|
||||
float dist = data["dist"].as<float>();
|
||||
const char* time = data["time"].as<const char*>();//.as<String>();
|
||||
int time = data["time"].as<int>();//.as<String>();
|
||||
// if (!isNumeric(speed)){
|
||||
// canSave = false;
|
||||
// }
|
||||
@ -2392,6 +2688,9 @@ void handlesetConst(AsyncWebServerRequest *request, JsonVariant &json){
|
||||
if (constvaluesettime==-1){
|
||||
canSave = false;
|
||||
}
|
||||
if (!(speed<100)) canSave = false;
|
||||
if (!(dist<1000)) canSave = false;
|
||||
if (!(time<1000)) canSave = false;
|
||||
|
||||
Serial.print(constconstanta,3); Serial.print(";"); Serial.println(constCurTrip);
|
||||
Serial.print(constvaluesettime); Serial.print(";"); Serial.println(speed);
|
||||
@ -2427,70 +2726,6 @@ void handlesetConst(AsyncWebServerRequest *request, JsonVariant &json){
|
||||
}
|
||||
|
||||
|
||||
void handleloadConst(AsyncWebServerRequest *request, JsonVariant &json) {
|
||||
isloadingConst=true;
|
||||
// while(iscalculatingRally) {
|
||||
// yield();
|
||||
// }
|
||||
String constTrip;
|
||||
String tempTrip;
|
||||
tempTrip.reserve(100);
|
||||
String tripload;
|
||||
|
||||
tripload = "{\"alltrip\":";
|
||||
tripload+="[";
|
||||
uint8_t maxI=81;
|
||||
DynamicJsonDocument doc(256);
|
||||
float speedinconstanta;
|
||||
// unsigned long sTimeinconstanta;
|
||||
String tempSpeed;
|
||||
tempSpeed.reserve(10);
|
||||
String tempsTime;
|
||||
tempsTime.reserve(10);
|
||||
for(uint8_t i=65; i<maxI; i++){
|
||||
constTrip = String(char(i));
|
||||
tempTrip=readFile(SPIFFS, String("/trip" + constTrip).c_str());
|
||||
// Serial.print(tempTrip.length()); Serial.print(";");Serial.println(tempTrip);
|
||||
deserializeJson(doc, tempTrip);
|
||||
speedinconstanta = getMemSpeedInConstanta(i-65);
|
||||
// sTimeinconstanta = getMemStime(i-65);
|
||||
tempsTime = getsTime(i-65);
|
||||
tempSpeed=String(speedinconstanta,5);
|
||||
tempSpeed.remove(6);
|
||||
Serial.print(tempSpeed);Serial.println(speedinconstanta,3);
|
||||
// Serial.println(tempsTime);
|
||||
if (tempTrip==""){
|
||||
doc["trip"]=String(char(i));
|
||||
doc["dist"]=String("");
|
||||
doc["time"]=String("");
|
||||
}
|
||||
doc["speed"]=String(tempSpeed);
|
||||
doc["stime"]=String(tempsTime);
|
||||
tempTrip="";
|
||||
tempSpeed="";
|
||||
tempsTime="";
|
||||
serializeJson(doc, tempTrip);
|
||||
// Serial.print(char(i));Serial.print(tempTrip.length()); Serial.print(";(AFTER)");Serial.println(tempTrip);
|
||||
if (tempTrip!=""){
|
||||
tripload+=tempTrip;
|
||||
tripload+=",";
|
||||
}
|
||||
}
|
||||
tripload.remove(tripload.length()-1,1);
|
||||
tripload+="]}";
|
||||
// tripload=readFile(SPIFFS, String("/trip" + trip).c_str());
|
||||
Serial.println(tripload);
|
||||
// AsyncResponseStream *response = request->beginResponseStream("application/json");
|
||||
// DynamicJsonDocument doc(1024);
|
||||
// deserializeJson(doc, tripload);
|
||||
// doc["ok"]=1;
|
||||
// serializeJson(doc, *response);
|
||||
request->send(200, "text/plain", tripload); // handle data and respond
|
||||
// request->send(tripload);
|
||||
isloadingConst=false;
|
||||
Serial.print("constLoadTime=");Serial.println(millis()-howLongInMillis);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
//
|
||||
@ -2555,8 +2790,9 @@ Trip[9].startSec = 58;
|
||||
|
||||
|
||||
//***************************END LCD Setup********************************
|
||||
getCalibJson.reserve(512);
|
||||
getRallyJson.reserve(512);
|
||||
strCalibJson.reserve(512);
|
||||
strRallyJson.reserve(512);
|
||||
strSetTimeJson.reserve(200);
|
||||
#ifdef DEBUG
|
||||
Serial.println("Setting time");
|
||||
#endif
|
||||
@ -2789,19 +3025,36 @@ Serial.println("calibration and constanta");
|
||||
|
||||
server.on("/bootstrap.css", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
// request->send_P(200, "text/html", HTML_startrally1, processor);
|
||||
Serial.println("load /bootstrap.css");
|
||||
Serial.println("load /bootstrap.css");Serial.println(millis());
|
||||
while(!semaphoreS){
|
||||
delay(1);
|
||||
}
|
||||
semaphoreS = false;
|
||||
Serial.println("load1 /bootstrap.css");Serial.println(millis());
|
||||
request->send(SPIFFS, "/bootstrap.css", "text/css");
|
||||
// request->send(SPIFFS, "/tripA", "text/plain");
|
||||
semaphoreS = true;
|
||||
// request->send(SPIFFS, "/bootstrap.css", "text/css");
|
||||
});
|
||||
|
||||
server.on("/bootstrap.bundle.min.js", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
// request->send_P(200, "text/html", HTML_startrally1, processor);
|
||||
Serial.println("load /bootstrap.bundle.min.js");
|
||||
Serial.print("load /bootstrap.bundle.min.js");Serial.println(millis());
|
||||
while(!semaphoreS){
|
||||
delay(1);
|
||||
}
|
||||
semaphoreS = false;
|
||||
Serial.print("load1 /bootstrap.bundle.min.js");Serial.println(millis());
|
||||
// request->send(SPIFFS, "/tripA", "text/plain");
|
||||
request->send(SPIFFS, "/bootstrap.bundle.min.js", "text/javascript");
|
||||
semaphoreS = true;
|
||||
// request->send(SPIFFS, "/bootstrap.bundle.min.js", "text/javascript");
|
||||
|
||||
});
|
||||
|
||||
server.on("/bootstrap.min.js", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
// request->send_P(200, "text/html", HTML_startrally1, processor);
|
||||
Serial.println("load /bootstrap.min.js");
|
||||
Serial.print("load /bootstrap.min.js");Serial.println(millis());
|
||||
request->send(SPIFFS, "/bootstrap.min.js", "text/javascript");
|
||||
});
|
||||
|
||||
@ -2874,6 +3127,21 @@ Serial.println("calibration and constanta");
|
||||
// Serial.println("TOGGLE 2");
|
||||
// request->redirect("/startrally1");
|
||||
// });
|
||||
server.on("/settime", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
int params = request->params(); //showing all params
|
||||
for(int i=0;i<params;i++){
|
||||
AsyncWebParameter* p = request->getParam(i);
|
||||
if(p->isFile()){ //p->isPost() is also true
|
||||
Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size());
|
||||
} else if(p->isPost()){
|
||||
Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||
} else {
|
||||
Serial.printf("GET[%s]: %s\n", p->name().c_str(), p->value().c_str());
|
||||
}
|
||||
}
|
||||
//PAGE.replace("%serveripaddress%", WiFi.localIP().toString());
|
||||
request->send_P(200, "text/html", HTML_SETTIME, processor);
|
||||
});
|
||||
|
||||
server.on("/calibration", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
int params = request->params(); //showing all params
|
||||
@ -2891,63 +3159,85 @@ Serial.println("calibration and constanta");
|
||||
request->send_P(200, "text/html", HTML_CALIBRATION, processor);
|
||||
});
|
||||
server.on("/constanta", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
Serial.println("start /const");
|
||||
if (grequestConstHTMLIsFull) {
|
||||
Serial.println("XXXXXXXXXXXXXXXXXXXX CONSTHTML FULLLL");
|
||||
// request->send(200, "text/plain", "{\"response\":\"request Const is full\"}");
|
||||
Serial.println("XXXXXXXXXXXXXXXXXXXX CONSTHTML SENT");
|
||||
} else {
|
||||
for (uint8_t i=0; i<REQUESTCOUNT;i++){
|
||||
if(!gGotRequestConstHTML[i]){
|
||||
grequestConstHTMLIsFull=true;
|
||||
gRequestConstHTML[i]=request;
|
||||
gGotRequestConstHTML[i]=true;
|
||||
Serial.print("FILL/const:");Serial.println(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Serial.print("start /const:");Serial.println(millis());
|
||||
while(!semaphoreS){
|
||||
delay(1);
|
||||
}
|
||||
semaphoreS = false;
|
||||
Serial.print("start1 /const:");Serial.println(millis());
|
||||
handleConstantaHTML(request);
|
||||
semaphoreS = true;
|
||||
// if (grequestConstHTMLIsFull) {
|
||||
// Serial.println("XXXXXXXXXXXXXXXXXXXX CONSTHTML FULLLL");
|
||||
// // request->send(200, "text/plain", "{\"response\":\"request Const is full\"}");
|
||||
// Serial.println("XXXXXXXXXXXXXXXXXXXX CONSTHTML SENT");
|
||||
// } else {
|
||||
// for (uint8_t i=0; i<REQUESTCOUNT;i++){
|
||||
// if(!gGotRequestConstHTML[i]){
|
||||
// grequestConstHTMLIsFull=true;
|
||||
// gRequestConstHTML[i]=request;
|
||||
// gGotRequestConstHTML[i]=true;
|
||||
// Serial.print("FILL/const:");Serial.println(i);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// handleConstantaHTML(request);
|
||||
});
|
||||
|
||||
|
||||
AsyncCallbackJsonWebHandler* setconst = new AsyncCallbackJsonWebHandler("/rest/endpoint", [](AsyncWebServerRequest *request, JsonVariant &json) {
|
||||
isloadingConst=true;
|
||||
// isloadingConst=true;
|
||||
// handlesetConst(request, json);
|
||||
// isloadingConst=false;
|
||||
while(!semaphoreS){
|
||||
delay(1);
|
||||
}
|
||||
semaphoreS = false;
|
||||
handlesetConst(request, json);
|
||||
isloadingConst=false;
|
||||
semaphoreS = true;
|
||||
});
|
||||
|
||||
AsyncCallbackJsonWebHandler* loadconst = new AsyncCallbackJsonWebHandler("/rest/loadconst", [](AsyncWebServerRequest *request, JsonVariant &json) {
|
||||
Serial.println("loadconst");
|
||||
// if (gGotRequest[0])
|
||||
if (grequestIsFull) {
|
||||
Serial.println("XXXXXXXXXXXXXXXXXXXX FULLLL");
|
||||
// request->send(200, "text/plain", "{\"response\":\"request is full\"}");
|
||||
Serial.println("XXXXXXXXXXXXXXXXXXXX SENT");
|
||||
} else {
|
||||
for (uint8_t i=0; i<REQUESTCOUNT;i++){
|
||||
if(!gGotRequest[i]){
|
||||
grequestIsFull=true;
|
||||
gRequest[i]=request;
|
||||
gJson[i]=json;
|
||||
gGotRequest[i]=true;
|
||||
Serial.print("FILL:");Serial.println(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Serial.print("loadconst");Serial.println(millis());
|
||||
while(!semaphoreS){
|
||||
delay(1);
|
||||
}
|
||||
semaphoreS = false;
|
||||
Serial.print("loadconst1");Serial.println(millis());
|
||||
handleloadConst(request, json);
|
||||
semaphoreS = true;
|
||||
// // if (gGotRequest[0])
|
||||
// if (grequestIsFull) {
|
||||
// Serial.println("XXXXXXXXXXXXXXXXXXXX FULLLL");
|
||||
// // request->send(200, "text/plain", "{\"response\":\"request is full\"}");
|
||||
// Serial.println("XXXXXXXXXXXXXXXXXXXX SENT");
|
||||
// } else {
|
||||
// for (uint8_t i=0; i<REQUESTCOUNT;i++){
|
||||
// if(!gGotRequest[i]){
|
||||
// grequestIsFull=true;
|
||||
// gRequest[i]=request;
|
||||
// gJson[i]=json;
|
||||
// gGotRequest[i]=true;
|
||||
// Serial.print("FILL:");Serial.println(i);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
});
|
||||
server.addHandler(setconst);
|
||||
server.addHandler(loadconst);
|
||||
|
||||
Serial.println("before onevent");
|
||||
ws.onEvent(onWsEvent); //add ws event
|
||||
wscal.onEvent(onWsEvent2); //add ws event
|
||||
// Serial.println("before onevent");
|
||||
ws.onEvent(onWsEvent); //add ws event Rally
|
||||
wscal.onEvent(onWsEventCalibration); //add ws event Calibration
|
||||
wssettime.onEvent(onWsEventSetTime); //add ws event Set Time
|
||||
server.addHandler(&ws);
|
||||
server.addHandler(&wscal);
|
||||
Serial.println("after onevent");
|
||||
server.addHandler(&wssettime);
|
||||
// Serial.println("after onevent");
|
||||
server.onNotFound(notFound);
|
||||
Serial.println("onnotfound");
|
||||
// Serial.println("onnotfound");
|
||||
|
||||
server.begin();
|
||||
Serial.println("server begin");
|
||||
@ -3992,8 +4282,16 @@ void loop() //loop from VSS RALLY V2
|
||||
}
|
||||
|
||||
if ((MENU==RALLY || globalClientRally) && ((now1 - prevCalculatingRallyMillis)>=calculatingRallyMillis)){
|
||||
calculationRally();
|
||||
prevCalculatingRallyMillis=now1;
|
||||
if(semaphoreS){
|
||||
prevCalculatingRallyMillis=millis();
|
||||
Serial.println("St calculationRally()");
|
||||
semaphoreS=false;
|
||||
calculationRally();
|
||||
Serial.print("end calculationRally() in:");Serial.println(millis()-prevCalculatingRallyMillis);
|
||||
prevCalculatingRallyMillis=now1;
|
||||
|
||||
semaphoreS=true;
|
||||
}
|
||||
}
|
||||
|
||||
if ((millis()-broadcastwebsocket) > 330 && !isloadingConst && globalClientRally) {
|
||||
@ -4003,18 +4301,24 @@ void loop() //loop from VSS RALLY V2
|
||||
fillRallyJsonWithData();
|
||||
// Serial.print("calculationRallyTime=");Serial.println(micros()-broadcastwebsocket);
|
||||
iscalculatingRally=false;
|
||||
// Serial.println(getRallyJson);
|
||||
ws.textAll(getRallyJson);
|
||||
// Serial.println(strRallyJson);
|
||||
ws.textAll(strRallyJson);
|
||||
// Serial.print("calculationRallyToTTime=");Serial.println(micros()-broadcastwebsocket);
|
||||
broadcastwebsocket = millis();
|
||||
}
|
||||
|
||||
if ((millis()-broadcastwebsocketcalib) > 499 && !isloadingConst && globalClientCalib) {
|
||||
broadcastwebsocketcalib = millis();
|
||||
redrawcalibrationMenuForESP32();
|
||||
// Serial.println(getCalibJson);
|
||||
if ((millis()-timerWebsocketCalibration) > 499 && !isloadingConst && globalClientCalib) {
|
||||
timerWebsocketCalibration = millis();
|
||||
// if (globalClientCalib) {
|
||||
redrawcalibrationMenuForESP32();
|
||||
wscal.textAll(strCalibJson);
|
||||
// }
|
||||
}
|
||||
|
||||
wscal.textAll(getCalibJson);
|
||||
if ((millis()-timerWebsocketSetTime) > 1000 && globalClientSetTime) {
|
||||
timerWebsocketSetTime = millis();
|
||||
fillSetTimeJsonForESP32();
|
||||
wssettime.textAll(strSetTimeJson);
|
||||
}
|
||||
|
||||
if(!isloadingConst){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user