-1

What is the best method or retrieving information such as temperature from multiple wifi clients with a ESP8266-01 ? I have one server and five client running with ESP8266. I have seen post ang Get method. JSON files. client-server transfers. What is the best method to do that ? I am reading temperature so I do not need the clients to be all connected at the same time. So reading the client one after another in a loop would be great. thanks in advance

Ken

  • This isn't really an Arduino question. A server can only query clients if the clients are maintaining connections to it, so often instead people just have the clients connect and post values. Or you can keep the connection open and try to reconnect automatically if it breaks - this does sometimes give you the ability to ask, but also costs more server resources per client. Also look at things like MQTT. – Chris Stratton Dec 30 '17 at 0:38
  • Hi jsotola, I am not seeing where in your link that multiple clients are called. I was thinking of adding an IP address to each clients and making a GET command to each IP to get the information. – Ken Dec 30 '17 at 13:54
  • @ken: that's the right track: an http server can be polled at any time, whereas a client must stay connected, which is not ideal. the other option is to have each sensor "phone home" on a schedule, so that the server doesn't need to maintain a client list/routine. – dandavis Dec 30 '17 at 20:02
0

you do not need http for this. use plain socket communication. create a WiFiServer on every 'sensor' and ask from the main esp8266 over WiFiClient object. the WiFiServer creates a WiFiClient object and the Clients can exchange what you want.

snippet from my code:

void loop() {
  WiFiClient client = telnetServer.available();
  if (!client) {
    delay(100);
    return;
  }
  if (client.status() != 4) {
    client.stop();
    delay(1000);
    return;
  }
  while (client.connected()) {
    if (!client.available())
      continue;
    char c = client.read();
    if (c == '\n') {
      long v = s.toInt();
      s = "";
      analogWrite(PWM_PIN, v);
      v = readElSens();
      client.println(v);
    } else {
      s += c;
    }
  }
  delay(100);
}
  • Hi. I get what you are saying. But how do you go from one sensor to another sensor. All I see in your code and more on the internet ''while (client.connected()) {...'' but I need to identify the client as in client1.connected....client2.connected.. but arduino IDE does not allow me to do that. – Ken Dec 30 '17 at 15:51
  • code is for the esp with a sensor. in this case the client is the central esp and the servers are the sensor esps – Juraj Dec 30 '17 at 16:16
  • I understand what you are saying concerning client-server. But I dont understand how I make the rotation from the multiple sensors. Each of my 5 sensors are on a ESP8266 chip. I should of mentionned that earlier. – Ken Dec 30 '17 at 17:04
  • and the WiFi network is created by a router or by the main esp? – Juraj Dec 30 '17 at 17:41
  • add a server to the main esp too and let the sensor esps register to main esp over it – Juraj Dec 30 '17 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.