Faster communication between two ESP8266 in client-server setup

0 votes

I am trying to communicate between two ESP8266 12 E modules, one is set up in access point mode and the other as a station. My aim is to establish communication between the two.

  1. How can I make the data transfer faster?
  2. Is this what is called TCP/IP connection?

The code for the access point:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
WiFiServer server(80);

void setup() {
  WiFi.mode(WIFI_AP);
  WiFi.softAP("esp", "lol123");
  server.begin();
  Serial.begin(9600);
  IPAddress IP = WiFi.softAPIP();
  //Serial.flush();
  Serial.println();
  Serial.print("Server IP is: ");
  Serial.println(IP);

}

void loop() {
  char ID, R, G, B, anim_ID;
  WiFiClient client = server.available();



  int data_outgoing[5] = {10, 128, 128, 123, 123};
  int mapFun[5];
  Serial.print("Sent data: ");
  Serial.print(ESP.getChipId());
  Serial.println();
  for(int i = 0; i < 5; i++){
    mapFun[i] =data_outgoing[i];
    //mapFun[i] = map(mapFun[i], 0, 255, 0, 128); 
    client.print(mapFun[i]);
    Serial.print(mapFun[i]);

  }

delay(10);
}

and for the receiving end, the station.

const char* ssid = "esp";
const char* password = "lol123";
const char* host = "192.168.4.1";
WiFiServer server(80);

void setup(){
  int count = 0;
  Serial.begin(9600);
  delay(10);
  //Serial.println();
  //Serial.println();
  //Serial.print("Connecting to: ");
  //Serial.print(ssid);
  //Serial.println();
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  //Serial.println("Connecting");

  while(WiFi.status() != WL_CONNECTED){
    delay(1000);
    Serial.print(".");
    count++;
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("Time for connection(s): ");
  Serial.print(count);
  Serial.println();
  Serial.println("IP address: ");
  Serial.print(WiFi.localIP());
  Serial.println();
}

void loop(){
 WiFiClient client;

 if((client.connect(host, 80))){
//  Serial.println("Connected");
//  Serial.print(host);
//  Serial.println();

}

String data;
data = client.readStringUntil('\n');
  //Serial.println(data);

 for(int i = 0; i< 100; i++){
    Serial.write(data[i]);
    Serial.print(data[i]);
 }
}

The problem with this set up is the data is transferred at a good speed, but while receiving the data is very slow. It takes quite a while to receive the data at the station side, what can be done to make this process faster, are there any other protocols to use to make this faster? The output is like this..

WiFi connected
Time for connection(s): 3
IP address: 
192.168.4.2
10128128123123

The long length of data is the string I received, how do i convert it into integers? I tried ATOI but failed.

I'm kinda new to networking, any suggestion much appreciated.

Jul 13, 2018 in IoT (Internet of Things) by Matt
• 2,270 points
6,812 views

1 answer to this question.

0 votes

Try following.

Server loop

void loop() {
  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    if (client.connected()) {
      if (client.available()) {

        int data_outgoing[5] = {10, 128, 128, 123, 123};
    for(int i = 0; i < 5; i++){
    client.print(data_outgoing[i]);

    //Edit
    client.print('\n');

  }

     }
    }

    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

Client loop

void loop(){
 WiFiClient client;


WiFiClient client = client.connect(host, 80);

while (client.connected()) {             
        char c = client.read();     
       Serial.print(c);
}

}
answered Jul 13, 2018 by anonymous2
• 4,280 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

Changing message format in KURA MQTT cloud client

The Eclipse Kura communicates with a MQTT ...READ MORE

answered Jul 29, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,159 views
0 votes
1 answer
0 votes
1 answer

Communication between Apache NiFi and iOT sensors

Your use case sounds like the kind ...READ MORE

answered Oct 8, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,720 views
0 votes
1 answer

Why two get requests are not updating fields in thingspeak?

You can update up to 8 fields ...READ MORE

answered Nov 22, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,634 views
0 votes
1 answer
0 votes
1 answer

How to send a data from arduino uno to a webpage through esp8266 wifi module?

You are missing a few \r\n and the length ...READ MORE

answered Aug 9, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
3,644 views
0 votes
1 answer

MQTT on ESP8266 with NodeMCU - problems with publishing

Perhaps this was solved by more recent ...READ MORE

answered Aug 13, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,982 views
0 votes
1 answer

What is the best way to retrofit existing alarm PIR with esp8266/etc?

Here is an explanation that best fits ...READ MORE

answered Sep 4, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
984 views
0 votes
1 answer

What protocols are used for Long Distance Communication in IoT ?

Azure IoT Hub supports three protocols: AMQP, ...READ MORE

answered Sep 11, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,786 views
0 votes
1 answer

Difference between particle.publish event and particle.subscribe event in particle.cloud

Particle.publish() Publish an event through the Particle Cloud ...READ MORE

answered Sep 18, 2018 in IoT (Internet of Things) by anonymous2
• 4,280 points
1,537 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP