'Get data from SQL to ESP32 Webserver
I would like to know what is happening? I want that number is in the sql database shows in box, and Idk what is happening Works fine when I do the print of the payload, always appears the number I want
String httpGETRequest(const char* serverName) {
HTTPClient http;
http.begin(serverName);
int httpCode = http.GET();
String payload = "";
if (httpCode > 0) {
payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpCode);
}
http.end();
return payload;
}
String processor(const String& var){
Serial.println(var);
else if(var == "THRESHOLD"){
return tempThreshold;
}
return String();
}
//temperature and threshold function
String readTemp1() {
return String(readTemp);
}
String tempThreshold1() {
return String(tempThreshold);
}
const char* THRESHOLD_INPUT_1 = "threshold_input";
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print("Connecting ...");
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println("\nConnected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
dht.begin();
tempThreshold = httpGETRequest(serverName);
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html, processor);
});
...
Result1:
And if I change the line
tempThreshold = httpGETRequest(serverName);
To this
tempThreshold = "60";
Result2:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


