Juan_Antonio’s ESP32 examples, Need Help

Thank you,
like I said if i use:
IPAddress local_IP(192, 168, 1, 115);
IPAddress gateway(192, 168, 1, 1);
it wont connect to my router.

I will try your eample with:
IPAddress local_IP(192, 168, 0, 115);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //opcional
IPAddress secondaryDNS(8, 8, 4, 4); //opcional

and let you know if it works.
Mike.

You must know the gateway, ssid and password of your Router.

Run in Windows

ipconfig to get gateway

ok, it shows 0.xx in all fields
so this should be my settings right?

IPAddress local_IP(192, 168, 0, 115);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //opcional
IPAddress secondaryDNS(8, 8, 4, 4); //opcional

https://www.google.com/search?q=ipconfig+how+get+gateway&sxsrf=ALeKk02dJivnngBpAucADG1Qk5DTDQ7Itw:1603645661199&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjao-zPndDsAhWHZd8KHX11DdwQ_AUoA3oECBAQBQ&biw=1280&bih=611

Looks like Juan has identified the cause of your main issue.

Note that using procedures that return a value negate the use of using delays - the script continues when the procedure has finished it's task, be that 1 second or 1 year.

ok using ipconfig i get this as the gateway:
192.168.0.1

so i changed my setings to this:
IPAddress local_IP(192, 168, 0, 115);
IPAddress gateway(192, 168, 0, 2);

I can turn the led on/off fine, but ESP-Now still reports:
Delivery Status: fail
Mike.

Areyou saying that ESP-Now is reporting:
Delivery Status: ok or that you can just control the led?

I can controll the led fine it is ESP-Now that keeps reporting:
Delivery Status: fail
Thanks mike.

The Web Server worked for me, the ESP32_NOW I have not tried it because I have never used it.

Try this with Master - Slave

Ok i have no problem with the web server working, it is getting ESP-now to work with it.

Thank you very much for all your time.
Mike.

If you have the kindness and the time, it should only take a few min.

If you have a 2 ESP32 boards or a ESP32 and a ESP8266

If you load my original code at the top of my post into a ESP32

And load this code into another ESP32 to be the ESP-Now receiver:

#include <WiFi.h>
#include <esp_wifi.h>
#include <esp_now.h>

uint8_t CustomMacAddress = {0x20, 0xAE, 0xA4, 0x20, 0x0D, 0x20};

typedef struct now_struct {
int d1 = 123; // fake test data
int d2 = 456; // fake test data
}
now_struct;
now_struct NowData;

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

WiFi.mode(WIFI_STA);
esp_wifi_set_mac(ESP_IF_WIFI_STA, &CustomMacAddress[0]);

if (esp_now_init() != ESP_OK) {return;}

esp_now_register_recv_cb(OnDataRecv);

}

void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&NowData, incomingData, sizeof(NowData));

Serial.print("Bytes received: ");
Serial.println(len);

Serial.print("D1: "); Serial.println(NowData.d1);
Serial.print("D2: "); Serial.println(NowData.d2);

Serial.println();
}

void loop() {

}

or if you don't have another ESP32 load this code into a ESP8266

#include <ESP8266WiFi.h>
#include <espnow.h>

uint8_t CustomMacAddress = {0x20, 0xAE, 0xA4, 0x20, 0x0D, 0x20};

typedef struct now_struct {
int d1;
int d2;
}
now_struct;
now_struct NowData;

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

WiFi.mode(WIFI_STA);
wifi_set_macaddr(STATION_IF, &CustomMacAddress[0]);

if (esp_now_init() != 0) {return;}

esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
esp_now_register_recv_cb(OnDataRecv);

}

void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
memcpy(&NowData, incomingData, sizeof(NowData));

Serial.print("Bytes received: ");
Serial.println(len);

Serial.print("D1: "); Serial.println(NowData.d1);
Serial.print("D2: "); Serial.println(NowData.d2);
Serial.println();
}

void loop() {

}

Then watch the serial monitor on the ESP32 sender you will see:
Delivery Status: fail

Comment out the WiFi.begin(ssid, password);

Then reload it you will see:
Delivery Status: ok

Thanks,
Mike.

Thanks Chris,
My main issue is not getting the server to work and control the LED, it is getting ESP-Now to work with it.

Yes, I am aware the script continues when the procedure has finished.

That is why I used elapsedMillis.h (a more advanced way to use none-blocking delays than Milliseconds elapsed)
And switch (Case) as a sort of State Machine to go threw each step one at a time, before allowing the next chunk of code to run.

Thank you for your input.

Mike.

That's good practise :sunglasses:

Having done that, with Procedures, I can't see how your setup would fail given that you can successfully run each comms individually - your idea of switching between them should work.

Ok I got it to work the way I wanted, by taking a different approach:

I decided to send the data by Bluetooth from the App to the ESP32.
Then have the ESP32 send the data to the slave ESP boards using ESP-Now.

When certain events are triggered that require an Email to be sent, I use Web1 Post Text to a PHP send Email script.

It seems to be working fine.

I will post a new topic with the PHP Email Script, for anyone else who would like to use in their app.

Thank you to everyone, who took the time to respond to my post, your input has helped me in many ways.

Mike.

1 Like

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