I have a ESP32 server receiving data from four ESP32 clients. With the server plugged into my PC I can view all four sets of client data as it comes in just fine. What I would like to do is print out each incoming clients data to a line of the LCD.
Here is what is sent from the client: client.print(temp);
client.print(" F DP Bdrm Blue );
And this is at the server end: Serial.write(c);
And this is an example of what I get at the server end on my PC screen: 77 F DP Bdrm Blue
I would like each clients data to print to a separate line on the LCD.
If I try printing to a 20x4 LCD it just all prints to the first line. So far I haven't been able to figure out how to separate out each clients data so it goes to it's own line on the LCD. I tried IF statements but that didn't work at all.[c/*********
6/18/2018 This works ok.
Sends 18B20 temperature from ESP32 client to ESP32 server.
From Random Nerd Tutorials.
*********/
//#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFi.h>
#include <WiFiMulti.h>
WiFiMulti WiFiMulti;
//const char* ssid = "----------";
//const char* password = "----------";
#define ONE_WIRE_BUS 21
// Setup a oneWire instance to communicate with a OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
// Temperature Sensor variables
int temperature;
void setup() {
sensors.begin();
Serial.begin(115200);
Serial.println("sketch_jul21a_2018_ESP32_18B20_Client_Blue_21_ForumA");
WiFiMulti.addAP("---------", "----------");
Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");
while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
}
void loop()
{
const uint16_t port = 80;
const char * host = "------------"; // ip or dns
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
Serial.println("wait 5 sec...");
delay(5000);
return;
}
sensors.requestTemperatures();
// temperature = sensors.getTempCByIndex(0); // Temperature in Celsius
temperature = sensors.getTempFByIndex(0); // Temperature in Fahrenheit
Serial.print("Temperature: ");
Serial.println(temperature);
// This will send the request to the server
client.print(temperature);
client.print(" F BLUE DP Bdrm");
//read back one line from server
String line = client.readStringUntil('\r');
client.println(line);
Serial.println("closing connection");
client.stop();
Serial.println("wait 5 sec...");
delay(5500);
}ode][/co/*
From Random Nerd Tutorials.
A simple web server.
This sketch will print the IP address of your WiFi Shield (once connected)
to the Serial monitor. From there, you can open that address in a web browser.
This example is written for a network using WPA encryption. For
WEP or WPA, change the Wifi.begin() call accordingly.
*/
#include <WiFi.h>
const char* ssid = "------";
const char* password = "------";
WiFiServer server(80);
void setup()
{
Serial.begin(115200);
Serial.println("sketch_jul21a_2018_ESP32_WiFiServer_21_Forum_A");
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("MAC address: ");
String mac = WiFi.macAddress();
Serial.println(mac);
server.begin();
}
int value = 0;
void loop(){
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
// Serial.println("New Client."); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then char
Serial.write(c); // print it out the serial monitor
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
} else { // if you got a newline, then clear currentLine:
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// close the connection:
client.stop();
// Serial.println("Client Disconnected.");
}
de]
How to print out from ESP32 server to 20x4 LCD.
Re: How to print out from ESP32 server to 20x4 LCD.
Its hard to read this code without formatting, but i am assuming you are reading one value at a time and displaying it. What im thinking is that you need each time before you display value to set cursor position, this way you will be able to display value in new row.
Who is online
Users browsing this forum: pbeam66 and 115 guests