mirror of
https://github.com/bcomsugi/VSS_Rally_V3.git
synced 2026-01-08 17:32:38 +07:00
init
This commit is contained in:
commit
7e3f40f15e
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
],
|
||||
"unwantedRecommendations": [
|
||||
"ms-vscode.cpptools-extension-pack"
|
||||
]
|
||||
}
|
||||
1972
backup/VSS_Rally_V2.h
Normal file
1972
backup/VSS_Rally_V2.h
Normal file
File diff suppressed because it is too large
Load Diff
413
backup/backup index before cleanup.h
Normal file
413
backup/backup index before cleanup.h
Normal file
@ -0,0 +1,413 @@
|
||||
const char MAIN_page[] PROGMEM = R"=====(
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<style>
|
||||
.card{
|
||||
max-width: 400px;
|
||||
min-height: 250px;
|
||||
background: #02b875;
|
||||
padding: 30px;
|
||||
box-sizing: border-box;
|
||||
color: #FFF;
|
||||
margin:20px;
|
||||
box-shadow: 0px 2px 18px -4px rgba(0,0,0,0.75);
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
|
||||
<div class="card">
|
||||
<h4>The ESP32 Update web page without refresh</h4><br>
|
||||
<h1>Sensor Value:<span id="ADCValue">0</span></h1><br>
|
||||
<h1>Sensor 2 Value:<span id="ADCValue2">0</span></h1><br>
|
||||
<h1>Sensor 3 Value:<span id="ADCValue3">0</span></h1><br>
|
||||
<h1>Time: <span id="time">0</span></h1><br>
|
||||
<br><a href="https://circuits4you.com">Circuits4you.com</a>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
setInterval(function() {
|
||||
// Call a function repetatively with 2 Second interval
|
||||
getData();
|
||||
}, 333); //2000mSeconds update rate
|
||||
|
||||
function getData() {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var data = JSON.parse(this.responseText);
|
||||
document.getElementById("ADCValue").innerHTML =
|
||||
data.pin36;
|
||||
document.getElementById("ADCValue2").innerHTML =
|
||||
data.pin39;
|
||||
document.getElementById("ADCValue3").innerHTML =
|
||||
data.pin5;
|
||||
document.getElementById("time").innerHTML =
|
||||
data.time;
|
||||
//this.responseText;
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", "readADC", true);
|
||||
xhttp.send();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
)=====";
|
||||
|
||||
|
||||
const char HTML_startrally1[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1</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">
|
||||
<script type = "text/javascript">
|
||||
const ws = new WebSocket("ws://%serveripaddress%/ws");
|
||||
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("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("tripspeed").innerHTML = data.curTripSpeed;
|
||||
document.getElementById("currentspeed").innerHTML = data.curSpeed;
|
||||
document.getElementById("dir1").innerHTML = data.dir1;
|
||||
document.getElementById("dir2").innerHTML = data.dir2;
|
||||
document.getElementById("odo1").innerHTML = data.curDist1;
|
||||
document.getElementById("odo2").innerHTML = data.curDist2;
|
||||
document.getElementById("time1").innerHTML = data.time1;
|
||||
document.getElementById("time2").innerHTML = data.time2;
|
||||
};
|
||||
</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>
|
||||
<div class=" bg-success text-white">
|
||||
<div class="row">
|
||||
<div class="col-1 mt-1"><h6><span id="counter">12345</span></h6></div>
|
||||
|
||||
<div class="col-3 mt-1 text-end"><h2>TRIP <span id="currenttrack">A</span> (<span id="tripspeed">123.4</span>Km/h)</h2></div>
|
||||
<div class="col mt-1"><h2 class="text-center">Time: <span id="currenttime">00:00:00</span></h2></div>
|
||||
<div class="col-2 mt-1 text-end"><h2><span id="currentspeed">123.4</span>Km/h</h2></div>
|
||||
<hr>
|
||||
</div>
|
||||
<!--//ODO1-->
|
||||
<div class="row">
|
||||
<div class="col-2"><h4>OD 1-></h4></div>
|
||||
<div class="col-3 text-end"><h3><span id="odo1">123.4567</span> km</h3></div>
|
||||
<div class="col-4"><h3><span id="dir1">DIRECT</span></h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time1">00:00:00</span></h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5 "><h4>
|
||||
<button ondblclick="resetodo1()" type="button" class="btn btn-primary btn-sm mb-2">Reset ODO1</button>
|
||||
<button ondblclick="copytoodo2()" type="button" class="btn btn-primary btn-sm mb-2">↓ to ODO2</button></h4>
|
||||
</div>
|
||||
<div class="col-4"><h4>
|
||||
<button ondblclick="dirFW1()" type="button" class="btn btn-primary btn-sm mb-2">FW</button>
|
||||
<button ondblclick="dirStop1()" type="button" class="btn btn-primary btn-sm mb-2">STOP</button>
|
||||
<button ondblclick="dirBack1()" type="button" class="btn btn-primary btn-sm mb-2">BACK</button></h4>
|
||||
</div>
|
||||
<div class="col"><h4>
|
||||
<div class="d-grid gap-0 d-md-flex justify-content-md-end">
|
||||
<button onclick="toggleTime1()" class="btn btn-primary btn-sm me-md-4" type="button">Toggle</button>
|
||||
</div></h4>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<!--//ODO2-->
|
||||
<div class="row">
|
||||
<div class="col-5 "><h3>OD 2-><span id="odo2">123.456</span> km</h3></div>
|
||||
<div class="col-4 "><h3><span id="dir2">DIRECT</span></h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time2">00:00:00</span></h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5"><h5>
|
||||
<button ondblclick="resetodo2()" type="button" class="btn btn-primary btn-sm mb-1">Reset ODO2</button>
|
||||
<button ondblclick="copytoodo1()" type="button" class="btn btn-primary btn-sm mb-1 arrow-up down-arrow">↑ to ODO1</button></h5>
|
||||
</div>
|
||||
<div class="col-4"><h5>
|
||||
<button ondblclick="dirFW2()" class="btn btn-primary btn-sm mb-1" type="button">FW</button>
|
||||
<button ondblclick="dirStop2()" class="btn btn-primary btn-sm mb-1" type="button">STOP</button>
|
||||
<button ondblclick="dirBack2()" class="btn btn-primary btn-sm mb-1" type="button">BACK</button></h5>
|
||||
</div>
|
||||
<div class="col"><h2>
|
||||
<div class="d-grid gap-0 d-md-flex justify-content-md-end">
|
||||
<button onclick="toggleTime2()" class="btn btn-primary btn-sm me-md-4" type="button">Toggle</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button ondblclick="location.href='/menu';" class="btn btn-secondary fw-bold btn-sm mt-2 mb-2">Back to Menu</button>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Are you Sure <span class="func">Reset</span> ODO <span id="p1" class="odonum">1</span> ?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button id="btnyesreset" type="button" data-bs-dismiss="modal" class="btn btn-primary">Yes, <span class="func">Reset</span> ODO <span class="odonum"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<script>
|
||||
setInterval(function() {
|
||||
// Call a function repetatively with 2 Second interval
|
||||
getData();
|
||||
}, 10000); //2000mSeconds update rate
|
||||
</script>
|
||||
<script>
|
||||
function getData() {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
console.log(this.responseText);
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var data = JSON.parse(this.responseText);
|
||||
document.getElementById("currenttime").innerHTML = data.curtime;
|
||||
document.getElementById("currenttrack").innerHTML = data.curtrack;
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("speed").innerHTML = data.speed;
|
||||
document.getElementById("dir1").innerHTML = data.dir1;
|
||||
document.getElementById("dir2").innerHTML = data.dir2;
|
||||
document.getElementById("odo1").innerHTML = data.odo1;
|
||||
document.getElementById("odo2").innerHTML = data.odo2;
|
||||
document.getElementById("time1").innerHTML = data.time1;
|
||||
document.getElementById("time2").innerHTML = data.time2;
|
||||
|
||||
//this.responseText;
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", "readADC", true);
|
||||
xhttp.send();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
getData();
|
||||
});
|
||||
</script>
|
||||
-->
|
||||
<script>
|
||||
function resetodo1(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "resetODO1()" );
|
||||
document.getElementById("p1").innerHTML = "1";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "1";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "RESET";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function resetodo2(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "resetODO2()" );
|
||||
document.getElementById("p1").innerHTML = "2";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "2";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "RESET";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function copytoodo2(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "copytoODO2()" );
|
||||
document.getElementById("p1").innerHTML = "2";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "2";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "Copy ODO 1 to";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function copytoodo1(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "copytoODO1()" );
|
||||
document.getElementById("p1").innerHTML = "1";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "1";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "Copy ODO 2 to";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function resetODO1(){
|
||||
ws.send('{"resetodo":1}');
|
||||
console.log("resetodo->1");
|
||||
}
|
||||
function resetODO2(){
|
||||
ws.send('{"resetodo":2}');
|
||||
console.log("resetodo->2");
|
||||
}
|
||||
function copytoODO2(){
|
||||
ws.send('{"copytoodo":2}');
|
||||
console.log("copytoodo->2");
|
||||
}
|
||||
function copytoODO1(){
|
||||
ws.send('{"copytoodo":1}');
|
||||
console.log("copytoodo->1");
|
||||
}
|
||||
function dirFW1(){
|
||||
ws.send('{"dir1":0}');
|
||||
console.log("dir1->0");
|
||||
}
|
||||
function dirStop1(){
|
||||
ws.send('{"dir1":1}');
|
||||
console.log("dir1->1");
|
||||
}
|
||||
function dirBack1(){
|
||||
ws.send('{"dir1":2}');
|
||||
console.log("dir1->2");
|
||||
}
|
||||
function dirFW2(){
|
||||
ws.send('{"dir2":0}');
|
||||
console.log("dir2->0");
|
||||
}
|
||||
function dirStop2(){
|
||||
ws.send('{"dir2":1}');
|
||||
console.log("dir2->1");
|
||||
}
|
||||
function dirBack2(){
|
||||
ws.send('{"dir2":2}');
|
||||
console.log("dir2->2");
|
||||
}
|
||||
function toggleTime1(){
|
||||
ws.send('{"toggle":1}');
|
||||
console.log("toggle->1");
|
||||
}
|
||||
function toggleTime2(){
|
||||
ws.send('{"toggle":2}');
|
||||
console.log("toggle->2");
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
)rawliteral";
|
||||
|
||||
//HTML_CALIBRATION
|
||||
|
||||
|
||||
|
||||
const char HTML_CALIBRATION[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1 Calibration</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">
|
||||
<script type = "text/javascript">
|
||||
const ws = new WebSocket("ws://%serveripaddress%/wscal");
|
||||
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("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("speed").innerHTML = data.curTripSpeed;
|
||||
document.getElementById("caldist").innerHTML = data.caldist;
|
||||
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>
|
||||
<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 Distance (<span id="caldist">9</span> Km)-></h3></div>
|
||||
<div class="col text-start"><h3>
|
||||
|
||||
<input type="number" step="any" maxlength="2" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="setdistance" name="setdistance" size="4">
|
||||
<button class="btn btn-primary mb-2 fw-bold" onclick="setDistance()">SET</button>
|
||||
</h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-end"><h3>Set Calibration Manually (<span id="calman">110000</span>)-></h3></div>
|
||||
<div class="col text-start"><h3>
|
||||
|
||||
<input type="number" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
size="3" id="setcalibration" name="setcalibration">
|
||||
<button class="btn btn-primary mb-2 fw-bold" onclick="setCalibration()">SET</button>
|
||||
</h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-end"><h4>
|
||||
<button ondblclick="startCalibration()" type="button" class="btn btn-primary mb-2 me-md-4">Start Calibration</button>
|
||||
<button ondblclick="stopCalibration()" type="button" class="btn btn-primary mb-2 me-md-4">Stop Calibration</button></h4>
|
||||
</div>
|
||||
<div class="col"><h3>
|
||||
<span id="calkm">00.000</span>Km</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-end me-md-4"><h3>1 meter=<span id="calmeter">123.456</span></h3></div>
|
||||
<div class="col"><h3><span id="calval">123456</span> Calibration Value</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 setDistance(e){
|
||||
const setDis = document.getElementById("setdistance").value;
|
||||
var full_data='{"setcaldis":'+setDis+'}';
|
||||
console.log(full_data);
|
||||
ws.send(full_data);
|
||||
}
|
||||
function setCalibration(e){
|
||||
const setCal = document.getElementById("setcalibration").value;
|
||||
var full_data='{"setcaldisman":'+setCal+'}';
|
||||
console.log(full_data);
|
||||
ws.send(full_data);
|
||||
}
|
||||
function startCalibration(e){
|
||||
ws.send('{"calstart":1}');
|
||||
console.log("calstart->1");
|
||||
}
|
||||
function stopCalibration(e){
|
||||
ws.send('{"calstart":0}');
|
||||
console.log("calstart->0");
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
)rawliteral";
|
||||
677
backup/backup_main.cpp
Normal file
677
backup/backup_main.cpp
Normal file
@ -0,0 +1,677 @@
|
||||
/*********
|
||||
Rui Santos
|
||||
Complete project details at https://RandomNerdTutorials.com/esp32-esp8266-input-data-html-form/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files.
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
*********/
|
||||
|
||||
#include <Arduino.h>
|
||||
#ifdef ESP32
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <SPIFFS.h>
|
||||
#else
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
#include <Hash.h>
|
||||
#include <FS.h>
|
||||
#endif
|
||||
#include <ESPAsyncWebServer.h>
|
||||
//#include <ESPAsync_WiFiManager.hpp>
|
||||
#include <index.h>
|
||||
#include <template_html.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <time.h>
|
||||
//#include <VSS_Rally_V2.h>
|
||||
|
||||
AsyncWebServer server(80);
|
||||
AsyncWebSocket ws("/ws");
|
||||
AsyncWebSocket wscal("/wscal");
|
||||
//WiFiManager wifiManager;
|
||||
|
||||
// REPLACE WITH YOUR NETWORK CREDENTIALS
|
||||
char ssid[] = "WiFi_SuGi";
|
||||
char password[] = "12345678901";
|
||||
|
||||
//strcpy(ssid,"WiFi_SuGi");
|
||||
|
||||
//password = "1234567890";
|
||||
|
||||
const char *soft_ap_ssid = "MyESP32AP";
|
||||
const char *soft_ap_password = "testpassword";
|
||||
|
||||
const char* PARAM_STRING = "inputString";
|
||||
const char* PARAM_INT = "inputInt";
|
||||
const char* PARAM_FLOAT = "inputFloat";
|
||||
|
||||
const char* PARAM_SSID = "ssidString";
|
||||
const char* PARAM_PWD = "inputPwd";
|
||||
|
||||
const char* ntpServer = "pool.ntp.org";
|
||||
const long gmtOffset_sec = 7*3600;
|
||||
const int daylightOffset_sec = 0;
|
||||
|
||||
|
||||
|
||||
void notFound(AsyncWebServerRequest *request) {
|
||||
request->send(404);
|
||||
}
|
||||
|
||||
String readFile(fs::FS &fs, const char * path){
|
||||
Serial.printf("Reading file: %s\r\n", path);
|
||||
File file = fs.open(path, "r");
|
||||
if(!file || file.isDirectory()){
|
||||
Serial.println("- empty file or failed to open file");
|
||||
return String();
|
||||
}
|
||||
Serial.print("- read from file:");
|
||||
String fileContent;
|
||||
while(file.available()){
|
||||
fileContent+=String((char)file.read());
|
||||
}
|
||||
file.close();
|
||||
Serial.println(fileContent);
|
||||
return fileContent;
|
||||
}
|
||||
|
||||
void writeFile(fs::FS &fs, const char * path, const char * message){
|
||||
Serial.printf("Writing file: %s\r\n", path);
|
||||
File file = fs.open(path, "w");
|
||||
if(!file){
|
||||
Serial.println("- failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
if(file.print(message)){
|
||||
Serial.println("- file written");
|
||||
} else {
|
||||
Serial.println("- write failed");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
// Replaces placeholder with stored values
|
||||
String processor(const String& var){
|
||||
//Serial.println(var);
|
||||
Serial.print("Processor ");
|
||||
Serial.print(var);
|
||||
if(var == "inputString"){
|
||||
return readFile(SPIFFS, "/inputString.txt");
|
||||
}
|
||||
else if(var == "inputInt"){
|
||||
return readFile(SPIFFS, "/inputInt.txt");
|
||||
}
|
||||
else if(var == "inputFloat"){
|
||||
return readFile(SPIFFS, "/inputFloat.txt");
|
||||
}
|
||||
else if(var == "ssidString"){
|
||||
return readFile(SPIFFS, "/ssidString.txt");
|
||||
}
|
||||
else if(var == "localip"){
|
||||
return WiFi.localIP().toString();
|
||||
}
|
||||
else if(var == "serveripaddress"){
|
||||
if (WiFi.localIP().toString()!="0.0.0.0"){
|
||||
Serial.println(WiFi.localIP());
|
||||
return WiFi.localIP().toString();
|
||||
} else {
|
||||
Serial.println(WiFi.softAPIP());
|
||||
return WiFi.softAPIP().toString();
|
||||
}
|
||||
}
|
||||
// else if(var == "inputPwd"){
|
||||
// return readFile(SPIFFS, "/inputPwd.txt");
|
||||
// }
|
||||
return String();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void OnWiFiEvent(WiFiEvent_t event)
|
||||
{
|
||||
switch (event) {
|
||||
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
Serial.println("ESP32 Connected to WiFi Network");
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_START:
|
||||
Serial.println("ESP32 soft AP started");
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STACONNECTED:
|
||||
Serial.println("Station connected to ESP32 soft AP");
|
||||
break;
|
||||
case SYSTEM_EVENT_AP_STADISCONNECTED:
|
||||
Serial.println("Station disconnected from ESP32 soft AP");
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
String getPin(){
|
||||
struct tm timeinfo;
|
||||
String hasil;
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
Serial.println("Failed to obtain time");
|
||||
return hasil;
|
||||
}
|
||||
// StaticJsonBuffer<200> jsonBuffer;
|
||||
// JsonObject& root = JsonBuffer.createObject();
|
||||
DynamicJsonDocument testdoc(512);
|
||||
//String datetime = &timeinfo;
|
||||
char datetime[21];
|
||||
char time[9];
|
||||
strftime(datetime, 21, "%d %b %Y %H:%M:%S", &timeinfo);
|
||||
strftime(time, 9, "%H:%M:%S", &timeinfo);
|
||||
//Serial.println(&timeinfo);
|
||||
//Serial.println(datetime);
|
||||
testdoc["pin36"]=242;
|
||||
testdoc["pin39"]=datetime;
|
||||
testdoc["time"]=time;
|
||||
// testdoc["datetime"]=datetime;
|
||||
testdoc["pin5"]=millis();
|
||||
testdoc["curtime"]=time;
|
||||
testdoc["speed"]=String(float(random(1,20000))/100,1);
|
||||
testdoc["counter"]=random(0,50000);
|
||||
String bb[]={"A","B","C","D","E","F","G","H","I","J","K","L"};
|
||||
testdoc["curtrack"]=bb[random(12)];
|
||||
String dir[]={"FW","STOP","BACK"};
|
||||
testdoc["dir1"]=dir[random(3)];
|
||||
testdoc["dir2"]=dir[random(3)];
|
||||
testdoc["time1"]=time;
|
||||
testdoc["time2"]=time;
|
||||
float odo1=float(millis())/10000;
|
||||
float odo2=float(millis())/20000;
|
||||
//Serial.println(odo1,3);
|
||||
testdoc["odo1"]=String(odo1,3);
|
||||
testdoc["odo2"]=String(odo2,3); // if disabled, the web will get undefined value
|
||||
//serializeJson(testdoc,Serial);
|
||||
serializeJson(testdoc,hasil);
|
||||
//testdoc.printTo(hasil);
|
||||
// testdoc.clear();
|
||||
return hasil;
|
||||
}
|
||||
String getCalib(){
|
||||
struct tm timeinfo;
|
||||
String hasil;
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
Serial.println("Failed to obtain time");
|
||||
return hasil;
|
||||
}
|
||||
DynamicJsonDocument testdoc(200);
|
||||
//String datetime = &timeinfo;
|
||||
char datetime[21];
|
||||
char time[9];
|
||||
strftime(datetime, 21, "%d %b %Y %H:%M:%S", &timeinfo);
|
||||
strftime(time, 9, "%H:%M:%S", &timeinfo);
|
||||
//Serial.println(&timeinfo);
|
||||
//Serial.println(datetime);
|
||||
// testdoc["datetime"]=datetime;
|
||||
testdoc["curtime"]=time;
|
||||
testdoc["speed"]=String(float(random(1,20000))/100,1);
|
||||
testdoc["counter"]=random(0,50000);
|
||||
String bb[]={"A","B","C","D","E","F","G","H","I","J","K","L"};
|
||||
testdoc["curtrack"]=bb[random(12)];
|
||||
float calkm=float(millis())/100000;
|
||||
float calmeter=float(millis())/100;
|
||||
testdoc["caldist"]=random(9);
|
||||
testdoc["calman"]=random(100000, 150000);
|
||||
testdoc["calkm"]=String(calkm,3);
|
||||
testdoc["calmeter"]=String(calmeter,3);
|
||||
//Serial.println(odo1,3);
|
||||
testdoc["calval"]=String(calmeter*1000); // if disabled, the web will get undefined value
|
||||
//serializeJson(testdoc,Serial);
|
||||
serializeJson(testdoc,hasil);
|
||||
//testdoc.printTo(hasil);
|
||||
// testdoc.clear();
|
||||
return hasil;
|
||||
}
|
||||
|
||||
void printLocalTime(){
|
||||
struct tm timeinfo;
|
||||
if(!getLocalTime(&timeinfo)){
|
||||
Serial.println("Failed to obtain time");
|
||||
return;
|
||||
}
|
||||
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
|
||||
Serial.print("Day of week: ");
|
||||
Serial.println(&timeinfo, "%A");
|
||||
Serial.print("Month: ");
|
||||
Serial.println(&timeinfo, "%B");
|
||||
Serial.print("Day of Month: ");
|
||||
Serial.println(&timeinfo, "%d");
|
||||
Serial.print("Year: ");
|
||||
Serial.println(&timeinfo, "%Y");
|
||||
Serial.print("Hour: ");
|
||||
Serial.println(&timeinfo, "%H");
|
||||
Serial.print("Hour (12 hour format): ");
|
||||
Serial.println(&timeinfo, "%I");
|
||||
Serial.print("Minute: ");
|
||||
Serial.println(&timeinfo, "%M");
|
||||
Serial.print("Second: ");
|
||||
Serial.println(&timeinfo, "%S");
|
||||
|
||||
Serial.println("Time variables");
|
||||
char timeHour[3];
|
||||
strftime(timeHour,3, "%H", &timeinfo);
|
||||
Serial.println(timeHour);
|
||||
char timeWeekDay[10];
|
||||
strftime(timeWeekDay,10, "%A", &timeinfo);
|
||||
Serial.println(timeWeekDay);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
boolean isDecimal(String str){
|
||||
for(byte i=0;i<str.length();i++)
|
||||
{
|
||||
if(isDigit(str.charAt(i))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
|
||||
if(type == WS_EVT_CONNECT){
|
||||
Serial.println("Websocket client connection received");
|
||||
Serial.print("IPAdd client:"); Serial.println(client->remoteIP());
|
||||
client->text(getPin());
|
||||
} else if(type == WS_EVT_DISCONNECT){
|
||||
Serial.println("Client disconnected");
|
||||
Serial.print("IPAdd client:"); Serial.println(client->remoteIP());
|
||||
} else if(type == WS_EVT_DATA){
|
||||
Serial.print("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(256);
|
||||
// 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("deserialiseJson() failed: ");
|
||||
Serial.println(error.c_str());
|
||||
client->text(error.c_str());
|
||||
return;
|
||||
}
|
||||
String ledstatus=doc["LED1"];
|
||||
if (ledstatus=="null"){Serial.println("led1 is null");}
|
||||
Serial.print("LED1=");Serial.println(ledstatus);
|
||||
}
|
||||
}
|
||||
|
||||
void onWsEvent2(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
|
||||
if(type == WS_EVT_CONNECT){
|
||||
Serial.println("wscal Websocket client connection received");
|
||||
Serial.print("IPAdd client:"); Serial.println(client->remoteIP());
|
||||
client->text(getCalib());
|
||||
} else if(type == WS_EVT_DISCONNECT){
|
||||
Serial.println("wscal Client disconnected");
|
||||
Serial.print("IPAdd client:"); Serial.println(client->remoteIP());
|
||||
} else if(type == WS_EVT_DATA){
|
||||
Serial.print("wscal 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(200);
|
||||
// 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("wscal deserialiseJson() failed: ");
|
||||
Serial.println(error.c_str());
|
||||
client->text(error.c_str());
|
||||
return;
|
||||
}
|
||||
String setdis=doc["setdis"];
|
||||
String setcal=doc["setcal"];
|
||||
String calstart=doc["calstart"];
|
||||
Serial.print("setdis=");Serial.println(setdis);
|
||||
Serial.print("setcal=");Serial.println(setcal);
|
||||
Serial.print("calstart=");Serial.println(calstart);
|
||||
if (setdis!="null"){
|
||||
if (isDecimal(setdis)){
|
||||
Serial.print("setdis=");Serial.println(setdis.toInt());
|
||||
}
|
||||
}
|
||||
if (setcal!="null"){
|
||||
if (isDecimal(setcal)){
|
||||
Serial.print("setcal=");Serial.println(setcal.toInt());
|
||||
}
|
||||
}
|
||||
if (calstart="null"){
|
||||
if (isDecimal(calstart)){
|
||||
if(calstart=="1"){
|
||||
Serial.print("calstart=");Serial.println("START");
|
||||
} else if(calstart=="0"){
|
||||
|
||||
}
|
||||
Serial.print("calstart=");Serial.println("STOP");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void configModeCallback (WiFiManager *myWiFiManager) {
|
||||
// Serial.println("Entered config mode");
|
||||
// Serial.println(WiFi.softAPIP());
|
||||
|
||||
// Serial.println(myWiFiManager->getConfigPortalSSID());
|
||||
// }
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
DynamicJsonDocument doc(512);
|
||||
// Initialize SPIFFS
|
||||
#ifdef ESP32
|
||||
if(!SPIFFS.begin(true)){
|
||||
Serial.println("An Error has occurred while mounting SPIFFS");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if(!SPIFFS.begin()){
|
||||
Serial.println("An Error has occurred while mounting SPIFFS");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// wifiManager.setAPCallback(configModeCallback);
|
||||
// wifiManager.autoConnect(soft_ap_ssid);
|
||||
|
||||
WiFi.onEvent(OnWiFiEvent);
|
||||
//WiFi.mode(WIFI_STA);
|
||||
WiFi.mode(WIFI_MODE_APSTA);
|
||||
|
||||
WiFi.softAP(soft_ap_ssid, soft_ap_password);
|
||||
|
||||
String yourSSIDString = readFile(SPIFFS, "/ssidString.txt");
|
||||
Serial.print("*** Your ssidString: ");
|
||||
Serial.println(yourSSIDString);
|
||||
Serial.println(ssid);
|
||||
if (yourSSIDString != ""){
|
||||
strncpy(ssid, yourSSIDString.c_str() , (sizeof ssid)-1);
|
||||
}
|
||||
|
||||
Serial.println(ssid);
|
||||
String yourInputPwd = readFile(SPIFFS, "/inputPwd.txt");
|
||||
Serial.print("*** Your inputPwd: ");
|
||||
Serial.println(yourInputPwd);
|
||||
if (yourInputPwd != ""){
|
||||
strncpy(password, yourInputPwd.c_str() , (sizeof password)-1);
|
||||
}
|
||||
|
||||
WiFi.begin(ssid, password);
|
||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.println("WiFi Failed!");
|
||||
//return;
|
||||
}
|
||||
|
||||
Serial.print("ESP32 IP as soft AP: ");
|
||||
Serial.println(WiFi.softAPIP());
|
||||
|
||||
Serial.println();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
// Init and get the time
|
||||
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
|
||||
printLocalTime();
|
||||
|
||||
// Send web page with input fields to client
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
if (ON_STA_FILTER(request)) {
|
||||
//request->send(200, "text/plain", "Hello from STA");
|
||||
request->send_P(200, "text/html", main_menu, processor);
|
||||
return;
|
||||
|
||||
} else if (ON_AP_FILTER(request)) {
|
||||
//request->send(200, "text/plain", "Hello from AP");
|
||||
Serial.println("on apfilter /");
|
||||
request->send_P(200, "text/html", wifi_html, processor);
|
||||
return;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
server.on("/wifi", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
|
||||
if (ON_STA_FILTER(request)) {
|
||||
//request->send(200, "text/plain", "Hello from STA");
|
||||
request->send_P(200, "text/html", wifi_html, processor);
|
||||
return;
|
||||
|
||||
} else if (ON_AP_FILTER(request)) {
|
||||
//request->send(200, "text/plain", "Hello from AP");
|
||||
Serial.println("on apfilter /wifi");
|
||||
request->send_P(200, "text/html", wifi_html, processor);
|
||||
return;
|
||||
}
|
||||
|
||||
request->send(200, "text/plain", "Hello from undefined");
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Send a GET request to <ESP_IP>/get?inputString=<inputMessage>
|
||||
server.on("/setwifi", HTTP_POST, [] (AsyncWebServerRequest *request) {
|
||||
String inputMessage;
|
||||
boolean bolrestart=false;
|
||||
Serial.println("ini masuk /setwifi");
|
||||
// GET inputString value on <ESP_IP>/get?inputString=<inputMessage>
|
||||
//List all parameters
|
||||
int params = request->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());
|
||||
}
|
||||
}
|
||||
if (request->hasParam(PARAM_SSID,true)) {
|
||||
Serial.println("hasparam ssid");
|
||||
inputMessage = request->getParam(PARAM_SSID,true)->value(); //add true for POST method. no true for GET method
|
||||
if (inputMessage!=""){
|
||||
writeFile(SPIFFS, "/ssidString.txt", inputMessage.c_str());
|
||||
delay(50);
|
||||
bolrestart=true;
|
||||
//ESP.restart();
|
||||
}
|
||||
}
|
||||
// GET inputPwd value on <ESP_IP>/wifi/get?inputPwd=<inputMessage>
|
||||
if (request->hasParam(PARAM_PWD,true)) { // add true for POST, no true for GET method
|
||||
Serial.println("hasparam pwd");
|
||||
inputMessage = request->getParam(PARAM_PWD,true)->value(); // add true for POST
|
||||
if (inputMessage!=""){
|
||||
writeFile(SPIFFS, "/inputPwd.txt", inputMessage.c_str());
|
||||
delay(50);
|
||||
bolrestart=true;
|
||||
//ESP.restart();
|
||||
}
|
||||
}
|
||||
else {
|
||||
inputMessage = "No message sent";
|
||||
}
|
||||
if (bolrestart) {
|
||||
ESP.restart();
|
||||
}
|
||||
Serial.println("ini /setwifi aja");Serial.println(inputMessage);
|
||||
request->send(200, "text/text", inputMessage);
|
||||
});
|
||||
|
||||
// // Send a GET request to <ESP_IP>/wifi/get?ssidString=<inputMessage>
|
||||
// server.on("/wifi/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
// String inputMessage;
|
||||
// // GET ssidString value on <ESP_IP>/wifi/get?ssidString=<inputMessage>
|
||||
// Serial.println("ini masuk wifi get");
|
||||
// Serial.println(request->params());
|
||||
// if (request->hasParam(PARAM_SSID)) {
|
||||
// inputMessage = request->getParam(PARAM_SSID)->value();
|
||||
// writeFile(SPIFFS, "/ssidString.txt", inputMessage.c_str());
|
||||
// delay(100);
|
||||
// ESP.restart();
|
||||
// }
|
||||
// // GET inputPwd value on <ESP_IP>/wifi/get?inputPwd=<inputMessage>
|
||||
// else if (request->hasParam(PARAM_PWD)) {
|
||||
// inputMessage = request->getParam(PARAM_PWD)->value();
|
||||
// writeFile(SPIFFS, "/inputPwd.txt", inputMessage.c_str());
|
||||
// delay(100);
|
||||
// ESP.restart();
|
||||
// }
|
||||
// else {
|
||||
// inputMessage = "No message sent";
|
||||
// }
|
||||
// Serial.println("/wifi/get value:"); Serial.println(inputMessage);
|
||||
// request->send(200, "text/text", inputMessage);
|
||||
// });
|
||||
|
||||
server.on("/menu", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
//String s = MAIN_page; //Read HTML contents
|
||||
//request->send_P(200, "text/html", s); //Send web page
|
||||
request->send_P(200, "text/html", main_menu);
|
||||
});
|
||||
|
||||
server.on("/startrally", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
//String s = MAIN_page; //Read HTML contents
|
||||
//request->send_P(200, "text/html", s); //Send web page
|
||||
String PAGE;
|
||||
PAGE += FPSTR(HTML_PAGEHEADER);
|
||||
PAGE.replace("%serveripaddress%", WiFi.localIP().toString());
|
||||
PAGE += FPSTR(HTML_DIVSTARTRALLY);
|
||||
//PAGE += FPSTR(HTML_SCRIPTSETINTERVAL);
|
||||
//PAGE += FPSTR(HTML_SCRIPTGETDATA);
|
||||
PAGE += FPSTR(HTML_END);
|
||||
//Serial.println(PAGE);
|
||||
request->send(200, "text/html", PAGE);
|
||||
});
|
||||
|
||||
server.on("/startrally1", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
request->send_P(200, "text/html", HTML_startrally1, processor);
|
||||
});
|
||||
|
||||
server.on("/resetodo1", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
Serial.println("ODORESET 1");
|
||||
request->redirect("/startrally1");
|
||||
});
|
||||
|
||||
server.on("/resetodo2", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
Serial.println("ODORESET 22222");
|
||||
request->redirect("/startrally1");
|
||||
});
|
||||
|
||||
server.on("/copytoodo2", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
Serial.println("COPY ODO 1 to 2");
|
||||
request->redirect("/startrally1");
|
||||
});
|
||||
|
||||
server.on("/copytoodo1", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
Serial.println("COPY ODO 2 to 1");
|
||||
request->redirect("/startrally1");
|
||||
});
|
||||
server.on("/DIR", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
String inputMessage;
|
||||
String inputParam;
|
||||
if (request->hasParam("DIR1")){
|
||||
inputMessage=request->getParam("DIR1")->value();
|
||||
Serial.print("DIR 1->");Serial.println(inputMessage);
|
||||
switch(inputMessage[0]){
|
||||
case 'F':
|
||||
Serial.println("FW1");
|
||||
break;
|
||||
case 'S':
|
||||
Serial.println("ST1");
|
||||
break;
|
||||
case 'B':
|
||||
Serial.println("BACK1");
|
||||
break;
|
||||
default:
|
||||
Serial.println("Default VAL1");
|
||||
}
|
||||
}
|
||||
else if (request->hasParam("DIR2")){
|
||||
inputMessage=request->getParam("DIR2")->value();
|
||||
Serial.print("DIR 2->");Serial.println(inputMessage);
|
||||
switch(inputMessage[0]){
|
||||
case 'F':
|
||||
Serial.println("FW2");
|
||||
break;
|
||||
case 'S':
|
||||
Serial.println("ST2");
|
||||
break;
|
||||
case 'B':
|
||||
Serial.println("BACK2");
|
||||
break;
|
||||
default:
|
||||
Serial.println("Default VAL2");
|
||||
}
|
||||
}
|
||||
request->redirect("/startrally1");
|
||||
});
|
||||
|
||||
|
||||
server.on("/TG1", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
Serial.println("TOGGLE 1");
|
||||
request->redirect("/startrally1");
|
||||
});
|
||||
|
||||
server.on("/TG2", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
Serial.println("TOGGLE 2");
|
||||
request->redirect("/startrally1");
|
||||
});
|
||||
// //server.on("/adc", HTTP_GET); //This is display page
|
||||
// server.on("/readADC", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
// // int a = analogRead(A0);
|
||||
// // String adcValue = String(millis());
|
||||
// String adcValue = getPin();
|
||||
// Serial.println(adcValue);
|
||||
// request->send_P(200, "text/plain", adcValue.c_str()); //Send ADC value only to client ajax request
|
||||
// });
|
||||
|
||||
server.on("/calibration", HTTP_GET, [] (AsyncWebServerRequest *request) {
|
||||
//PAGE.replace("%serveripaddress%", WiFi.localIP().toString());
|
||||
request->send_P(200, "text/html", HTML_CALIBRATION, processor);
|
||||
});
|
||||
|
||||
ws.onEvent(onWsEvent); //add ws event
|
||||
wscal.onEvent(onWsEvent2); //add ws event
|
||||
server.addHandler(&ws);
|
||||
server.addHandler(&wscal);
|
||||
|
||||
server.onNotFound(notFound);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// // To access your stored values on inputString, inputInt, inputFloat
|
||||
// String yourInputString = readFile(SPIFFS, "/inputString.txt");
|
||||
// Serial.print("*** Your inputString: ");
|
||||
// Serial.println(yourInputString);
|
||||
|
||||
// int yourInputInt = readFile(SPIFFS, "/inputInt.txt").toInt();
|
||||
// Serial.print("*** Your inputInt: ");
|
||||
// Serial.println(yourInputInt);
|
||||
|
||||
// float yourInputFloat = readFile(SPIFFS, "/inputFloat.txt").toFloat();
|
||||
// Serial.print("*** Your inputFloat: ");
|
||||
// Serial.println(yourInputFloat);
|
||||
|
||||
// String yourSSIDString = readFile(SPIFFS, "/ssidString.txt");
|
||||
// Serial.print("*** Your ssidString: ");
|
||||
// Serial.println(yourSSIDString);
|
||||
|
||||
// String yourInputPwd = readFile(SPIFFS, "/inputPwd.txt");
|
||||
// Serial.print("*** Your inputPwd: ");
|
||||
// Serial.println(yourInputPwd);
|
||||
// delay(10000);
|
||||
delay(10330);
|
||||
ws.textAll(getPin());
|
||||
wscal.textAll(getCalib());
|
||||
//printLocalTime();
|
||||
}
|
||||
|
||||
2844
backup/backup_main_before cleaning lcd and at24cx
Normal file
2844
backup/backup_main_before cleaning lcd and at24cx
Normal file
File diff suppressed because it is too large
Load Diff
2844
backup/backup_main_before tryingVSSRALLYv2only.cpp
Normal file
2844
backup/backup_main_before tryingVSSRALLYv2only.cpp
Normal file
File diff suppressed because it is too large
Load Diff
302
backup/startrally1.html
Normal file
302
backup/startrally1.html
Normal file
@ -0,0 +1,302 @@
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1</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">
|
||||
<script type = "text/javascript">
|
||||
var ping;
|
||||
const ws = new WebSocket("ws://%serveripaddress%/ws");
|
||||
ws.onopen = function() {
|
||||
console.log("WebSocket Connected");
|
||||
if(document.getElementById("mainTime").classList.contains("bg-danger")){
|
||||
document.getElementById("mainTime").classList.remove("bg-danger")
|
||||
}
|
||||
ping = 1;
|
||||
};
|
||||
ws.onclose = function() {
|
||||
// alert("WS Connection Closed");
|
||||
console.log("WS Connection Closed");
|
||||
if(!document.getElementById("mainTime").classList.contains("bg-danger")){
|
||||
document.getElementById("mainTime").classList.add("bg-danger")
|
||||
}
|
||||
ping = -1;
|
||||
};
|
||||
ws.onmessage = function(event) {
|
||||
// console.log(event.data);
|
||||
let data = JSON.parse(event.data);
|
||||
// if (data.hasOwnProperty("ping")) {
|
||||
// console.log("with ping key");
|
||||
// ping++;
|
||||
// } else{
|
||||
let curTrack=document.getElementById("currenttrack").innerHTML;
|
||||
let tripSpeed=document.getElementById("tripspeed").innerHTML;
|
||||
let tripDist=document.getElementById("tripdist").innerHTML;
|
||||
let tripTime=document.getElementById("triptime").innerHTML;
|
||||
let tripsTime=document.getElementById("tripstime").innerHTML;
|
||||
if(curTrack==data.Trip){
|
||||
if(tripSpeed!=data.TSpeed || tripDist != data.TDist || tripTime!=data.TTime ||tripsTime!=data.TsTime){
|
||||
console.log("Refresh Trip "+data.Trip);
|
||||
changeTrip(data.Trip);
|
||||
}
|
||||
}
|
||||
ping++;
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("currenttime").innerHTML = data.Time;
|
||||
document.getElementById("currenttrack").innerHTML = data.Trip;
|
||||
document.getElementById("tripspeed").innerHTML = data.TSpeed;
|
||||
document.getElementById("tripdist").innerHTML = data.TDist;
|
||||
document.getElementById("triptime").innerHTML = data.TTime;
|
||||
document.getElementById("tripstime").innerHTML = data.TsTime;
|
||||
document.getElementById("currentspeed").innerHTML = data.curSpeed;
|
||||
document.getElementById("dir1").innerHTML = data.dir1;
|
||||
document.getElementById("dir2").innerHTML = data.dir2;
|
||||
document.getElementById("odo1").innerHTML = data.curDist1;
|
||||
document.getElementById("odo2").innerHTML = data.curDist2;
|
||||
document.getElementById("time1").innerHTML = data.time1;
|
||||
document.getElementById("time2").innerHTML = data.time2;
|
||||
// }
|
||||
};
|
||||
|
||||
setInterval(checkPing, 1000); //heartbeat
|
||||
function checkPing(){
|
||||
// console.log("ping="+ping);
|
||||
ping--;
|
||||
if (ping>=0){
|
||||
ping=0;
|
||||
} else if (ping<=-20){
|
||||
ping = -19;
|
||||
} else if (ping<-3){ // 3secs ping timeout
|
||||
if(!document.getElementById("mainTime").classList.contains("bg-danger")){
|
||||
document.getElementById("mainTime").classList.add("bg-danger")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</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>
|
||||
<div class=" bg-success text-white">
|
||||
<div class="row">
|
||||
<div class="col-2 mt-1"><h6><span id="counter">12345</span></h6></div>
|
||||
<div id="mainTime" class="col mt-1 bg-danger"><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="currentspeed">123.4</span>Km/h</h2></div>
|
||||
<div class="col-2"><button ondblclick="location.href='/menu';" class="btn btn-secondary fw-bold btn-sm mt-2 mb-2">To Menu</button></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-1">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
TRIP <span id="currenttrack">A</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
|
||||
<li><a class="dropdown-item" onclick="changeTrip('A');">TRIP A</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('B');">TRIP B</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('C');">TRIP C</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('D');">TRIP D</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('E');">TRIP E</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('F');">TRIP F</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('G');">TRIP G</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('H');">TRIP H</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('I');">TRIP I</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('J');">TRIP J</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('K');">TRIP K</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('L');">TRIP L</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('M');">TRIP M</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('N');">TRIP N</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('O');">TRIP O</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('P');">TRIP P</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col mt-1 text-center"><h5>S:<span id="tripdist">123.45</span>Km | V:<span id="tripspeed">123.4</span>Km/h | T: <span id="triptime">123</span>Min</h5></div>
|
||||
<!--
|
||||
<div class="col-3 mt-1 text-center"><h5>Speed: <span id="tripspeed">123.4</span>Km/h</h5></div>
|
||||
<div class="col-2 mt-1 text-center"><h5>Time: <span id="triptime">123</span>Min</h5></div>
|
||||
-->
|
||||
<div class="col-3 mt-1 text-center"><h5>sTime: <span id="tripstime">12:34:50</span></h5></div>
|
||||
|
||||
<hr>
|
||||
</div>
|
||||
<!--//ODO1-->
|
||||
<div class="row">
|
||||
<div class="col-2"><h4>OD 1-></h4></div>
|
||||
<div class="col-3 text-end"><h3><span id="odo1">123.4567</span> km</h3></div>
|
||||
<div class="col-4"><h3><span id="dir1">DIRECT</span></h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time1">00:00:00</span></h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5 "><h4>
|
||||
<button ondblclick="resetodo1()" type="button" class="btn btn-primary btn-sm mb-2">Reset ODO1</button>
|
||||
<button ondblclick="copytoodo2()" type="button" class="btn btn-primary btn-sm mb-2">↓ to ODO2</button></h4>
|
||||
</div>
|
||||
<div class="col-4"><h4>
|
||||
<button ondblclick="dirFW1()" type="button" class="btn btn-primary btn-sm mb-2">FW</button>
|
||||
<button ondblclick="dirStop1()" type="button" class="btn btn-primary btn-sm mb-2">STOP</button>
|
||||
<button ondblclick="dirBack1()" type="button" class="btn btn-primary btn-sm mb-2">BACK</button></h4>
|
||||
</div>
|
||||
<div class="col"><h4>
|
||||
<div class="d-grid gap-0 d-md-flex justify-content-md-end">
|
||||
<button onclick="toggleTime1()" class="btn btn-primary btn-sm me-md-4" type="button">Toggle</button>
|
||||
</div></h4>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<!--//ODO2-->
|
||||
<div class="row">
|
||||
<div class="col-5 "><h3>OD 2-><span id="odo2">123.456</span> km</h3></div>
|
||||
<div class="col-4 "><h3><span id="dir2">DIRECT</span></h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time2">00:00:00</span></h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5"><h5>
|
||||
<button ondblclick="resetodo2()" type="button" class="btn btn-primary btn-sm mb-1">Reset ODO2</button>
|
||||
<button ondblclick="copytoodo1()" type="button" class="btn btn-primary btn-sm mb-1 arrow-up down-arrow">↑ to ODO1</button></h5>
|
||||
</div>
|
||||
<div class="col-4"><h5>
|
||||
<button ondblclick="dirFW2()" class="btn btn-primary btn-sm mb-1" type="button">FW</button>
|
||||
<button ondblclick="dirStop2()" class="btn btn-primary btn-sm mb-1" type="button">STOP</button>
|
||||
<button ondblclick="dirBack2()" class="btn btn-primary btn-sm mb-1" type="button">BACK</button></h5>
|
||||
</div>
|
||||
<div class="col"><h2>
|
||||
<div class="d-grid gap-0 d-md-flex justify-content-md-end">
|
||||
<button onclick="toggleTime2()" class="btn btn-primary btn-sm me-md-4" type="button">Toggle</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button ondblclick="location.href='/menu';" class="btn btn-secondary fw-bold btn-sm mt-2 mb-2">Back to Menu</button>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Are you Sure <span class="func">Reset</span> ODO <span id="p1" class="odonum">1</span> ?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button id="btnyesreset" type="button" data-bs-dismiss="modal" class="btn btn-primary">Yes, <span class="func">Reset</span> ODO <span class="odonum"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function resetodo1(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "resetODO1()" );
|
||||
document.getElementById("p1").innerHTML = "1";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "1";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "RESET";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function resetodo2(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "resetODO2()" );
|
||||
document.getElementById("p1").innerHTML = "2";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "2";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "RESET";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function copytoodo2(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "copytoODO2()" );
|
||||
document.getElementById("p1").innerHTML = "2";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "2";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "Copy ODO 1 to";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function copytoodo1(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "copytoODO1()" );
|
||||
document.getElementById("p1").innerHTML = "1";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "1";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "Copy ODO 2 to";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function resetODO1(){
|
||||
ws.send('{"resetodo":1}');
|
||||
console.log("resetodo->1");
|
||||
}
|
||||
function resetODO2(){
|
||||
ws.send('{"resetodo":2}');
|
||||
console.log("resetodo->2");
|
||||
}
|
||||
function copytoODO2(){
|
||||
ws.send('{"copytoodo":2}');
|
||||
console.log("copytoodo->2");
|
||||
}
|
||||
function copytoODO1(){
|
||||
ws.send('{"copytoodo":1}');
|
||||
console.log("copytoodo->1");
|
||||
}
|
||||
function dirFW1(){
|
||||
ws.send('{"dir1":0}');
|
||||
console.log("dir1->0");
|
||||
}
|
||||
function dirStop1(){
|
||||
ws.send('{"dir1":1}');
|
||||
console.log("dir1->1");
|
||||
}
|
||||
function dirBack1(){
|
||||
ws.send('{"dir1":2}');
|
||||
console.log("dir1->2");
|
||||
}
|
||||
function dirFW2(){
|
||||
ws.send('{"dir2":0}');
|
||||
console.log("dir2->0");
|
||||
}
|
||||
function dirStop2(){
|
||||
ws.send('{"dir2":1}');
|
||||
console.log("dir2->1");
|
||||
}
|
||||
function dirBack2(){
|
||||
ws.send('{"dir2":2}');
|
||||
console.log("dir2->2");
|
||||
}
|
||||
function toggleTime1(){
|
||||
ws.send('{"toggle":1}');
|
||||
console.log("toggle->1");
|
||||
}
|
||||
function toggleTime2(){
|
||||
ws.send('{"toggle":2}');
|
||||
console.log("toggle->2");
|
||||
}
|
||||
function changeTrip(cTrip){
|
||||
// alert("Change to TRIP "+cTrip);
|
||||
ws.send('{"ctotrip":"'+cTrip+'"}');
|
||||
console.log("ctotrip->"+cTrip);
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
177
data/constanta.html
Normal file
177
data/constanta.html
Normal file
@ -0,0 +1,177 @@
|
||||
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1 Constanta</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">
|
||||
<script type = "text/javascript">
|
||||
const ws = new WebSocket("ws://%serveripaddress%/wscal");
|
||||
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);
|
||||
const elemen = document.getElementsByClassName(data.trip)[0];
|
||||
console.log(elemen);
|
||||
element.getElementsByClassName("speed")[0].value = data.speed;
|
||||
element.getElementsByClassName("dist")[0].value = data.dist;
|
||||
element.getElementsByClassName("time")[0].value = data.time;
|
||||
element.getElementsByClassName("stime")[0].value = data.stime;
|
||||
document.getElementById("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("speed").innerHTML = data.curTripSpeed;
|
||||
};
|
||||
</script>
|
||||
<script>
|
||||
function onlyNumberKey(evt,e) {
|
||||
// Only ASCII character in that range allowed
|
||||
var ASCIICode = (evt.which) ? evt.which : evt.keyCode
|
||||
if (ASCIICode > 31 && (ASCIICode < 48 || ASCIICode > 57) && ASCIICode !=46)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
function chback(e){ //change background to yellow
|
||||
e.style.backgroundColor = "yellow";
|
||||
}
|
||||
</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>
|
||||
<div class=" bg-success 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>
|
||||
<!--//Constanta Menu-->
|
||||
|
||||
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-1"></div>
|
||||
<div class="col-1 text-center "><label class="col-form-label fs-6 fw-bold">Speed</label></div>
|
||||
<div class="col-1"></div>
|
||||
<div class="col-1 text-center "><label class="col-form-label fs-6 fw-bold">Distance(Km)</label></div>
|
||||
<div class="col-1"></div>
|
||||
<div class="col-1 text-center "><label class="col-form-label fs-6 fw-bold">Time(min)</label></div>
|
||||
<div class="col-1"></div>
|
||||
<div class="col-2 text-center "><label class="col-form-label fs-6 fw-bold">Start Time</label></div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row g-2 align-items-center" id="tripA">
|
||||
<div class="col-1 "><label for="speedA" class="col-form-label fs-4 ms-2 trip">A-></label></div>
|
||||
<div class="col-2 ">
|
||||
<input type="text" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="speedA" name="speedA" class="form-control speed" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
<div class="col-2">
|
||||
<input type="text" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="distA" name="distA" class="form-control dist" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
<div class="col-2">
|
||||
<input type="text" maxlength="5" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="timeA" name="timeA" class="form-control time" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
<div class="col-2">
|
||||
<input type="time" id="stimeA" name="stimeA" class="form-control stime" onchange="chback(this)" required></div>
|
||||
<div class="col-auto">
|
||||
<button class="btn btn-primary fw-bold" id="myBtn" onclick="setConstanta(this)">SET A</button></div>
|
||||
</div>
|
||||
<div class="row g-2 align-items-center" id="tripB">
|
||||
<div class="col-1 "><label for="speedB" class="col-form-label fs-4 trip">B-></label></div>
|
||||
<div class="col-2 ">
|
||||
<input type="text" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="SpeedB" name="speedB" class="form-control speed" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
<div class="col-2">
|
||||
<input type="text" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="distB" name="distB" class="form-control dist" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
<div class="col-2">
|
||||
<input type="text" maxlength="5" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="timeB" name="timeB" class="form-control time" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></div>
|
||||
<div class="col-2">
|
||||
<input type="time" id="stimeB" name="stimeB" class="form-control stime" onchange="chback(this)"></div>
|
||||
<div class="col-auto">
|
||||
<button class="btn btn-primary fw-bold" id="myBtn" onclick="setConstanta(this)">SET B</button></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 setConstanta(e){
|
||||
e = e || window.event;
|
||||
var targ1 = e.target || e.srcElement || e;
|
||||
if (targ1.nodeType == 3) targ1 = targ1.parentNode; // defeat Safari bug
|
||||
const targ = targ1.closest(".row");
|
||||
const trip = targ.getElementsByClassName("trip")[0].textContent.split("-")[0];
|
||||
const speed = targ.getElementsByClassName("speed")[0].value;
|
||||
if (speed===""){
|
||||
alert ("Trip "+trip+"-> [Speed] is required");
|
||||
return;
|
||||
}
|
||||
const stime = targ.getElementsByClassName("stime")[0].value;
|
||||
if (stime===""){
|
||||
alert ("Trip "+trip+"-> [Start Time] is required");
|
||||
return;
|
||||
}
|
||||
// targ.getElementsByClassName("speed")[0].value = "345" //trial change backColor
|
||||
// targ.getElementsByClassName("speed")[0].style.backgroundColor = "white"
|
||||
var dist = targ.getElementsByClassName("dist")[0].value;
|
||||
const time = targ.getElementsByClassName("time")[0].value;
|
||||
|
||||
var full_data='{"trip":"'+trip+'", "speed":"'+speed+'", "dist":"'+dist+'", "time":"'+time+'", "stime":"'+stime+'"}';
|
||||
console.log(full_data);
|
||||
sendjson(full_data);
|
||||
};
|
||||
|
||||
function compare(name){
|
||||
let name1=name || "";
|
||||
console.log(name, name1)
|
||||
return name1;
|
||||
};
|
||||
|
||||
function sendjson(data){
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "/rest/endpoint";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
console.log(xhr.responseText);
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
console.log(json.trip + ", " + json.speed + ", " + json.dist + ", " + json.time + ", " + json.stime);
|
||||
if (json.ok) {
|
||||
var tripID = document.getElementById("trip"+json.trip);
|
||||
const speed = tripID.getElementsByClassName("speed"+json.trip);
|
||||
const dist = tripID.getElementsByClassName("dist"+json.trip);
|
||||
const time = tripID.getElementsByClassName("time"+json.trip);
|
||||
const stime = tripID.getElementsByClassName("stime"+json.trip);
|
||||
speed.value = json.speed;
|
||||
dist.value = json.dist;
|
||||
time.value = json.time;
|
||||
stime.value = json.stime;
|
||||
speed.style.backgroundColor = "green"
|
||||
dist.style.backgroundColor = "green"
|
||||
time.style.backgroundColor = "green"
|
||||
stime.style.backgroundColor = "green"
|
||||
console.log("result:"+json.trip + ", " + speed.value + ", " + dist.value + ", " + time.value + ", " + stime.value);
|
||||
}
|
||||
|
||||
console.log(json);
|
||||
}
|
||||
};
|
||||
console.log(data);
|
||||
var datajson = JSON.stringify(data);
|
||||
console.log(datajson);
|
||||
xhr.send(data);
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
|
||||
|
||||
1
data/inputPwd.txt
Normal file
1
data/inputPwd.txt
Normal file
@ -0,0 +1 @@
|
||||
1234567890
|
||||
1
data/ssidString.txt
Normal file
1
data/ssidString.txt
Normal file
@ -0,0 +1 @@
|
||||
WiFi_SuGi
|
||||
1
data/text.txt
Normal file
1
data/text.txt
Normal file
@ -0,0 +1 @@
|
||||
Hello world from data
|
||||
0
data/tripA
Normal file
0
data/tripA
Normal file
0
data/tripB
Normal file
0
data/tripB
Normal file
0
data/tripC
Normal file
0
data/tripC
Normal file
0
data/tripD
Normal file
0
data/tripD
Normal file
0
data/tripE
Normal file
0
data/tripE
Normal file
0
data/tripF
Normal file
0
data/tripF
Normal file
0
data/tripG
Normal file
0
data/tripG
Normal file
0
data/tripH
Normal file
0
data/tripH
Normal file
0
data/tripI
Normal file
0
data/tripI
Normal file
0
data/tripJ
Normal file
0
data/tripJ
Normal file
0
data/tripK
Normal file
0
data/tripK
Normal file
0
data/tripL
Normal file
0
data/tripL
Normal file
0
data/tripM
Normal file
0
data/tripM
Normal file
0
data/tripN
Normal file
0
data/tripN
Normal file
0
data/tripO
Normal file
0
data/tripO
Normal file
0
data/tripP
Normal file
0
data/tripP
Normal file
39
include/README
Normal file
39
include/README
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
46
lib/README
Normal file
46
lib/README
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||
34
platformio.ini
Normal file
34
platformio.ini
Normal file
@ -0,0 +1,34 @@
|
||||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:lolin32_lite]
|
||||
platform = espressif32
|
||||
board = lolin32_lite
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
ottowinter/ESPAsyncWebServer-esphome@^2.1.0
|
||||
esphome/AsyncTCP-esphome@^1.2.2
|
||||
SPIFFS
|
||||
bblanchon/ArduinoJson@^6.19.4
|
||||
khoih-prog/ESPAsync_WiFiManager@^1.12.2
|
||||
rodan/ds3231@^1.0
|
||||
;fmalpartida/LiquidCrystal@^1.5.0
|
||||
https://github.com/cyberp/AT24Cx.git
|
||||
https://github.com/JChristensen/JC_Button.git
|
||||
Wire
|
||||
;arduino-libraries/LiquidCrystal@^1.0.7
|
||||
https://github.com/fdebrabander/Arduino-LiquidCrystal-I2C-library.git
|
||||
|
||||
[env:env1]
|
||||
lib_deps =
|
||||
khoih-prog/ESPAsync_WiFiManager@^1.12.2
|
||||
rodan/ds3231@^1.0
|
||||
arduino-libraries/LiquidCrystal@^1.0.7
|
||||
194
src/constanta.h
Normal file
194
src/constanta.h
Normal file
@ -0,0 +1,194 @@
|
||||
const char HTML_CONSTHEADER[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1 Constanta</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">
|
||||
<script>
|
||||
function onlyNumberKey(evt,e) {
|
||||
// Only ASCII character in that range allowed
|
||||
var ASCIICode = (evt.which) ? evt.which : evt.keyCode
|
||||
if (ASCIICode > 31 && (ASCIICode < 48 || ASCIICode > 57) && ASCIICode !=46)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
function chback(e){ //change background to yellow
|
||||
e.style.backgroundColor = "yellow";
|
||||
}
|
||||
</script>
|
||||
</head><body onload="loaded();">
|
||||
<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>
|
||||
<div class="bg-info 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>
|
||||
<!--//Constanta Menu-->
|
||||
|
||||
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-1"></div>
|
||||
<div class="col-1 text-center "><label class="col-form-label fs-6 fw-bold">Speed</label></div>
|
||||
<div class="col-1"></div>
|
||||
<div class="col-1 text-center "><label class="col-form-label fs-6 fw-bold">Distance(Km)</label></div>
|
||||
<div class="col-1"></div>
|
||||
<div class="col-1 text-center "><label class="col-form-label fs-6 fw-bold">Time(min)</label></div>
|
||||
<div class="col-1"></div>
|
||||
<div class="col-2 text-center "><label class="col-form-label fs-6 fw-bold">Start Time</label></div>
|
||||
</div>
|
||||
)rawliteral";
|
||||
|
||||
const char HTML_CONSTROW[] PROGMEM = R"rawliteral(
|
||||
<div class="row g-2 align-items-center" id="trip%A%">
|
||||
<div class="col-1 "><label for="%speed%" 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="%speed%" name="%speed%" class="form-control speed" onkeypress="return onlyNumberKey(event,this)" onchange="chback(this)"></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>
|
||||
<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>
|
||||
<div class="col-2">
|
||||
<input type="time" id="%stime%" name="%stime%" class="form-control stime" onchange="chback(this)"></div>
|
||||
<div class="col-2">
|
||||
<button class="btn btn-primary fw-bold" id="myBtn" onclick="setConstanta(this)">SET %A%</button></div>
|
||||
</div>
|
||||
)rawliteral";
|
||||
|
||||
const char HTML_CONSTEND[] PROGMEM = R"rawliteral(
|
||||
<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>
|
||||
// document.addEventListener("DOMContentLoaded", function() {
|
||||
function loaded(){
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "/rest/loadconst";
|
||||
console.log("before open");
|
||||
// for (var i=65; i<81; i++){
|
||||
xhr.open("POST", url, true);
|
||||
console.log("before setrequest");
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
console.log(xhr.responseText);
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var jsonAllTrip = JSON.parse(xhr.responseText);
|
||||
const jsonlen = Object.keys(jsonAllTrip.alltrip).length;
|
||||
console.log(jsonAllTrip.alltrip[0]);
|
||||
console.log("jsondlen="+jsonlen);
|
||||
var jsontemp;
|
||||
for (var i=0; i<jsonlen; i++){
|
||||
jsontemp = jsonAllTrip.alltrip[i];
|
||||
console.log(jsontemp);
|
||||
var json = JSON.parse(JSON.stringify(jsontemp));
|
||||
console.log(json);
|
||||
|
||||
// if (json.ok) {
|
||||
parsingjson(json);
|
||||
}
|
||||
//console.log(json.trip + ", " + json.speed + ", " + json.dist + ", " + json.time + ", " + json.stime);
|
||||
console.log(json);
|
||||
}
|
||||
};
|
||||
let data = '{"req":"B"}'
|
||||
console.log(data);
|
||||
var datajson = JSON.stringify(data);
|
||||
console.log(datajson);
|
||||
|
||||
// console.log(String.fromCharCode(i));
|
||||
// data = '{"req":"'+String.fromCharCode(i)+'"}'
|
||||
xhr.send(data);
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
function setConstanta(e){
|
||||
e = e || window.event;
|
||||
var targ1 = e.target || e.srcElement || e;
|
||||
if (targ1.nodeType == 3) targ1 = targ1.parentNode; // defeat Safari bug
|
||||
const targ = targ1.closest(".row");
|
||||
const trip = targ.getElementsByClassName("trip")[0].textContent[0];
|
||||
const speed = targ.getElementsByClassName("speed")[0].value;
|
||||
if (speed===""){
|
||||
alert ("Trip "+trip+"-> [Speed] is required");
|
||||
return;
|
||||
}
|
||||
const stime = targ.getElementsByClassName("stime")[0].value;
|
||||
if (stime===""){
|
||||
alert ("Trip "+trip+"-> [Start Time] is required");
|
||||
return;
|
||||
}
|
||||
// targ.getElementsByClassName("speed")[0].value = "345" //trial change backColor
|
||||
// targ.getElementsByClassName("speed")[0].style.backgroundColor = "white"
|
||||
const dist = targ.getElementsByClassName("dist")[0].value;
|
||||
const time = targ.getElementsByClassName("time")[0].value;
|
||||
|
||||
var full_data='{"trip":"'+trip+'", "speed":"'+speed+'", "dist":"'+dist+'", "time":"'+time+'", "stime":"'+stime+'"}';
|
||||
console.log(full_data);
|
||||
sendjson(full_data);
|
||||
};
|
||||
|
||||
function parsingjson(json){
|
||||
console.log(json);
|
||||
var tripID = document.getElementById("trip"+json.trip);
|
||||
console.log(tripID);
|
||||
const speed = tripID.getElementsByClassName("speed")[0];
|
||||
const dist = tripID.getElementsByClassName("dist")[0];
|
||||
const time = tripID.getElementsByClassName("time")[0];
|
||||
const stime = tripID.getElementsByClassName("stime")[0];
|
||||
setValBackColor(speed, json.speed);
|
||||
setValBackColor(dist, json.dist);
|
||||
setValBackColor(time, json.time);
|
||||
setValBackColor(stime, json.stime);
|
||||
// speed.value = json.speed;
|
||||
// dist.value = json.dist;
|
||||
// time.value = json.time;
|
||||
// stime.value = json.stime;
|
||||
// speed.style.backgroundColor = "#94C4E2"// #6495ED
|
||||
// dist.style.backgroundColor = "#94C4E2"
|
||||
// time.style.backgroundColor = "#94C4E2"
|
||||
// stime.style.backgroundColor = "#94C4E2"
|
||||
console.log("result ok:"+json.trip + ", " + speed.value + ", " + dist.value + ", " + time.value + ", " + stime.value);
|
||||
};
|
||||
|
||||
function setValBackColor(elem, jsonval){
|
||||
if (jsonval) {
|
||||
elem.value = jsonval;
|
||||
elem.style.backgroundColor = "#94C4E2";
|
||||
} else {
|
||||
elem.style.backgroundColor = "white";
|
||||
}
|
||||
};
|
||||
|
||||
function sendjson(data){
|
||||
var xhr = new XMLHttpRequest();
|
||||
var url = "/rest/endpoint";
|
||||
xhr.open("POST", url, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/json");
|
||||
xhr.onreadystatechange = function () {
|
||||
console.log(xhr.responseText);
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var json = JSON.parse(xhr.responseText);
|
||||
console.log(json.trip + ", " + json.speed + ", " + json.dist + ", " + json.time + ", " + json.stime);
|
||||
if (json.ok) {
|
||||
parsingjson(json);
|
||||
}
|
||||
//console.log(json.trip + ", " + json.speed + ", " + json.dist + ", " + json.time + ", " + json.stime);
|
||||
console.log(json);
|
||||
}
|
||||
};
|
||||
console.log(data);
|
||||
var datajson = JSON.stringify(data);
|
||||
console.log(datajson);
|
||||
xhr.send(data);
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
|
||||
)rawliteral";
|
||||
406
src/index.h
Normal file
406
src/index.h
Normal file
@ -0,0 +1,406 @@
|
||||
const char HTML_startrally1[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1</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">
|
||||
<script type = "text/javascript">
|
||||
var ping;
|
||||
const ws = new WebSocket("ws://%serveripaddress%/ws");
|
||||
ws.onopen = function() {
|
||||
console.log("WebSocket Connected");
|
||||
if(document.getElementById("mainTime").classList.contains("bg-danger")){
|
||||
document.getElementById("mainTime").classList.remove("bg-danger")
|
||||
}
|
||||
ping = 1;
|
||||
};
|
||||
ws.onclose = function() {
|
||||
// alert("WS Connection Closed");
|
||||
console.log("WS Connection Closed");
|
||||
if(!document.getElementById("mainTime").classList.contains("bg-danger")){
|
||||
document.getElementById("mainTime").classList.add("bg-danger")
|
||||
}
|
||||
ping = -1;
|
||||
};
|
||||
ws.onmessage = function(event) {
|
||||
// console.log(event.data);
|
||||
let data = JSON.parse(event.data);
|
||||
// if (data.hasOwnProperty("ping")) {
|
||||
// console.log("with ping key");
|
||||
// ping++;
|
||||
// } else{
|
||||
let curTrack=document.getElementById("currenttrack").innerHTML;
|
||||
let tripSpeed=document.getElementById("tripspeed").innerHTML;
|
||||
let tripDist=document.getElementById("tripdist").innerHTML;
|
||||
let tripTime=document.getElementById("triptime").innerHTML;
|
||||
let tripsTime=document.getElementById("tripstime").innerHTML;
|
||||
if(curTrack==data.Trip){
|
||||
if(tripSpeed!=data.TSpeed || tripDist != data.TDist || tripTime!=data.TTime ||tripsTime!=data.TsTime){
|
||||
console.log("Refresh Trip "+data.Trip);
|
||||
changeTrip(data.Trip);
|
||||
}
|
||||
}
|
||||
ping++;
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("currenttime").innerHTML = data.Time;
|
||||
document.getElementById("currenttrack").innerHTML = data.Trip;
|
||||
document.getElementById("tripspeed").innerHTML = data.TSpeed;
|
||||
document.getElementById("tripdist").innerHTML = data.TDist;
|
||||
document.getElementById("triptime").innerHTML = data.TTime;
|
||||
document.getElementById("tripstime").innerHTML = data.TsTime;
|
||||
document.getElementById("currentspeed").innerHTML = data.curSpeed;
|
||||
document.getElementById("dir1").innerHTML = data.dir1;
|
||||
document.getElementById("dir2").innerHTML = data.dir2;
|
||||
document.getElementById("odo1").innerHTML = data.curDist1;
|
||||
document.getElementById("odo2").innerHTML = data.curDist2;
|
||||
document.getElementById("time1").innerHTML = data.time1;
|
||||
document.getElementById("time2").innerHTML = data.time2;
|
||||
// }
|
||||
};
|
||||
|
||||
setInterval(checkPing, 1000); //heartbeat
|
||||
function checkPing(){
|
||||
// console.log("ping="+ping);
|
||||
ping--;
|
||||
if (ping>=0){
|
||||
ping=0;
|
||||
} else if (ping<=-20){
|
||||
ping = -19;
|
||||
} else if (ping<-3){ // 3secs ping timeout
|
||||
if(!document.getElementById("mainTime").classList.contains("bg-danger")){
|
||||
document.getElementById("mainTime").classList.add("bg-danger")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
</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>
|
||||
<div class=" bg-success text-white">
|
||||
<div class="row">
|
||||
<div class="col-2 mt-1"><h6><span id="counter">12345</span></h6></div>
|
||||
<div id="mainTime" class="col mt-1 bg-danger"><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="currentspeed">123.4</span>Km/h</h2></div>
|
||||
<div class="col-2"><button ondblclick="location.href='/menu';" class="btn btn-secondary fw-bold btn-sm mt-2 mb-2">To Menu</button></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-2">
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
TRIP <span id="currenttrack">A</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
|
||||
<li><a class="dropdown-item" onclick="changeTrip('A');">TRIP A</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('B');">TRIP B</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('C');">TRIP C</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('D');">TRIP D</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('E');">TRIP E</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('F');">TRIP F</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('G');">TRIP G</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('H');">TRIP H</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('I');">TRIP I</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('J');">TRIP J</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('K');">TRIP K</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('L');">TRIP L</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('M');">TRIP M</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('N');">TRIP N</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('O');">TRIP O</a></li>
|
||||
<li><a class="dropdown-item" onclick="changeTrip('P');">TRIP P</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col mt-1 text-center"><h5>S: <span id="tripdist">123.45</span>Km | V: <span id="tripspeed">123.4</span>Km/h | T: <span id="triptime">123</span>Min</h5></div>
|
||||
<!--
|
||||
<div class="col-3 mt-1 text-center"><h5>S: <span id="tripdist">123.45</span>Km</h5></div>
|
||||
<div class="col-2 mt-1 text-center"><h5>V: <span id="tripspeed">123.4</span>Km/h</h5></div>
|
||||
<div class="col-2 mt-1 text-center"><h5>T: <span id="triptime">123</span>Min</h5></div>
|
||||
-->
|
||||
<div class="col-3 mt-1 text-center"><h5>ST: <span id="tripstime">12:34:50</span></h5></div>
|
||||
<hr>
|
||||
</div>
|
||||
<!--//ODO1-->
|
||||
<div class="row">
|
||||
<div class="col-2"><h4>OD 1-></h4></div>
|
||||
<div class="col-3 text-end"><h3><span id="odo1">123.4567</span> km</h3></div>
|
||||
<div class="col-4"><h3><span id="dir1">DIRECT</span></h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time1">00:00:00</span></h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5 "><h4>
|
||||
<button ondblclick="resetodo1()" type="button" class="btn btn-primary btn-sm mb-2">Reset ODO1</button>
|
||||
<button ondblclick="copytoodo2()" type="button" class="btn btn-primary btn-sm mb-2">↓ to ODO2</button></h4>
|
||||
</div>
|
||||
<div class="col-4"><h4>
|
||||
<button ondblclick="dirFW1()" type="button" class="btn btn-primary btn-sm mb-2">FW</button>
|
||||
<button ondblclick="dirStop1()" type="button" class="btn btn-primary btn-sm mb-2">STOP</button>
|
||||
<button ondblclick="dirBack1()" type="button" class="btn btn-primary btn-sm mb-2">BACK</button></h4>
|
||||
</div>
|
||||
<div class="col"><h4>
|
||||
<div class="d-grid gap-0 d-md-flex justify-content-md-end">
|
||||
<button onclick="toggleTime1()" class="btn btn-primary btn-sm me-md-4" type="button">Toggle</button>
|
||||
</div></h4>
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
<hr>
|
||||
-->
|
||||
<!--//ODO2-->
|
||||
<div class="row">
|
||||
<div class="col-5 "><h3>OD 2-><span id="odo2">123.456</span> km</h3></div>
|
||||
<div class="col-4 "><h3><span id="dir2">DIRECT</span></h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time2">00:00:00</span></h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5"><h5>
|
||||
<button ondblclick="resetodo2()" type="button" class="btn btn-primary btn-sm mb-1">Reset ODO2</button>
|
||||
<button ondblclick="copytoodo1()" type="button" class="btn btn-primary btn-sm mb-1 arrow-up down-arrow">↑ to ODO1</button></h5>
|
||||
</div>
|
||||
<div class="col-4"><h5>
|
||||
<button ondblclick="dirFW2()" class="btn btn-primary btn-sm mb-1" type="button">FW</button>
|
||||
<button ondblclick="dirStop2()" class="btn btn-primary btn-sm mb-1" type="button">STOP</button>
|
||||
<button ondblclick="dirBack2()" class="btn btn-primary btn-sm mb-1" type="button">BACK</button></h5>
|
||||
</div>
|
||||
<div class="col"><h2>
|
||||
<div class="d-grid gap-0 d-md-flex justify-content-md-end">
|
||||
<button onclick="toggleTime2()" class="btn btn-primary btn-sm me-md-4" type="button">Toggle</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Are you Sure <span class="func">Reset</span> ODO <span id="p1" class="odonum">1</span> ?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button id="btnyesreset" type="button" data-bs-dismiss="modal" class="btn btn-primary">Yes, <span class="func">Reset</span> ODO <span class="odonum"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function resetodo1(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "resetODO1()" );
|
||||
document.getElementById("p1").innerHTML = "1";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "1";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "RESET";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function resetodo2(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "resetODO2()" );
|
||||
document.getElementById("p1").innerHTML = "2";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "2";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "RESET";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function copytoodo2(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "copytoODO2()" );
|
||||
document.getElementById("p1").innerHTML = "2";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "2";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "Copy ODO 1 to";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
function copytoodo1(){
|
||||
document.getElementById("btnyesreset").setAttribute( "onClick", "copytoODO1()" );
|
||||
document.getElementById("p1").innerHTML = "1";
|
||||
elements = document.getElementsByClassName("odonum");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "1";
|
||||
}
|
||||
elements = document.getElementsByClassName("func");
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
elements[i].innerHTML = "Copy ODO 2 to";
|
||||
}
|
||||
var myModal = new bootstrap.Modal(document.getElementById("exampleModal"), {});
|
||||
myModal.show();
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function resetODO1(){
|
||||
ws.send('{"resetodo":1}');
|
||||
console.log("resetodo->1");
|
||||
}
|
||||
function resetODO2(){
|
||||
ws.send('{"resetodo":2}');
|
||||
console.log("resetodo->2");
|
||||
}
|
||||
function copytoODO2(){
|
||||
ws.send('{"copytoodo":2}');
|
||||
console.log("copytoodo->2");
|
||||
}
|
||||
function copytoODO1(){
|
||||
ws.send('{"copytoodo":1}');
|
||||
console.log("copytoodo->1");
|
||||
}
|
||||
function dirFW1(){
|
||||
ws.send('{"dir1":0}');
|
||||
console.log("dir1->0");
|
||||
}
|
||||
function dirStop1(){
|
||||
ws.send('{"dir1":1}');
|
||||
console.log("dir1->1");
|
||||
}
|
||||
function dirBack1(){
|
||||
ws.send('{"dir1":2}');
|
||||
console.log("dir1->2");
|
||||
}
|
||||
function dirFW2(){
|
||||
ws.send('{"dir2":0}');
|
||||
console.log("dir2->0");
|
||||
}
|
||||
function dirStop2(){
|
||||
ws.send('{"dir2":1}');
|
||||
console.log("dir2->1");
|
||||
}
|
||||
function dirBack2(){
|
||||
ws.send('{"dir2":2}');
|
||||
console.log("dir2->2");
|
||||
}
|
||||
function toggleTime1(){
|
||||
ws.send('{"toggle":1}');
|
||||
console.log("toggle->1");
|
||||
}
|
||||
function toggleTime2(){
|
||||
ws.send('{"toggle":2}');
|
||||
console.log("toggle->2");
|
||||
}
|
||||
function changeTrip(cTrip){
|
||||
// alert("Change to TRIP "+cTrip);
|
||||
ws.send('{"ctotrip":"'+cTrip+'"}');
|
||||
console.log("ctotrip->"+cTrip);
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
)rawliteral";
|
||||
|
||||
//HTML_CALIBRATION
|
||||
|
||||
|
||||
|
||||
const char HTML_CALIBRATION[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1 Calibration</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">
|
||||
<script type = "text/javascript">
|
||||
const ws = new WebSocket("ws://%serveripaddress%/wscal");
|
||||
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("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("speed").innerHTML = data.curTripSpeed;
|
||||
document.getElementById("caldist").innerHTML = data.caldist;
|
||||
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>
|
||||
<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 Distance (<span id="caldist">9</span> Km)-></h3></div>
|
||||
<div class="col text-start"><h3>
|
||||
|
||||
<input type="number" step="any" maxlength="2" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
id="setdistance" name="setdistance" size="4">
|
||||
<button class="btn btn-primary mb-2 fw-bold" onclick="setDistance()">SET</button>
|
||||
</h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-end"><h3>Set Calibration Manually (<span id="calman">110000</span>)-></h3></div>
|
||||
<div class="col text-start"><h3>
|
||||
|
||||
<input type="number" step="any" maxlength="6" required oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);"
|
||||
size="3" id="setcalibration" name="setcalibration">
|
||||
<button class="btn btn-primary mb-2 fw-bold" onclick="setCalibration()">SET</button>
|
||||
</h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-end"><h4>
|
||||
<button ondblclick="startCalibration()" type="button" class="btn btn-primary mb-2 me-md-4">Start Calibration</button>
|
||||
<button ondblclick="stopCalibration()" type="button" class="btn btn-primary mb-2 me-md-4">Stop Calibration</button></h4>
|
||||
</div>
|
||||
<div class="col"><h3>
|
||||
<span id="calkm">00.000</span>Km</h3>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col text-end me-md-4"><h3>1 meter=<span id="calmeter">123.456</span></h3></div>
|
||||
<div class="col"><h3><span id="calval">123456</span> Calibration Value</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 setDistance(e){
|
||||
const setDis = document.getElementById("setdistance").value;
|
||||
var full_data='{"setcaldis":'+setDis+'}';
|
||||
console.log(full_data);
|
||||
ws.send(full_data);
|
||||
}
|
||||
function setCalibration(e){
|
||||
const setCal = document.getElementById("setcalibration").value;
|
||||
var full_data='{"setcaldisman":'+setCal+'}';
|
||||
console.log(full_data);
|
||||
ws.send(full_data);
|
||||
}
|
||||
function startCalibration(e){
|
||||
ws.send('{"calstart":1}');
|
||||
console.log("calstart->1");
|
||||
}
|
||||
function stopCalibration(e){
|
||||
ws.send('{"calstart":0}');
|
||||
console.log("calstart->0");
|
||||
}
|
||||
</script>
|
||||
</body></html>
|
||||
)rawliteral";
|
||||
3652
src/main.cpp
Normal file
3652
src/main.cpp
Normal file
File diff suppressed because it is too large
Load Diff
281
src/template_html.h
Normal file
281
src/template_html.h
Normal file
@ -0,0 +1,281 @@
|
||||
const char HTML_PAGEHEADER[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1</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">
|
||||
<script type = "text/javascript">
|
||||
const ws = new WebSocket("ws://%serveripaddress%/ws");
|
||||
ws.onopen = function() {console.log("websocket connected");};
|
||||
ws.onclose = function() {alert("WSocket Connection Closed");};
|
||||
ws.onmessage = function(event) {
|
||||
console.log(event.data);
|
||||
var data = JSON.parse(event.data);
|
||||
document.getElementById("currenttime").innerHTML = data.curTime;
|
||||
document.getElementById("currenttrack").innerHTML = data.curTrip;
|
||||
|
||||
document.getElementById("counter").innerHTML = data.counter;
|
||||
document.getElementById("speed").innerHTML = data.curTripSpeed;
|
||||
document.getElementById("dir1").innerHTML = data.dir1;
|
||||
document.getElementById("dir2").innerHTML = data.dir2;
|
||||
document.getElementById("odo1").innerHTML = data.curDist1;
|
||||
document.getElementById("odo2").innerHTML = data.curDist2;
|
||||
document.getElementById("time1").innerHTML = data.time1;
|
||||
document.getElementById("time2").innerHTML = data.time2;
|
||||
};
|
||||
</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>)rawliteral";
|
||||
|
||||
const char HTML_STYLECARD[] PROGMEM = R"rawliteral(
|
||||
<style>
|
||||
.card{
|
||||
max-width: 400px;
|
||||
min-height: 250px;
|
||||
background: #02b875;
|
||||
padding: 30px;
|
||||
box-sizing: border-box;
|
||||
color: #FFF;
|
||||
margin:20px;
|
||||
box-shadow: 0px 2px 18px -4px rgba(0,0,0,0.75);
|
||||
}
|
||||
</style>)rawliteral";
|
||||
|
||||
const char HTML_DIVSTARTRALLY[] PROGMEM = R"rawliteral(
|
||||
<div class=" bg-success 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>
|
||||
<!--//ODO1-->
|
||||
<div class="row">
|
||||
<div class="col-1"><h6>OD 1-></h6></div>
|
||||
<div class="col-3 text-end"><h3><span id="odo1">123.4567</span> km</h3></div>
|
||||
<div class="col"></div>
|
||||
<div class="col-4"><h3><span id="dir1">DIRECT</span></h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time1">00:00:00</span></h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5 "><h4>
|
||||
<button ondblclick="resetodo1()" type="button" class="btn btn-primary btn-sm mb-2">Reset ODO1</button>
|
||||
<button ondblclick="copytoodo2()" type="button" class="btn btn-primary btn-sm mb-2">↓ to ODO2</button></h4>
|
||||
</div>
|
||||
<div class="col-4"><h4>
|
||||
<button ondblclick="location.href='/DIR?DIR1=FW';" type="button" class="btn btn-primary btn-sm mb-2">FW</button>
|
||||
<button ondblclick="location.href='/DIR?DIR1=ST';" type="button" class="btn btn-primary btn-sm mb-2">STOP</button>
|
||||
<button ondblclick="location.href='/DIR?DIR1=BK';" type="button" class="btn btn-primary btn-sm mb-2">BACK</button></h4>
|
||||
</div>
|
||||
<div class="col"><h4>
|
||||
<div class="d-grid gap-0 d-md-flex justify-content-md-end">
|
||||
<button onclick="location.href='/TG1';" class="btn btn-primary btn-sm me-md-4" type="button">Toggle</button>
|
||||
</div></h4>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<!--//ODO2-->
|
||||
<div class="row">
|
||||
<div class="col-5 "><h3>OD 2-><span id="odo2">123.456</span> km</h3></div>
|
||||
<div class="col-4 "><h3><span id="dir2">DIRECT</span></h3></div>
|
||||
<div class="col-3 text-end"><h3><span id="time2">00:00:00</span></h3></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-5"><h5>
|
||||
<button ondblclick="resetodo2()" type="button" class="btn btn-primary btn-sm mb-1">Reset ODO2</button>
|
||||
<button ondblclick="copytoodo1()" type="button" class="btn btn-primary btn-sm mb-1 arrow-up down-arrow">↑ to ODO1</button></h5>
|
||||
</div>
|
||||
<div class="col-4"><h5>
|
||||
<button ondblclick="location.href='/DIR?DIR2=FW';" class="btn btn-primary btn-sm mb-1" type="button">FW</button>
|
||||
<button ondblclick="location.href='/DIR?DIR2=ST';" class="btn btn-primary btn-sm mb-1" type="button">STOP</button>
|
||||
<button ondblclick="location.href='/DIR?DIR2=BK';" class="btn btn-primary btn-sm mb-1" type="button">BACK</button></h5>
|
||||
</div>
|
||||
<div class="col"><h2>
|
||||
<div class="d-grid gap-0 d-md-flex justify-content-md-end">
|
||||
<button onclick="location.href='/TG2';" class="btn btn-primary btn-sm me-md-4" type="button">Toggle</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button ondblclick="location.href='/menu';" class="btn btn-secondary fw-bold btn-sm mt-2 mb-2">Back to Menu</button>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Are you Sure <span class="func">Reset</span> ODO <span id="p1" class="odonum">1</span> ?
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button id="btnyesreset" type="button" class="btn btn-primary">Yes, <span class="func">Reset</span> ODO <span class="odonum"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)rawliteral";
|
||||
|
||||
const char HTML_SCRIPTSETINTERVAL[] PROGMEM = R"rawliteral(
|
||||
<script>setInterval(function() {
|
||||
// Call a function repetatively with 333 miliSecond interval
|
||||
getData();
|
||||
}, 333); //333mSeconds update rate
|
||||
</script>
|
||||
)rawliteral";
|
||||
|
||||
const char HTML_SCRIPTGETDATA[] PROGMEM = R"rawliteral(
|
||||
<script>
|
||||
function getData() {
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 && this.status == 200) {
|
||||
var data = JSON.parse(this.responseText);
|
||||
document.getElementById("ADCValue").innerHTML =
|
||||
data.pin36;
|
||||
document.getElementById("ADCValue2").innerHTML =
|
||||
data.pin39;
|
||||
document.getElementById("ADCValue3").innerHTML =
|
||||
data.pin5;
|
||||
document.getElementById("time").innerHTML =
|
||||
data.time;
|
||||
//this.responseText;
|
||||
}
|
||||
};
|
||||
xhttp.open("GET", "readADC", true);
|
||||
xhttp.send();
|
||||
}
|
||||
</script>)rawliteral";
|
||||
|
||||
const char HTML_END[] PROGMEM = R"rawliteral(
|
||||
</body></html>)rawliteral";
|
||||
|
||||
// HTML web page to handle 3 input fields (inputString, inputInt, inputFloat)
|
||||
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">
|
||||
<script>
|
||||
function submitMessage() {
|
||||
alert("Saved value to ESP SPIFFS");
|
||||
setTimeout(function(){ document.location.reload(false); }, 500);
|
||||
}
|
||||
</script></head><body><h3>
|
||||
<form action="/get" target="hidden-form">
|
||||
inputString (current value %inputString%): <input type="text" name="inputString">
|
||||
<input type="submit" value="Submit" onclick="submitMessage()">
|
||||
</form><br>
|
||||
<form action="/get" target="hidden-form">
|
||||
inputInt (current value %inputInt%): <input type="number " name="inputInt">
|
||||
<input type="submit" value="Submit" onclick="submitMessage()">
|
||||
</form><br>
|
||||
<form action="/get" target="hidden-form">
|
||||
inputFloat (current value %inputFloat%): <input type="number " name="inputFloat">
|
||||
<input type="submit" value="Submit" onclick="submitMessage()">
|
||||
</form>
|
||||
<iframe style="display:none" name="hidden-form"></iframe></h3>
|
||||
</body></html>)rawliteral";
|
||||
|
||||
const char wifi_html[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>ESP WIFI Station</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script>
|
||||
function submitMessage() {
|
||||
alert("Saved value to ESP SPIFFS");
|
||||
setTimeout(function(){ document.location.reload(false); }, 500);
|
||||
}
|
||||
</script></head><body>
|
||||
<h3>Your Local IP is: %localip% <hr>
|
||||
<form action="/setwifi" method="POST" target="hidden-form" >
|
||||
Wifi SSID (current value %ssidString%): <input type="text" name="ssidString">
|
||||
Password (current value %inputPwd%): <input type="text" name="inputPwd">
|
||||
<input type="submit" value="Submit" >
|
||||
</form><br>
|
||||
|
||||
<iframe style="display:none" name="hidden-form"></iframe></h3>
|
||||
</body></html>
|
||||
)rawliteral";
|
||||
|
||||
|
||||
|
||||
|
||||
const char main_menu[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1</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">
|
||||
</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>
|
||||
<fieldset>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col align-self-end"><h1>MENU1</h1></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col justify-content-around d-flex flex-column">
|
||||
<div><button onclick="location.href='/startrally';" id="startrally" name="startrally" class="btn btn-primary mt-2 mb-2">START RALLY</button></div>
|
||||
<div><button onclick="location.href='/startrally1';" id="startrally1" name="startrally1" class="btn btn-primary mt-2 mb-2">START RALLY 1</button></div>
|
||||
<div><button onclick="location.href='/settime';" id="settime" name="settime" class="btn btn-primary mt-2 mb-2">Set TIME</button></div>
|
||||
<div><button onclick="location.href='/wifi';" id="setwifi" name="setwifi" class="btn btn-primary mt-2 mb-2">Set Wifi</button></div>
|
||||
<div><button onclick="location.href='/calibration';" id="calibration" name="calibration" class="btn btn-primary mt-2 mb-2">CALIBRATION</button></div>
|
||||
<div><button onclick="location.href='/constanta';" id="constanta" name="constanta" class="btn btn-primary mt-2 mb-2">CONSTANTA</button></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row row-cols-auto">
|
||||
|
||||
<div class="col"><button onclick="location.href='/startrally';" id="startrally" name="startrally" class="btn btn-primary mt-2 mb-2">START RALLY</button></div>
|
||||
<div class="col"><button onclick="location.href='/settime';" id="settime" name="settime" class="btn btn-primary mt-2 mb-2">Set TIME</button></div>
|
||||
<div class="col"><button onclick="location.href='/wifi';" id="setwifi" name="setwifi" class="btn btn-primary mt-2 mb-2">Set Wifi</button></div>
|
||||
<div class="col"><button onclick="location.href='/calibration';" id="calibration" name="calibration" class="btn btn-primary mt-2 mb-2">CALIBRATION</button></div>
|
||||
<div class="col"><button onclick="location.href='/constanta';" id="constanta" name="constanta" class="btn btn-primary mt-2 mb-2">CONSTANTA</button></div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="card text-white bg-primary mb-3" style="max-width: 20rem;">
|
||||
<div class="card-header">MENU</div>
|
||||
<div class="card-body">
|
||||
<button onclick="location.href='/startrally';" id="startrally" name="startrally" class="btn btn-primary ">START RALLY</button>
|
||||
<button onclick="location.href='/wifi';" id="settime" name="settime" class="btn btn-primary">Wifi</button>
|
||||
<button onclick="location.href='/calibration';" id="calibration" name="calibration" class="btn btn-primary">CALIBRATION</button>
|
||||
<button onclick="location.href='/constanta';" id="constanta" name="constanta" class="btn btn-primary">CONSTANTA</button>
|
||||
<a href='/wifi' class='btn btn-primary' alt='Broken Link'>Wifi</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
|
||||
</body></html>)rawliteral";
|
||||
|
||||
const char main_menu1[] PROGMEM = R"rawliteral(
|
||||
<!DOCTYPE HTML><html><head>
|
||||
<title>Rally TerraTrip v1</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">
|
||||
</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>
|
||||
<fieldset>
|
||||
<div class="card text-white bg-primary mb-3" style="max-width: 20rem;">
|
||||
<div class="card-header">MENU</div>
|
||||
<div class="card-body">
|
||||
<button onclick="location.href='/startrally';" id="startrally" name="startrally" class="btn btn-primary ">START RALLY</button>
|
||||
<button onclick="location.href='/wifi';" id="settime" name="settime" class="btn btn-primary">Wifi</button>
|
||||
<button onclick="location.href='/calibration';" id="calibration" name="calibration" class="btn btn-primary">CALIBRATION</button>
|
||||
<button onclick="location.href='/constanta';" id="constanta" name="constanta" class="btn btn-primary">CONSTANTA</button>
|
||||
<a href='/wifi' class='btn btn-primary' alt='Broken Link'>Wifi</a>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
</body></html>)rawliteral";
|
||||
11
test/README
Normal file
11
test/README
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
||||
Loading…
Reference in New Issue
Block a user