0

I beg your pardon, but my English is not good too. I want to make a server Esp32 that displays results from clients. 2 clients send temperature and humidity.I have a problem in recognizing which customer sends data and whether it is tempeartura or humidity. The server is based on tcp. I am looking for help in how to recognize customer and data. Client send: Tem(1)=21 Hum(1)=60

include

#include <LiquidCrystal_I2C.h>

// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;

// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);  
const char* ssid = "xxxx";
const char* password =  "xxx";

WiFiServer wifiServer(8088);

void setup() {
 lcd.init();
  // turn on LCD backlight                      
  lcd.backlight();
  Serial.begin(115200);

  delay(1000);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  Serial.println("Connected to the WiFi network");
  Serial.println(WiFi.localIP());

  wifiServer.begin();
}

void loop() {

  WiFiClient client = wifiServer.available();

  if (client) {

    while (client.connected()) {

      while (client.available()>0) {
        lcd.setCursor(0, 0);
         String Message = client.readStringUntil('\n'); 
         Serial.println(Message);
         lcd.println(Message);
         delay(1000);
         lcd.clear();

      }

      delay(10);
    }

    client.stop();
    Serial.println("Client disconnected");

5
  • 1
    the question is too broad, show the snippets of code of what you tried. Commented Dec 21, 2019 at 22:26
  • This is such a basic version of the code I have no idea how to do it Commented Dec 21, 2019 at 22:41
  • do you have access to the devices that are sending the message? Commented Dec 21, 2019 at 22:53
  • yes I have an access Commented Dec 21, 2019 at 22:57
  • the idea of using raw TCP is that you are sending binary data, you need to parse it then. To avoid difficulties in your case you can use HTTP, there are plenty of examples of http server on arduino. Commented Dec 21, 2019 at 23:02

1 Answer 1

0

If I understand you correctly, you want the client to send Temperature data over TCP/IP using the URL he's calling.

Since at every given time only one client can be connected to your web server, I think the simplest way to distinguish between different clients is to let them use an identifier in the string they're sending to your server, and then you can process it before you sent it to the LCD.

Please let me know if that's what you're trying to do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.