-->
Page 1 of 2

wifi.send() Sending a variable

PostPosted: Sat Oct 22, 2016 10:13 pm
by Ian Phill
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();
}

Re: wifi.send() Sending a variable

PostPosted: Sun Oct 23, 2016 4:33 am
by sebcologne
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.

Re: wifi.send() Sending a variable

PostPosted: Sun Oct 23, 2016 8:08 am
by martinayotte
Simply do the following :
Code: Select allserver.send(200, "text/html", String("<h1>") + incomingByte + "</h1>");

Re: wifi.send() Sending a variable

PostPosted: Sun Oct 23, 2016 3:59 pm
by Ian Phill
Thank you for your time and help.