Giter VIP home page Giter VIP logo

esp-now-network-and-wifi-gateway's Introduction

ESP-NOW network + WiFi gateway to the Internet

The objective of this mini-project is to illustrate a communication based on the (connectionless) ESP-NOW protocol between a set of ESP32 senders and an ESP32 receiver, while configuring the receiver as a gateway to the Internet by connecting it to a WiFi router.

Scheme of implementation

This mini-project was born from the observation of an erroneous implementation on the following tutorial, published by Rui and Sara on Random Nerd Tutorials:

ESP32: ESP-NOW Web Server Sensor Dashboard (ESP-NOW + Wi-Fi)

This observation led me to open a discussion on the RNT Lab forum to get the opinion of interested readers. And I'd especially like to thank Lee and Steve for taking the time to discuss the issue with me. We were finally able to identify what was wrong.

The solution was initially published on the Espressif forum by ardcp32, which I thank in passing, and which you will find here.

This mini-project is therefore intended to illustrate the right way to proceed for all readers of Random Nerd Tutorials.

You'll find here the code to be implemented on all ESP-NOW sending nodes, as well as that of the ESP-NOW receiving gateway, which is simultaneously connected to the Internet through a WiFi router.

Note that for this to work, each sender must use the same radio channel as the WiFi router. You can hard-code it, but if your router is configured to automatically switch to the least congested channel, it is best to have a routine that scans available networks and looks for the SSID of your router. This way you can easily identify the channel it is using. So I added this routine in the sender's code.

esp-now-network-and-wifi-gateway's People

Contributors

m1cr0lab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp-now-network-and-wifi-gateway's Issues

Receiver is not a functional gateway to the Internet

If you send a successful HTTP request to a server before receiving data from the sender, in the setup function for instance, it will work fine and you'll get a 200 code.

However, if you add a line in the onReceive() function of the receiver that sends the same HTTP request using your WiFi network (whenever you receive data from the esp32 sender using the same WiFi channel), it will always give you a -1 error code.

Here is an example where the first POST request is sent in setup(), and the two other POST requests are sent in onReceive() function, after receiving data two times :

Sender (does not appear on the image)

Receiver: 192.168.188.120
Server: 192.168.188.230

image

As you can see, the first POST request works fine (frames 105 to 120). Meanwhile, in the two last POST requests the receiver sends [RST, ACK] and does not proceed with sending payload, regardless of how the server is coded. Here is the code I used for receiver and sender:

You can reproduce this issue using the following files:

The code tries to send a GET request to api.github.com before receiving data and every time it receives data in the callback function. Here is the result:

Capture d’écran du 2023-06-28 11-12-23

Note: I had to comment this line peerInfo.ifidx = ESP_IF_WIFI_STA; because it would not compile using Arduino.

Unable to send any data

I was able to connect to my network, but I can't send anything using internet.
I'm using a socket connection, but everytime I call it, I get an error...

The code is the same as the repository, except for the socket connection...
Does anybody had any problems like this?

One sender, many receivers

Never used ESP-NOW before.... Is there a reason this will not work in the opposite direction? I need the sender to be the gateway, broadcasting to a number of receivers every few seconds.

I have modified the code to have the sender be gateway and the receivers pair themselves to it as peers. Both sender and receiver(s) report correct initialization and pairing (receivers) but the receivers never receive a msg. I tried a broadcast send AND specific MAC address with no difference. Happy to contribute my code if this is possible and I can get it to work.

Multiple Router with same SSID

Hey all,

I can confirm that you have to use the same WiFi-Channel for ESPNow-Sender and ESPNow-to-WiFi-Gateways. If you have multiple routers with the same SSID (e.g. in university or company) and you always want to use the best WiFi (so no hardcoded channel) you have to try to send the message on each channel until you get a success reply.

  • Gateway on random channel

`

channel = 1

send = false;

while(!send){

    send = sendOnChannel(channel);

    if(send){

         break;

    }else{

        channel = channel % 13 + 1;

     }

}

`

Compiling error Arduino IDE 2023

The following line of code seems to not be working anymore:
peerInfo.ifidx = ESP_IF_WIFI_STA;

I get the following error

In file included from sketch\ESP_NOW_2.ino.cpp:1:0:
C:\Users\..\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.7\cores\esp32/Arduino.h:194:12: error: 'std::round' has not been declared
 using std::round;
            ^
C:\Users\..\..\Documents\Arduino\..\ESP_NOW_2\ESP_NOW_2.ino: In function 'void initEspNow()':
ESP_NOW_2:139:20: error: cannot convert 'esp_interface_t' to 'wifi_interface_t' in assignment
   peerInfo.ifidx   = ESP_IF_WIFI_STA;
                    ^
Multiple libraries were found for "WiFi.h"
 Used: C:\Users\..\..\..\Arduino15\packages\esp32\hardware\esp32\2.0.7\libraries\WiFi
 Not used: D:\Program Files\Arduino\libraries\WiFi
exit status 1
cannot convert 'esp_interface_t' to 'wifi_interface_t' in assignment

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.