Sending an array from one Nodemcu to another Nodemcu?

I am working on a gesture control car project and I find everyone on the internet using RF modules or Bluetooth modules to do it, I had two NodeMCU lying around so I thought why not use them and bring a change. But I am finding difficulty in sending the accelerometer values from one Nodemcu to another, For connecting the two Nodemcu I took help from here

So instead of a string (which they use), I tried sending an array of two variables, but I fail to send/receive it from the transmitter to the receiver. I have spent a lot of time on it, but I think I need help.

I now know ( just this morning ) that Nodemcu has only one analog pin, I have ordered for a 74HC4051 IC. So I haven't changed the code for that, so please bear that in mind. Also, I have used the xAxis only now just to test if the data is being sent, but it is not.

If there is any other easier way of sending the two variable values, please do suggest.

This is the actual project, I asked the author for help, but no reply yet.

I have given below the edited code that I have now

Transmitter code

#include <SPI.h>
#include <ESP8266WiFi.h>

int xAxis = A0;
int yAxis = D2;
int data[1];
int x;


int ledPin = D8;
char ssid[] = "********";               // SSID 
char pass[] = "********";               // password I removed them while posting the question
WiFiServer server(80);                    

IPAddress ip(192, 168,1, 80);            // IP address of the server
IPAddress gateway(192,168,1,1);           // gateway of your network
IPAddress subnet(255,255,255,0);          // subnet mask of your network

void setup() {
  Serial.begin(115200);                   // only for debug
  WiFi.config(ip, gateway, subnet);       // forces to use the fix IP
  WiFi.begin(ssid, pass);                 // connects to the WiFi router
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  server.begin();                         // starts the server
  Serial.println("Connected to wifi");
  Serial.print("Status: "); Serial.println(WiFi.status());  // some parameters from the network
  Serial.print("IP: ");     Serial.println(WiFi.localIP());
  Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
  Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
  Serial.print("SSID: "); Serial.println(WiFi.SSID());
  Serial.print("Signal: "); Serial.println(WiFi.RSSI());
  Serial.print("Networks: "); Serial.println(WiFi.scanNetworks());
  pinMode(ledPin, OUTPUT);
  }


void loop () {
  WiFiClient client = server.available();
  if (client) {
    if (client.connected()) {
      digitalWrite(ledPin, LOW);  // to show the communication only (inverted logic)
      Serial.println(".");
      client.flush();
      Serial.println("Data send"); 
      x= analogRead(xAxis);
      data[0]= analogRead(xAxis);
      client.println(data[x,yAxis]); 
      Serial.println(x); 
      Serial.println(data[0]); //This appears on the screen only if i have the line  data[0]= analogRead(xAxis);
      digitalWrite(ledPin, HIGH);
    }
    client.stop();                // tarminates the connection with the client
  }delay(2000);
}

Receiver Code

#include <SPI.h>
#include <ESP8266WiFi.h>

int ENA = D1;
int ENB = D2;
int MotorA1 = D3;
int MotorA2 = D4;
int MotorB1 = D5;
int MotorB2 = D6;
int data[1];

int xAxis;
int yAxis;

int ledPin = D8;
char ssid[] = "*****";           
char pass[] = "*****";            

unsigned long askTimer = 0;

IPAddress server(192,168,1,80);       // the fix IP address of the server
WiFiClient client;

