Chat freely about anything...

User avatar
By Ian Phill
#57219
martinayotte wrote:Simply do the following :
Code: Select allserver.send(200, "text/html", String("<h1>") + incomingByte + "</h1>");


Can you tell me where I can find documentation about this? Because I wanna sent this string :0400FF000F0F0F0FC1 to server but I have this string inside a char array and when I use this way the result is !@#%^$&*%*(&^ something like this. Thank you
User avatar
By martinayotte
#57225 The String class allow concatenation by itself, but first argument need to be a string. OP post was trying to concatenate "char *" with "char *", which is not available in plain C.

In your case, are you sure you have done it right ?
shows us your code, we can try to figure out.
User avatar
By Ian Phill
#57231 #include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

const char *ssid = "ESPap";
const char *password = "thereisnospoon";

char incomingData[19];
int pos = 0;

ESP8266WebServer server(80);

void handleRoot() {
server.send(200, "text/html", String("<h1>@") + incomingData + "</h1>");
}

void setup() {
delay(1000);
Serial.begin(9600);
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
server.on("/index.html", handleRoot);
server.begin();
}

void loop() {
server.handleClient();

if (Serial.available() > 0) {
while (Serial.available() > 0) {
incomingData[pos++] = Serial.read();
}
}

pos = 0;

server.send(200, "text/html", String("<h1>@") + incomingData + "</h1>");
}


Tank you in advance
User avatar
By martinayotte
#57248 First your incomingData buffer is limited to 19, you need to add guards in case the Serial get larger set of data.
Second, this incomingData is never NULL character terminated, so the concatenate won't end until it find some NULL character, somewhere in memory. You need to add "incomingData[pos] = 0;" before resetting pos to zero.