Hi All,
I an trying to code a simple webinterface (AP) with directional control buttons that will drive stepper motors to Open or Close positions.
The Web server setup shown below produces the following compile error:
Compilation error: 'class AsyncWebServer' has no member named 'send'; did you mean 'end'?
As a novice with code I am at a complete loss, reading up on this is just muddling things even more!!
Can anyone help?
// Web server setup
server.on("/", HTTP_GET, [](AsyncWebServer* request)
{
String html = R"rawliteral(
<!DOCTYPE html>
<html>
<head><title>Stepper Motor Control</title></head>
<body>
<h1>Motor Control</h1>
<p>Current Mode: <span id="mode">Manual</span></p>
<button onclick="toggleMode()">Toggle Mode</button>
<br><br>
<div id="manual-controls">
<h3>Manual Controls</h3>
<h4>Motor 1</h4>
<input type="range" id="positionSlider1" min="0" max="180" value="0"
oninput="updatePosition1(this.value)">
<span id="positionValue1">0</span>°<br>
<button onclick="sendPosition1()">Move Motor 1</button>
<h4>Motor 2</h4>
<input type="range" id="positionSlider2" min="0" max="180" value="0"
oninput="updatePosition2(this.value)">
<span id="positionValue2">0</span>°<br>
<button onclick="sendPosition2()">Move Motor 2</button>
</div>
<br>
<h3>Position and Current Monitoring</h3>
<p>Encoder 1 Position: <span id="encoderPosition1">0.00</span>°</p>
<p>Encoder 2 Position: <span id="encoderPosition2">0.00</span>°</p>
<p>Motor Current: <span id="motorCurrent">0.00</span> A</p>
<p id="alarmMessage" style="color:red; font-weight:bold; display:none;">Current
Alarm: High Current Detected!</p>
<script>
let isManual = true;
function toggleMode() {
fetch('/toggleMode').then(() => location.reload());
}
function updatePosition1(value) {
document.getElementById('positionValue1').innerText = value;
}
function sendPosition1() {
const position = document.getElementById('positionSlider1').value;
fetch(`/setPosition1?value=${position}`);
}
function updatePosition2(value) {
document.getElementById('positionValue2').innerText = value;
}
function sendPosition2() {
const position = document.getElementById('positionSlider2').value;
fetch(`/setPosition2?value=${position}`);
}
function updateStatus() {
fetch('/getStatus').then(response => response.json()).then(data => {
document.getElementById('encoderPosition1').innerText = data.encoder1.toFixed(2);
document.getElementById('encoderPosition2').innerText = data.encoder2.toFixed(2);
document.getElementById('motorCurrent').innerText = data.current.toFixed(2);
const alarmMessage = document.getElementById('alarmMessage');
if (data.alarm) {
alarmMessage.style.display = 'block';
} else {
alarmMessage.style.display = 'none';
}
});
}
setInterval(updateStatus, 1000);
fetch('/getMode').then(response => response.text()).then(mode => {
isManual = mode === 'Manual';
document.getElementById('mode').innerText = mode;
document.getElementById('manual-controls').style.display = isManual ? 'block' : 'none';
});
</script>
</body>
</html>
)rawliteral";
request->send(200, "text/html", html);
});