Chat freely about anything...

User avatar
By armin.kozljak
#45410 Hi,
Does anyone know how can I increase data transfer speed between two ESPs. I send data from one ESP (client) to other ESP (server). On client ESP I test voltage level (LOW or HIGH) on two digital input pins and I need to send this data to other ESP as fast as possible. With them code that I have now, data transfer is between 0.5 and 1 second. I use two ESP 12E.

CLIENT
Code: Select all#include <ESP8266WiFi.h>

const char* ssid     = "ateESPteam";
const char* password = "arminkozljak";

const char* host = "192.168.4.1";
const char* url = "";
String podatak;
bool stanje1,stanje2;

int GPIO12 = 12;
int GPIO4 = 4;
int pom;

void setup() {
 
  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  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());
 
  //pom = 0;
}

void loop() {
 
  stanje1 = digitalRead(GPIO4);
  delay(10);
  stanje2=digitalRead(GPIO12);
  delay(10);
 
  if((stanje1 == LOW)&&(stanje2 == LOW))
    podatak = "jedan";
  else if((stanje1 == LOW)&&(stanje2 == HIGH))
    podatak = "dva"; 
  else if((stanje1 == HIGH)&&(stanje2 == LOW))
    podatak = "tri";
  else if((stanje1 == HIGH)&&(stanje2 == HIGH))
    podatak = "cetiri";
    WiFiClient client;
     
  // Use WiFiClient class to create TCP connections
   // This will send the request to the server
  const int httpPort = 80;
  if (client.connect(host, httpPort)) {
    client.print(podatak);
  }
  else{
  Serial.println("connection failed");
        return;
  } 
}


SERVER
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>

/* Set these to your desired credentials. */
const char *ssid     = "ateESPteam";
const char *password = "arminkozljak";

int GPIO5 = 5;
int analog;
String line = "";
WiFiClient client;
WiFiServer server(80);

void setup() {
  pinMode(GPIO5, OUTPUT);

  analog = 0;
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.begin();
  Serial.println("server started");
}

void loop(){

  delay(10); 
  if (!client)
  {
      client = server.available();
  } 
  else
  {
     if (client.status() == CLOSED)
     {
      client.stop();
     }   

    if (client.available() > 0)
    {
      line = client.readStringUntil('\r');
      Serial.println(line);

      if ((analog < 1023) && (line == "dva")){
      analog = analog + 100;
      analogWrite(GPIO5 , analog);
        if (analog > 1000)
          analog = 1023;         
      }
      if ((analog > 1) && (line == "tri")){
      analog = analog - 100;
      analogWrite(GPIO5 , analog);
        if (analog  < 1)
          analog = 0;
         
      }
      if (line == "GET /on HTTP/1.1"){
        digitalWrite(GPIO5 , HIGH);
        analog = 1023;}

      if (line == "GET /off HTTP/1.1"){
        digitalWrite(GPIO5 , LOW);
        analog = 0;
        }
     
      line = "";
      client.stop();
    }
  }
}