Hello, im trying to get my project work but i struggle quite a bit since i'm not a pro programmer
From my asynchWebServer on a ESP8266 i receive the values of 8 Checkboxes
Website javascript function:
<script>
function HandleHexConvert() {
var Pump1 = document.getElementById("pump1").checked + 0;
var Pump2 = document.getElementById("pump2").checked + 0;
var Pump3 = document.getElementById("pump3").checked + 0;
var Pump4 = document.getElementById("pump4").checked + 0;
var Pump5 = document.getElementById("pump5").checked + 0;
var Pump6 = document.getElementById("pump6").checked + 0;
var Pump7 = document.getElementById("pump7").checked + 0;
var Pump8 = document.getElementById("pump8").checked + 0;
var BinaryPumpString = Pump1.toString(2)+Pump2.toString(2)+Pump3.toString(2)+Pump4.toString(2)+Pump5.toString(2)+Pump6.toString(2)+Pump7.toString(2)+Pump8.toString(2);
console.log(BinaryPumpString);
var HexPumpString = parseInt(BinaryPumpString, 2).toString(16).toUpperCase();
console.log("0x" + HexPumpString);
SendRequest(BinaryPumpString);
}
function SendRequest(h) {
var r = new XMLHttpRequest();
r.open('POST', 'http://192.168.4.1/post', true);
r.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
r.send('message=' + "0b" + h + '×=' + "5");
}
</script>
Backend ESP8266
server.on("/post", HTTP_POST, [](AsyncWebServerRequest * request) {
String message;
String times;
if (request->hasParam(PARAM_MESSAGE, true)) {
message = request->getParam(PARAM_MESSAGE, true)->value();
times = request->getParam(PARAM_TIMES, true)->value();
} else {
message = "No message sent";
}
request->send(200);
Serial.println(message);
Serial.println(times);
startPumps(message, times);
});
I can pretty much choose whats the string that i get from the Post request contains but i fail to convert it to a understandable data type for the wire.h library.
Here is the startPumps() function that delivers the right value in Serial Monitor but shows a strange behavior when i measure the voltage on the different pins on my mcp23017. Strange behavior means that are random pins get high, actual not that pins what should be high with the hex value.
void startPumps(String message, String times) {
Serial.println();
Serial.println("Starte PUMPEN" + message);
Serial.print(" für" + times + "Sekunden");
char buf[11];
message.toCharArray(buf,10);
Serial.println(buf);
Wire.beginTransmission(MCP_ADDRESS);
Wire.write(MCP_GPIOA);
Wire.write(buf);
Wire.endTransmission();
}
I would appreciate any help, and sorry for my bad english i'm form austria