Dear Everyone,
Im new to the platform and programming too, i would like to get IR Commands via JSON and send it with IRSEND. Here is my code:
server.onRequestBody([](AsyncWebServerRequest * request, uint8_t data, size_t len, size_t index, size_t total) {
Serial.println("Running");
if (request->url() == "/test") {
DynamicJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject((const char)data);
if (root.success()) {
if (root.containsKey("command")) {
Serial.println(root["command"].asString()); // Hello
uint8_t cmd = root["command"];irsend.sendGree(cmd);
}
}
request->send(200, "text/plain", "end");
}
});
I sending the code like this:
curl -i -X POST -H 'Content-Type: application/json' -d '{"command": "0x19, 0x00, 0x60, 0x50x00, 0x00, 0x00, 0x30"}' http://192.168.0.185/test
Or
curl -i -X POST -H 'Content-Type: application/json' -d '{"command": "[0x19, 0x00, 0x60, 0x50x00, 0x00, 0x00, 0x30]"}' http://192.168.0.185/test
It is arriving, but not seem to working.
I have a working code, but the ir commands are hardcoded. Example:
//Declaration
uint8_t Power_ON[8] = {0x19, 0x09, 0x60, 0x50, 0x00, 0x00, 0x00, 0xC0};
//Called like
irsend.sendGree(Power_ON);
So the command is comming as char, but it is a byte actually. Please help. Thank you!