Send data between 2 NodeMcu ESP8266

Greetings,

I have a project that send GPS position from and Arduino to another (nano to micro), with 2 Bluetooth (HC-05)

SENDER:

//Arduino Nano (compatible)
//ATmega328

#include <TinyGPS.h>
#include <SoftwareSerial.h>

SoftwareSerial bt_port(2, 3);

TinyGPS gps;
long lat, lon;

void setup() {
  Serial.begin(9600);
  bt_port.begin(38400);
}

void loop() {
  if (Serial.available()) {
    if (gps.encode(Serial.read())) {
      gps.get_position(&lat, &lon);

      Serial.println("EMISSOR:");
      Serial.print("     lat: "); Serial.println(lat);
      Serial.print("     lon: "); Serial.println(lon);

      bt_port.println(lat);
      bt_port.print ('/');
      bt_port.println(lon);

      delay(2000);
    }
  }
}

RECEIVER:

...

if (Serial.available() > 0) {

    currentMillis = millis();

    String emiLat = Serial.readStringUntil('/');
    float emiLatitude = emiLat.toFloat();
    String emiLon = Serial.readStringUntil('\0');
    float emiLongitude = emiLon.toFloat();

...

I’m trying to change the project and communicate between 2 NodeMcu ESP8266

SENDER:

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>v
#include <TinyGPS.h>

const char *ssid = "testeteste";
const char *password = "vamosver";

//int milisInterval = 2000;

ESP8266WebServer server(80);

TinyGPS gps;
long lat, lon;

void handleRoot() {
  
String html ="<!DOCTYPE html> <html> <body> <h1>Latitude</h1> <head><meta http-equiv=\"refresh\" content=\"1\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"></head> <div id=\"light\">";
html += lat;
html +="</div><h1>Longitude</h1><div id=\"random\">";
html += lon;
html +="</div> </body> </html>";
  server.send(200, "text/html", html);
}

void setup() {
  Serial.begin(9600);

  Serial.println();
  Serial.print("Configuring access point...");
  WiFi.softAP(ssid, password);

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

void loop() {
  if (Serial.available()) {
    if (gps.encode(Serial.read())) {
      gps.get_position(&lat, &lon);

      Serial.println("EMISSOR:");
      Serial.print("     lat: "); Serial.println(lat);
      Serial.print("     lon: "); Serial.println(lon);

//      bt_port.println(lat);
//      bt_port.print ('/');
//      bt_port.println(lon);

      delay(2000);
    }
  }

  server.handleClient();
}

So, I can get the position on “Serial Monitor” and in the webpage created by the sender.
But really not getting on how I can receive on NodeMcu RECEIVER…

Thanks in advance, any help will be helpful and appreciated.

The NodeMcu device is configured to be either a client or a server. Your sender is a server. Your receiver is a?

A server responds to client requests. Your receiver, if it is a client, is NOT making any GET or POST requests.

The NodeMcu devices are NOT direct replacements for radios.

Interesting, Thanks a lot!!

So, there is no way to reproduce what I did with Bluetooth, is that it!?

Anyway, if I defined

lat; lon;

in the HTML and they change every second, is there a way to pick it since I'm connected to that "server"!?

Thanks again.

So, there is no way to reproduce what I did with Bluetooth, is that it!?

It can be done, but it will not be as easy as using radios dedicated for the purpose of sending data, like the XBees, the NRF modules, the 433 MHz radios, etc.

One device would need to be a server, having data to share, or accepting data from the other one.

The other one would make a GET request, to get the data or to share the data (like when asking google to search for a specific term, you need to supply some data - the term to search for).

Client/server interactions are relatively slow, for the purposes of sharing data.

Anyway, if I defined

lat; lon;

in the HTML and they change every second, is there a way to pick it since I'm connected to that "server"!?

If the server has the lat and lon data of interest, the client can ask for the data whenever it needs it. It will not be able to tell that the data changed since the last time it asked, unless the server also supplies a last-time-updated value.

The server can not push the data to the client.

In general, I think you have the roles reversed. The sender should be a client. The receiver should be a server. The client should ask the server to do something with the lat and lon values:

GET /useThisData?lat="SomeLatitudeValue"&lon="SomeLongitudeValue"

The server does not need to return anything more than a 200 status code to say that it accepted the data.