Server.send Serial Monitor Input

Hi,
I have a Wemos D1 board (Esp8266 based)
I am trying to send some text to a server through Server.send
This is what I tried so far.

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

const char* ssid = "MySpectrumWiFid8-2G";
const char* password = ".............";
ESP8266WebServer server(80);

const int led = 13;

void handleRoot() {
digitalWrite(led, 1);

server.send(200, "text/plain", Serial.read());
digitalWrite(led, 0);
}

void handleNotFound() {
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET) ? "GET" : "POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i = 0; i < server.args(); i++) {
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}

void setup(void) {
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");

// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}

server.on("/", handleRoot);

server.on("/inline", {
server.send(200, "text/plain", "this works as well");
});

server.onNotFound(handleNotFound);

server.begin();
Serial.println("HTTP server started");
}

void loop(void) {
server.handleClient();
}

But I get this error:

HelloServer:17:47: error: converting to 'const String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'

server.send(200, "text/plain", Serial.read());

^

void send(int code, const char* content_type = NULL, const String& content = String(""));

exit status 1
converting to 'const String' from initializer list would use explicit constructor 'String::String(int, unsigned char)'

I'm sorry if this is really informative, but I don't know what else I could add.

First: read the sticky post at the top of the forum! Always use code tags when posting code!

server.send(200, "text/plain", Serial.read());

What do you expect that line to do? Serial.read() returns an integer but the server.send() method doesn't expect an integer parameter.

If your intention is to send a string read from the serial interface, you must read the string from the serial, save it into a variable and let server.send() send that variable. This is because it's not very probable that a character is available at the serial interface just in the moment the HTTP request is handled. And you probably don't want to return just one single character.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

What do you expect that line to do? Serial.read() returns an integer but the server.send() method doesn't expect an integer parameter.

If your intention is to send a string read from the serial interface, you must read the string from the serial, save it into a variable and let server.send() send that variable. This is because it's not very probable that a character is available at the serial interface just in the moment the HTTP request is handled. And you probably don't want to return just one single character.
[/quote]

Thank you for answering, but I'm not sure what this would look like.

I tried to get the Serial Input like this:
char SerialInput = Serial.read();

But then if I make this line of code:
server.send(200, "text/plain", SerialInput;

I get this error:
expected ')' before ';' token

zachgreen2018:
Thank you for answering, but I'm not sure what this would look like.

I tried to get the Serial Input like this:
char SerialInput = Serial.read();

Have you studied the link in Reply #2 ?

...R

Yes I tried to figure out how to apply Example 2 - Receiving several characters from the Serial Monitor
to my code, but I'm not completely sure how to go about this.
I experimented with it, but ultimately failed.

I probably misunderstood something. I really don't know.

zachgreen2018:
I experimented with it, but ultimately failed.

I probably misunderstood something. I really don't know.

Unless you post the program you tried I cannot see what you did or offer any advice to get things working.

...R

I'm just going to study the Serial Input Basics, like you suggested, until I get it.

I'll figure it out eventually.

Thank you.