need solution to communications issue

Hi, I have a system that has 9 nodes, 1 master and 8 slaves. The 8 slave nodes announce a data structure to the master using NRF24 cards. Currently this is working. i want to switch to esp8266 instead of NRF24 cards. I really need guidance thinking of a design. With my little experience i'm thinking about have an arduino connected to every ESP in the system via serial. The slaves will announce data to the master esp but how should i handle the arduino getting the received data from the master esp? This is where i need help. Should i just print everything incoming from the master esp to the arduinos rx pin? sort the data on the arduino? Please someone guide me here

Why do you want to switch?

Why not program the ESP8266 directly so that you don't need it attached to an Arduino?

...R

Robin2:
Why do you want to switch?

Why not program the ESP8266 directly so that you don't need it attached to an Arduino?

...R

Thanks,

I will need to use a mega 2560 for the master because i use an (I2C LCD) otherwise maybe i could get away with an ESP32. 2 of my nodes analog sensors are 0-5v. other than that i could use an esp technically for 6 of my modules. I want to switch because i just like the stability and range of the wifi better and as a plus it would be less wiring and parts. they already have NRF and ESP8266 cards in them i would like to just use the ESP8266. I'm going in circles here trying to come up with a plan. I basically want all 8 slave nodes to connect to the master node's soft-ap and communicate that way. I don't know how i should handle this. Especially the arduinos to ESP situation. Do i just send a struct over serial? vice versa? If you dont already know how the system works, The 8 slave nodes announce on a timer a data struct to the master. I'm thinking announce data struct from salves to the master ESP. The master ESP then would send that struct to the arduino via serial? Please forgive my intelligence

If i was to use the NRF24 the main problem is that i would need to use expensive shielded modules with external directional antennas. For me this causes problems. I currently use a shielded (amplified) version of the NRF24 in my master module. It transmits pretty good as far as range goes. The slaves are all (non amplified) and they have a hard time getting the signal out. Also i can make use of (ESP8266AVRISP) and program the arduino over wifi. I could get a flag to enable flash mode on the ESP's and upload sketches to the arduinos. The list goes on. How would you setup the esp for this communications project?

How Should i structure the data to be sent between the esp's. How should i structure the data to be sent to the arduino from the esp vice/versa?

notsolowki:
The slaves will announce data to the master esp but how should i handle the arduino getting the received data from the master esp? This is where i need help. Should i just print everything incoming from the master esp to the arduinos rx pin? sort the data on the arduino? Please someone guide me here

Yeah that would be the best way here. As you mentioned you are using Arduino Mega 2560 so you can use Serial 1 or Serial 2 to communicate between Arduino and ESP8266.

If you want to make it wireless then you can use any RF module like XBee, NRF24L01 etc which will be sending data from Master ESP node to Arduino Mega 2560.

jackthom41:
Yeah that would be the best way here. As you mentioned you are using Arduino Mega 2560 so you can use Serial 1 or Serial 2 to communicate between Arduino and ESP8266.

If you want to make it wireless then you can use any RF module like XBee, NRF24L01 etc which will be sending data from Master ESP node to Arduino Mega 2560.

I use the NRF24 right now and am trying to go with the ESP. Right now im trying to figure out how i'm going to send the data. multiple devices sending large amounts of variables. how am i going to know whats from who. I want to just send it all in a structure but i have not achieved this yet. I'm trying to use ESPAsyncTCP but i don't really know what i'm doing

You can place some sort of checks like if the data is coming from first node then it's enclosed between @ & #, if it's coming from 2nd node then use different characters something like this:

@ Node 1 Data #
~ Node 2 Data $
! Node 3 Data %

Now if we make it even more simple then you can use such notation:

[N1: Node 1 Data ]
[N2: Node 2 Data ]
[N3: Node 3 Data ]

You can even make the N1 as a variable and can assign it from the master node to your desired salve node.

jackthom41:
You can place some sort of checks like if the data is coming from first node then it's enclosed between @ & #, if it's coming from 2nd node then use different characters something like this:

@ Node 1 Data #
~ Node 2 Data $
! Node 3 Data %

Now if we make it even more simple then you can use such notation:

[N1: Node 1 Data ]
[N2: Node 2 Data ]
[N3: Node 3 Data ]

You can even make the N1 as a variable and can assign it from the master node to your desired salve node.

i started to think about ways to verify the data but then i was stopped at trying to send a structure over tcp with ESPASyncTCP. i can send string but i have not figured out how to send a struct.

here in this code i posted below you can see the sample struct i created and the original code i commented out then i add my line of code to send the struct but it wont compile,

part i modified,

struct sampleStruct {
  int var1;
  byte Array[20];
  float var2;
  unsigned long var3;
  unsigned long var4;
  unsigned long var5;
  unsigned long var6;
  unsigned long var7;
  unsigned long var8;
  bool var9;
};
sampleStruct st;
static os_timer_t intervalTimer;

static void replyToServer(void* arg) {
	AsyncClient* client = reinterpret_cast<AsyncClient*>(arg);

	// send reply
	if (client->space() > 32 && client->canSend()) {
//		char message[32];
//		sprintf(message, "this is from %s", WiFi.localIP().toString().c_str());
//		client->add(message, strlen(message));
//		client->send();
client->add(st, sizeof(st));
	}
}

whole code,

#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>

extern "C" {
#include <osapi.h>
#include <os_type.h>
}

#include "config.h"

struct sampleStruct {
  int var1;
  byte Array[20];
  float var2;
  unsigned long var3;
  unsigned long var4;
  unsigned long var5;
  unsigned long var6;
  unsigned long var7;
  unsigned long var8;
  bool var9;
};
sampleStruct st;
static os_timer_t intervalTimer;

static void replyToServer(void* arg) {
	AsyncClient* client = reinterpret_cast<AsyncClient*>(arg);

	// send reply
	if (client->space() > 32 && client->canSend()) {
//		char message[32];
//		sprintf(message, "this is from %s", WiFi.localIP().toString().c_str());
//		client->add(message, strlen(message));
//		client->send();
client->add(st, sizeof(st));
	}
}


/* event callbacks */
static void handleData(void* arg, AsyncClient* client, void *data, size_t len) {
	Serial.printf("\n data received from %s \n", client->remoteIP().toString().c_str());
	Serial.write((uint8_t*)data, len);

	os_timer_arm(&intervalTimer, 2000, true); // schedule for reply to server at next 2s
}

void onConnect(void* arg, AsyncClient* client) {
	Serial.printf("\n client has been connected to %s on port %d \n", SERVER_HOST_NAME, TCP_PORT);
	replyToServer(client);
}


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

	// connects to access point
	WiFi.mode(WIFI_STA);
	WiFi.begin(SSID, PASSWORD);
	while (WiFi.status() != WL_CONNECTED) {
		Serial.print('.');
		delay(500);
	}

	AsyncClient* client = new AsyncClient;
	client->onData(&handleData, client);
	client->onConnect(&onConnect, client);
	client->connect(SERVER_HOST_NAME, TCP_PORT);

	os_timer_disarm(&intervalTimer);
	os_timer_setfn(&intervalTimer, &replyToServer, client);
}

void loop() {

}