Chat freely about anything...

User avatar
By Ian Phill
#56970 Hello. I have been trying to send a variable like second parameter in server.send("",variable) but this is the result: invalid operands of types 'const char [5]' and 'char*' to binary 'operator+'

Somebody can help me, pls?

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

const char *ssid = "ESPap";
const char *password = "thereisnospoon";
char *incomingByte = "0"; // for incoming serial data

ESP8266WebServer server(80);

void handleRoot() {
server.send(200, "text/html", "<h1>" + incomingByte + "</h1>"); //Here is the problem
}

void setup() {
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
WiFi.softAP(ssid, password);

IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);

incomingByte = Serial.read(); //Here I read the incoming data

server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
}

void loop() {
server.handleClient();
}
User avatar
By sebcologne
#56974
Ian Phill wrote: invalid operands of types 'const char [5]' and 'char*' to binary 'operator+'


It's exactly that in your third parameter. C does not know what Strings are. You are basically trying to add two Arrays together. There are noumerous implementations of "C String concatenation" online, so pick one that you like.