Connect two ESP8266 using serial connection

Hi everyone,

First of all, I would like to thank everyone on this forum for the time you dedicate to us.

I am new, and I have registered to help in any situation I can, and for any problem that may arise in a project I am carrying out.

I am trying to investigate if it's possible to connect two ESP8266 with serial connection using "SoftwareSerial" library, but i just have one ESP8266 right now and i don't find a simulator witch can emulate an ESP8266 board.

All articles i found on Internet explain how to connect an Arduino Uno and an ESP, but not two ESP.

Is this possible? Do you know any simulator i could use?

Thanks!

My experience of using software serial on an ESP8266 is that it doesn't work very well. My understanding is that the cause is that the interrupts that drive the WiFi part of the ESP8266 mess up the serial timing.

Are you aware that you can move (swap) the serial port away from the USB port on an ESP8266? If you put:
Serial.swap();
In your code then the hardware serial port moves to GPIO13 Rx and GPIO15 Tx

Personally I would not use serial to communicate between 2 ESP8266s, they are WiFi devices, so use WiFi to send data between them.

So buy some more! D1 Minis are good and cheap.

Hi Perry, thanks for reply.

My experience of using software serial on an ESP8266 is that it doesn't work very well. My understanding is that the cause is that the interrupts that drive the WiFi part of the ESP8266 mess up the serial timing.

Yes, i think WiFi part mess up the serial timing too.

Cita Are you aware that you can move (swap) the serial port away from the USB port on an ESP8266?

And what advantages can I get if I change the port to USB port? The WiFi part doesn't mess up the serial timing?.

Personally I would not use serial to communicate between 2 ESP8266s, they are WiFi devices, so use WiFi to send data between them.

I have to use communication between two ESP and not use WiFi devices, because one of them is used to ESP-NOW connection and other to connect a network, so i can't to use them to communicate both board with each other. This is the reason i am thinking about serial connection to connect them.

So buy some more! D1 Minis are good and cheap.

I already ordered two more ESP8266 :slight_smile: .

The WiFi code messes with software serial. I am talking about the hardware serial port, which the WiFi code does not interfere with. If you use the hardware serial port the way I suggest you do lose the USB connection, but maybe that does not matter, you have to decide on that.

I have no experience with ESP now but I would have thought it possible to do what you want with WiFi, but you will have to experiment to find what works, I can't really advise you as I have not done what you are trying to do.

As mentioned, ESP-NOW is an option.
Getting Started with ESP-NOW (ESP8266 NodeMCU with Arduino IDE) | Random Nerd Tutorials

I would recommend beginning there and seeing if it's fast enough. The reasoning is that the ESP-NOW protocol is easy to use and specifically designed for these devices. Also, it does not require a router as it is direct connect.

It might not suit every project but it's where I would start.

For some completely inadequately described reason, the OP actually appears to wish to construct a "bridge" between an ESP-NOW system and a standard WiFi service, so it is not a matter of communicating between two ESP modules themselves, but between another two unspecified systems! :astonished:

A block diagram of what you want to do would answer a lot of questions.

Explain this a little further. There's a good chance you're making things more complicated than they need to be.

Hi Koraks

Okay, I will explain this a little further.

I need to do a gateway that connecto several ESP using ESP-NOW (obligatorily) to MQTT(obligatorily), Its obligatorily to use first ESP-NOW and later MQTT, so a i need a gateway that receive all the information about ESP-NOW (input of gateway), convert it, and send all these information to MQTT (network)(output of gateway).

In fact, I need to convert the information that several ESP sends using ESP-NOW, to send using MQTT. To do that, i am going to use an ESP8266 to receive all the information about ESP-NOW (master/slave), and connect this ESP8266 with another ESP8266 to send this information to MQTT.

The reason to use two is because one of them is using ESP-NOW connection, and the other WiFi connection to MQTT. I Just need a method to communicate the two ESP8266 without use WiFi module (because the wifi module is already used).

This is to my final degree project, this is the reason why i have to use this protocol communicatión obligatorily.

Thanks for yout time!

Hi Steve,

Attached in the previous comment.

Thanks!

You could use serial, I2C ,or SPI to get the 2 thingies talking

If you used ESP32's for the ESPNow server and the MQTT sender software serial will not be needed and you'll get faster serial transmissions.

If you use serial then use Serial.swap() as I suggested and connect GPIO15 to GPIO13 on the other ESP8266, don't forget ground (3 wires in total).

Ok, clear @alexgaro5. I think my personal preference would be to connect them via I2C. Mostly because I find it relatively easy to do it this way, but arguable it's not much simpler than a (soft-)USART connection. SPI, as @Idahowalker says - why not? Also a viable option.

Perhaps a distinction can/should be made on the basis of the number of connected sensors and the frequency of updates that you want to send over MQTT, or, in other words, how responsive you want the system to be.

Isn't SPI faster? Is that a necessary factor?

If 2 ESP's are used for the ESPnow server and ESP32 to MQTT connector and SPI is used for communication then use the ESP32 SPI API over the ESP32's Arduino Core. The number of SPI options go way up by using the ESP32's SPI API.

Also, ESP32's have a built in ODBCII module, the ESP32 still requires a ODBCII transceiver. I've got some really good transfer speeds in noisy environments and using long wires.

As Koraks said- this makes the solution way more complex than it needs to be. You don't need ESP-Now at all. But your block diagram would work since ESP NOW allows for a many to one protocol.

But, you don't need the "Send to MQTT" device. The "Receive ESP-NOW" device can publish the MQTT message itself.

What is a "wifi module"?

If I were designing this for a real-world system, I would eliminate the gateway altogether and just have each sensor ESP publish the MQTT message. But that doesn't seem to meet the parameters of the assignment.

Apparently that is the actual deliberate intention of the assignment. :grin:

It's "one of those" educational projects.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.