Connection Test Between Two ESP8266

Find maximum wifi range between two Nodemcu

I bought two nodemcu from aliexpress. It is too cheap but wifi range maximum 20 meters. Okay lets test wifi range. You need 2 Nodemcu , 4 double A batteries and hand skills. One of client other one is hotspot.

Setting up Hotspot(Mirror) Side

Connect your nodemcu to pc. Open Arduino IDE software and write codes below. I think you do not have a friend with you when you do this test. Turned off the light on the mirror side of the device so that you could not get someone’s attention while you were testing. I assumed the mirror side was fixed because you can control wifi range with your phone.

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

WiFiUDP Udp;
unsigned int UdpPort = 4210;  // local port to listen on
char incomingPacket[255];  // buffer for incoming packets
char  replyPacekt[] = "Mirror side";  // a reply string to send back


void setup()
{
  //pinMode(2, OUTPUT); // if you need blue led flash you can uncomment this line.
  Serial.begin(115200);
  Serial.println();
  WiFi.softAP("ESP", "Rangetest");
  Udp.begin(UdpPort);
 }


void loop()
{
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    //digitalWrite(2, LOW); // if you need blue led flash you can uncomment this line.
    int len = Udp.read(incomingPacket, 255);
    if (len > 0)
    {
      incomingPacket[len] = 0;
    }
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(replyPacekt);
    Udp.endPacket();
   }
   delay(200);
   //digitalWrite(2, HIGH); // if you need blue led flash you can uncomment this line.
   delay(200);
}

Setting up Client Side

To set up the device you will bring with you, connect the device to the computer and write the sample code. The device will be connected to the Server side first. If the connection is provided, then it will send a UDP packet, if there is an answer from the other side, the blue LED on the device will be lit.

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "ESP";
const char* password = "Rangetest";

WiFiUDP Udp;
unsigned int UdpPort = 4210;
char incomingPacket[255];
char  replyPacekt[] = "Client Side";


void setup()
{
  pinMode(2, OUTPUT);
  Serial.begin(115200);
  Serial.println();
  WiFi.mode(WIFI_STA);
  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");
  Udp.begin(UdpPort);
}

void loop()
{
  Udp.beginPacket("192.168.4.1", UdpPort);
  Udp.write(replyPacekt);
  Udp.endPacket();
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    digitalWrite(2, LOW);
  }
  delay(200);
   digitalWrite(2, HIGH);
  delay(200);
    
}


If everything is ready, go out and do the test.


© 2024 All rights reserved.

Powered by Hydejack v7.5.0