void setup() {
  Serial.begin(115200);               // only for debug
  WiFi.begin(ssid, pass);             // connects to the WiFi router
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
/*  Serial.println("Connected to wifi");
  Serial.print("Status: "); Serial.println(WiFi.status());    // Network parameters
  Serial.print("IP: ");     Serial.println(WiFi.localIP());
  Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
  Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
  Serial.print("SSID: "); Serial.println(WiFi.SSID());
  Serial.print("Signal: "); Serial.println(WiFi.RSSI());*/
  pinMode(ledPin, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(MotorA1, OUTPUT);
  pinMode(MotorA2, OUTPUT);
  pinMode(MotorB1, OUTPUT);
  pinMode(MotorB2, OUTPUT);
  digitalWrite(MotorA1, LOW);
  digitalWrite(MotorA2, LOW);
  digitalWrite(MotorB1, LOW);
  digitalWrite(MotorB2, LOW);
  analogWrite(ENA, 0);
  analogWrite(ENB, 0);
}

void loop () {
  client.connect(server, 80);   // Connection to the server
  digitalWrite(ledPin, LOW);    // to show the communication only (inverted logic)
  Serial.println(".");
   
   data[xAxis,yAxis] = client.read();   // receives the answer from the sever
  Serial.println(" Received from Server ");
  client.flush();
  digitalWrite(ledPin, HIGH);
  Serial.println(xAxis);
  if(yAxis > 400) {
  digitalWrite(MotorA1, LOW);
  digitalWrite(MotorA2, HIGH);
  digitalWrite(MotorB1, HIGH);
  digitalWrite(MotorB2, LOW);
  analogWrite(ENA, 150);
  analogWrite(ENB, 150);
  
}else if(yAxis < 320) {
  digitalWrite(MotorA1, HIGH);
  digitalWrite(MotorA2, LOW);
  digitalWrite(MotorB1, LOW);
  digitalWrite(MotorB2, HIGH);
  analogWrite(ENA, 150);
  analogWrite(ENB, 150);
} else if(xAxis < 320){
  digitalWrite(MotorA1, HIGH);
  digitalWrite(MotorA2, LOW);
  digitalWrite(MotorB1, HIGH);
  digitalWrite(MotorB2, LOW);
  analogWrite(ENA, 150);
  analogWrite(ENB, 150);
}else if(xAxis > 400){
  digitalWrite(MotorA1, LOW);
  digitalWrite(MotorA2, HIGH);
  digitalWrite(MotorB1, LOW);
  digitalWrite(MotorB2, HIGH);
  analogWrite(ENA, 150);
  analogWrite(ENB, 150);
}else {
  digitalWrite(MotorA1, LOW);
  digitalWrite(MotorA2, LOW);
  digitalWrite(MotorB1, LOW);
  digitalWrite(MotorB2, LOW);
  analogWrite(ENA, 0);
  analogWrite(ENB, 0);
  } 
                   
     delay(2000);              // client will trigger the communication after two seconds
}

you may find someone more familiar with your transmission problem under the Network, Protocols and Devices forum.

gcjr:
you may find someone more familiar with your transmission problem under the Network, Protocols and Devices forum.

As you said I have now posted the same question there

You should have asked a Moderator to move this post instead of starting a new thread there. Now there are 2 places with the same question.

If just want to communicate between 2 ESP8266 (don't need WiFi) have a look at ESP-NOW

Robin2 has a tutorial on using ESP-NOW.

"But I am finding difficulty in sending the accelerometer values from one Nodemcu to another,"

Are you able to send the data just to the serial monitor for testing purposes?

zoomkat:
"But I am finding difficulty in sending the accelerometer values from one Nodemcu to another,"

Are you able to send the data just to the serial monitor for testing purposes?

Yes I can see the values in the serial monitor of the transmitter
only if i have the line data[0]= analogRead(xAxis);

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

groundFungus:
You should have asked a Moderator to move this post instead of starting a new thread there. Now there are 2 places with the same question.

If just want to communicate between 2 ESP8266 (don't need WiFi) have a look at ESP-NOW

Robin2 has a tutorial on using ESP-NOW.

Really thankful for including the tutorial too, I find it hard to understand, but will crack it down soon, Thank you @groundFungus

ballscrewbob:
Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

I am sorry for the inconvenience caused, also thank you for removing the other post

groundFungus:
You should have asked a Moderator to move this post instead of starting a new thread there. Now there are 2 places with the same question.

If just want to communicate between 2 ESP8266 (don't need WiFi) have a look at ESP-NOW

Robin2 has a tutorial on using ESP-NOW.

Hey, can you tell me how I can replace the string with the array in Robin's code?? I tried and failed

first of all replace
client.println(data[x,yAxis]);
with
client.println(data[0]);

Juraj:
first of all replace
client.println(data[x,yAxis]);
with
client.println(data[0]);

I tried it but, still, no result
I rewrote the receiving code in the receiver as

int data = client.read();

what I am getting in the receiver serial monitor is

.
-1
 Received from Server 
.
-1
 Received from Server 
.
-1
 Received from Server 
.
-1
 Received from Server

I even tried it with removing data array in the transmitter and sent x by the code client.println(x);

you get -1 because you read without checking if something is available. TCP is not so fast so you can connect and read the response immediately after that. and than you disconnect and connect again and there is again nothing

read this