Hallo zusammen,
ich bin relativ neu (arbeite die letzten 6 Tage am selben Problem.
Ich möchte gerne wie in diesem Tutorial beschrieben, Input Data on HTML Form ESP32/ESP8266 Web Server Arduino IDE | Random Nerd Tutorials über einen Webserver einen HEXwert mit einer Farbangabe in meinem Code an eine LED weitergeben damit man die Farbe über die Webseite festlegen kann.
Board: ESP8266 (NodeMCU (ESP-12E)
IDE: 1.8.12
Windows 10
Wenn ich allerdings auf der Webseite, im Feld 3 Input3 einen wert alla 0x39ff33 eingebe wird die LED 4 leider nur weiß.
An LED 3 sehe ich aber, dass er Hex Werte nimmt.
Ich wäre über Hilfe sehr dankbar, ich bekomme es einfach nicht ans laufen.
Sketch:
/*********
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>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <FastLED.h>
#include <pixeltypes.h>
AsyncWebServer server(80);
// NETWORK SETUP==========================================================================================
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "???";
const char* password = "???";
IPAddress ipaWifiIP(0 , 0, 0, 0);
IPAddress ipaWifiSubnet(0, 0, 0, 0);
IPAddress ipaWifiGateway(0, 0, 0, 0);
IPAddress ipaWifiDns(0, 0, 0, 0);
//======================================================================================================
//FAST LED SETUP========================================================================================
#include <FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 21
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB
#define BRIGHTNESS 50
CRGB leds[NUM_LEDS];
//======================================================================================================
const char* PARAM_INPUT_1 = "input1";
const char* PARAM_INPUT_2 = "input2";
const char* PARAM_INPUT_3 = "input3";
/*
String PARAM_INPUT_1 = "input1";
String PARAM_INPUT_2 = "input2";
String PARAM_INPUT_3 = "input3";
*/
// HTML web page to handle 3 input fields (input1, input2, input3)
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">
</head><body>
<form action="/get">
input1: <input type="text" name="input1">
<input type="submit" value="Submit">
</form>
<form action="/get">
input2: <input type="text" name="input2">
<input type="submit" value="Submit">
</form>
<form action="/get">
input3: <input type="text" name="input3">
<input type="submit" value="Submit">
</form>
</body></html>)rawliteral";
void notFound(AsyncWebServerRequest *request) {
request->send(404, "text/plain", "Not found");
}
void setup() {
LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.config(ipaWifiIP, ipaWifiDns, ipaWifiGateway, ipaWifiSubnet);
WiFi.hostname("Todestor");
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed!");
return;
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
// Send web page with input fields to client
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html);
});
// Send a GET request to <ESP_IP>/get?input1=<inputMessage>
server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) {
String inputMessage;
String inputParam;
// GET input1 value on <ESP_IP>/get?input1=<inputMessage>
if (request->hasParam(PARAM_INPUT_1)) {
inputMessage = request->getParam(PARAM_INPUT_1)->value();
inputParam = PARAM_INPUT_1;
}
// GET input2 value on <ESP_IP>/get?input2=<inputMessage>
else if (request->hasParam(PARAM_INPUT_2)) {
inputMessage = request->getParam(PARAM_INPUT_2)->value();
inputParam = PARAM_INPUT_2;
}
// GET input3 value on <ESP_IP>/get?input3=<inputMessage>
else if (request->hasParam(PARAM_INPUT_3)) {
inputMessage = request->getParam(PARAM_INPUT_3)->value();
inputParam = PARAM_INPUT_3;
leds[0] = CRGB::Red;
leds[1] = CRGB::Yellow;
leds[2] = CRGB::Green;
leds[3] = 0x39ff33;
leds[4] = "input Message";
FastLED.show();
delay(20);
FastLED.clear();
}
else {
inputMessage = "No message sent";
inputParam = "none";
}
Serial.println(inputMessage);
//Serial.println(inputParam);
request->send(200, "text/html", "HTTP GET request sent to your ESP on input field ("
+ inputParam + ") with value: " + inputMessage +
"
<a href=\"/\">Return to Home Page</a>");
});
server.onNotFound(notFound);
server.begin();
}
void loop()
{
}