Giter VIP home page Giter VIP logo

Comments (16)

ArminPP avatar ArminPP commented on September 27, 2024

Hello,

I would highly recommend this fork https://github.com/leodesigner/espNowFloodingMeshLibrary2 because unfortunately this library is no longer maintained.
leodesigner's examples and the updated library also are working on PlatformIO.

from espnowfloodingmeshlibrary.

marcopiai avatar marcopiai commented on September 27, 2024

Thanks
I have tried with the fork, i'm using the flooding mesh master/slave example.
for the master i need to make arrangment in library but in slave there are a lot of compiling error.
I will try with the leodesigner example (pir_sensor), but i need to cut some parts of code.

Marco

from espnowfloodingmeshlibrary.

ArminPP avatar ArminPP commented on September 27, 2024

This is a slave demo with https://github.com/arttupii/espNowFloodingMeshLibrary/issues/url:
(I cut it out from one of my test programs)

#include <Arduino.h>

#include "espNowFloodingMeshLibrary2/EspNowFloodingMesh.h"

struct MeshProbe_struct
{
  char name[15]; // name of the mesh slave
  uint64_t TimeStamp;
  float MPU_Temperature;
};
MeshProbe_struct MeshProbe;

unsigned char secredKey[] = {0xB8, 0xF0, 0xF4, 0xB7, 0x4B, 0x1E, 0xD7, 0x1E, 0x8E, 0x4B, 0x7C, 0x8A, 0x09, 0xE0, 0x5A, 0xF1}; // AES 128bit
unsigned char iv[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};

int ESP_NOW_CHANNEL = 1; 
int bsid = 0x010101;
const int ttl = 3;

void espNowFloodingMeshRecv(const uint8_t *data, int len, uint32_t replyPrt)
{
  static bool blink = false;
  if ((blink = !blink))
  {
    digitalWrite(D9, HIGH);
  }
  else
  {
    digitalWrite(D9, LOW);
  }

  Serial.print("<=== received Data :");
  Serial.println((const char *)data);

}

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

  uint64_t chipid;
  char chipname[256];
  chipid = ESP.getEfuseMac();
  sprintf(chipname, "TempHum%04X", (uint16_t)(chipid >> 32));

  pinMode(D9, OUTPUT);  // onboard LED

  espNowFloodingMesh_secredkey(secredKey);
  espNowFloodingMesh_setAesInitializationVector(iv);
  espNowFloodingMesh_disableTimeDifferenceCheck();
  espNowFloodingMesh_setToMasterRole(false, ttl);
  espNowFloodingMesh_setToBatteryNode(false);
  espNowFloodingMesh_RecvCB(espNowFloodingMeshRecv);

  espNowFloodingMesh_begin(ESP_NOW_CHANNEL, bsid, true); // disconnect wifi true!

  espNowFloodingMesh_ErrorDebugCB([](int level, const char *str)
                                  {
                            if (level == 0) {
                               Serial.printf("ERROR %s", str);
                               
                            }
                            if (level == 1) {
                               Serial.printf("WRN   %s", str);
                               
                            }
                            if (level == 2) {
                               Serial.printf("INFO  %s", str);
                              
                            } });
}

void loop()
{
  espNowFloodingMesh_loop();

  static uint64_t iCount = 0;

  static unsigned long MeshLoopPM = 0;
  unsigned long MeshLoopCM = millis();
  if (MeshLoopCM - MeshLoopPM >= 2000) // sending mesh values every 2 seconds

  {

    strlcpy(MeshProbe.name, "TempHum", sizeof(MeshProbe.name));
    MeshProbe.MPU_Temperature = (millis() * 0.001);
    MeshProbe.TimeStamp = iCount++;

    espNowFloodingMesh_send((uint8_t *)&MeshProbe, sizeof(MeshProbe), ttl); // set ttl to 3

    Serial.printf("(%llu) from %s: temp: %f\n",
                  MeshProbe.TimeStamp,
                  MeshProbe.name,
                  MeshProbe.MPU_Temperature);

        // -------- MeshLoop end --------
    MeshLoopPM = MeshLoopCM;
  }
}

from espnowfloodingmeshlibrary.

ArminPP avatar ArminPP commented on September 27, 2024

This is a master demo with https://github.com/arttupii/espNowFloodingMeshLibrary/issues/url:
(I cut it out from one of my test programs, untested, should work)

#include <Arduino.h>
#include "esp_wifi.h"
#include "espNowFloodingMeshLibrary2/EspNowFloodingMesh.h"

struct MeshProbe_struct
{
  char name[15]; // name of the mesh slave
  uint64_t TimeStamp;
  float MPU_Temperature;
};
MeshProbe_struct MeshProbe;

unsigned char secredKey[] = {0xB8, 0xF0, 0xF4, 0xB7, 0x4B, 0x1E, 0xD7, 0x1E, 0x8E, 0x4B, 0x7C, 0x8A, 0x09, 0xE0, 0x5A, 0xF1}; // AES 128bit
unsigned char iv[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};

int ESP_NOW_CHANNEL = 1; 
int bsid = 0x010101;
const int ttl = 3;

void espNowFloodingMeshRecv(const uint8_t *data, int len, uint32_t replyPrt)
{
  if (len > 0)
  {
    MeshProbe_struct *MeshProbe = (MeshProbe_struct *)data;
    Serial.printf("from: %s %llu\n", MeshProbe->name, MeshProbe->TimeStamp);
  }
}
void setup()
{
  Serial.begin(115200);

  int8_t power;
  // esp_wifi_set_max_tx_power(20);
  esp_wifi_get_max_tx_power(&power);
  Serial.printf("wifi power: %d \n", power);

  uint64_t chipid;
  char chipname[256];
  chipid = ESP.getEfuseMac();
  sprintf(chipname, "Master%04X", (uint16_t)(chipid >> 32));

  // Set device in AP mode to begin with
  espNowFloodingMesh_RecvCB(espNowFloodingMeshRecv);
  espNowFloodingMesh_secredkey(secredKey);
  espNowFloodingMesh_disableTimeDifferenceCheck();
  espNowFloodingMesh_setAesInitializationVector(iv);

  espNowFloodingMesh_setToMasterRole(true); // Set ttl to 3.

  espNowFloodingMesh_ErrorDebugCB([](int level, const char *str)
                                  {
                            if (level == 0) {
                               Serial.printf("ERROR %s", str);
                            }
                            if (level == 1) {
                               Serial.printf("WRN   %s", str);
                            }
                            if (level == 2) {
                               Serial.printf("INFO  %s", str);
                            } });

  espNowFloodingMesh_begin(ESP_NOW_CHANNEL, bsid, true);
}

void loop()
{
  static unsigned long counter = 0;
  static unsigned long m = millis();
  if (m + 2000 < millis())
  {

    char Message[35]{};
    snprintf(Message, sizeof(Message), "Master: %lu", counter);

    espNowFloodingMesh_sendAndHandleReply((uint8_t *)&Message, sizeof(Message), 3, [](const uint8_t *data, int len)
                                          {
        if(len>0) {
          Serial.print(">");
          Serial.println((const char*)data);
        } });
    m = millis();
    counter++;
  }

M5.update();
  espNowFloodingMesh_loop();
  // delay(10);
}

from espnowfloodingmeshlibrary.

marcopiai avatar marcopiai commented on September 27, 2024

Many thanks, tomorrow i will test it.

Marco

from espnowfloodingmeshlibrary.

marcopiai avatar marcopiai commented on September 27, 2024

Dear Armin, your sample works fine, many thanks
just 2 arrangement in your code to work for every other developer interested
in slave code i have added #define D9 2 (for example, to have a blink on a led connected to pin 2)
in master code i have comment out MS.update i think that is not in this portion of code)

I would like to ask you another information, if you can:
i need to send about 512 byte, but i can only sent at least 229 bytes
i have made this:
//define array of bytes
uint8_t Data[230];

//popolate array in setup
for(int i=0;i <sizeof(Data);i++){
Data[i] = i;
}

//and send in delayed loop
espNowFloodingMesh_send((uint8_t *)&Data, sizeof(Data), ttl);

but over the 229 bytes size array generate error
E (2170) ESPNOW: Invalid argument!

did you know why? the function "espNowFloodingMesh_send" has defined with uint8_t, I thinks that could work until 255 bytes
and also is there away to send up to 512 byes in single sent?

from espnowfloodingmeshlibrary.

ArminPP avatar ArminPP commented on September 27, 2024

Hi Marco,
the packet size of a ESP-Mesh packet is limited to <= 250 bytes, the FloodingMesh Packet size is <= 230 bytes (0...229 items) due to the overhead for encryption and so on, see here: https://github.com/arttupii/espNowFloodingMeshLibrary#message-headers.

You can split your message into two different packets and send them one after the other. (Make sure, that the 1st packet is received properly, before send the 2nd one...)

from espnowfloodingmeshlibrary.

marcopiai avatar marcopiai commented on September 27, 2024

Yes, many thanks, i have founded tha table of byted used.

another little help, i have tryed to change channel ESP_NOW_CHANNEL from 1 to 2 or 5 on both master/slave code, but works only with 1.
where i'm wrong?

i will pay you a pizza, for help!

Marco

from espnowfloodingmeshlibrary.

ArminPP avatar ArminPP commented on September 27, 2024

Depends on...
Are you using WiFi at the same Time?
Than WiFi and ESP-Now must have both the same channel.

Otherwise my code should work with different channels...

BR, Armin

from espnowfloodingmeshlibrary.

marcopiai avatar marcopiai commented on September 27, 2024

from espnowfloodingmeshlibrary.

marcopiai avatar marcopiai commented on September 27, 2024

Dear,
I have tryed, your original code and if i change channel variable ESP_NOW_CHANNEL = 2 in both master/slave code
the terminal show this error:
E (xxx) ESPNOW: Peer channel is not equal to the home channel, send fail!

i don't understand where i'm wrong

Thanks

from espnowfloodingmeshlibrary.

ArminPP avatar ArminPP commented on September 27, 2024

You're right, I forgot something...
I copied the code from old test programs, hence the few fragments that didn't fit.
I have now cleaned up the code a bit and tested it on two ESP32 modules "M5Atom". now everything should work...

This you have to remove if you do not use a M5Atom device: #include <M5Atom.h>

from espnowfloodingmeshlibrary.

ArminPP avatar ArminPP commented on September 27, 2024

Master

#include <M5Atom.h>

#include <Arduino.h>
#include <WiFi.h>
#include "esp_wifi.h"
#include "espNowFloodingMeshLibrary2/EspNowFloodingMesh.h"

struct MeshProbe_struct
{
  char name[15]; // name of the mesh master
  uint64_t TimeStamp;
  float MPU_Temperature;
};
MeshProbe_struct MeshProbe;

unsigned char secredKey[] = {0xB8, 0xF0, 0xF4, 0xB7, 0x4B, 0x1E, 0xD7, 0x1E, 0x8E, 0x4B, 0x7C, 0x8A, 0x09, 0xE0, 0x5A, 0xF1}; // AES 128bit
unsigned char iv[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};

int ESP_NOW_CHANNEL = 11;
int bsid = 0x010101;
const int ttl = 3;

void espNowFloodingMeshRecv(const uint8_t *data, int len, uint32_t replyPrt)
{
  if (len > 0)
  {
    MeshProbe_struct *MeshProbe = (MeshProbe_struct *)data;
    Serial.printf("   >=== received Data from: %s %llu %6.2f\n", MeshProbe->name, MeshProbe->TimeStamp, MeshProbe->MPU_Temperature);
  }
}
void setup()
{
  Serial.begin(115200);
  Serial.println(F("Welcome to ESP-NOW Master"));

  int8_t power;
  // esp_wifi_set_max_tx_power(20);
  esp_wifi_get_max_tx_power(&power);
  Serial.printf("wifi power: %d \n", power);

  uint64_t chipid;
  char chipname[256];
  chipid = ESP.getEfuseMac();
  sprintf(chipname, "Master%04X", (uint16_t)(chipid >> 32));

  espNowFloodingMesh_RecvCB(espNowFloodingMeshRecv);
  espNowFloodingMesh_secredkey(secredKey);
  espNowFloodingMesh_disableTimeDifferenceCheck();
  espNowFloodingMesh_setAesInitializationVector(iv);

  espNowFloodingMesh_setToMasterRole(true); // Set ttl to 3.

  espNowFloodingMesh_ErrorDebugCB([](int level, const char *str)
                                  {
                            if (level == 0) {
                               Serial.printf("ERROR %s", str);
                            }
                            if (level == 1) {
                               Serial.printf("WRN   %s", str);
                            }
                            if (level == 2) {
                               Serial.printf("INFO  %s", str);
                            } });

  espNowFloodingMesh_begin(ESP_NOW_CHANNEL, bsid, true);

  Serial.println(F("WiFi Settings before setting new channel"));
  WiFi.printDiag(Serial); // shows default channel
  ESP_ERROR_CHECK(esp_wifi_set_channel(ESP_NOW_CHANNEL, WIFI_SECOND_CHAN_NONE));
  Serial.println(F("WiFi Settings after setting new channel"));
  WiFi.printDiag(Serial); // shows chosen EspNow channel
}

void loop()
{
  espNowFloodingMesh_loop();

  static uint64_t iCount = 0;

  static unsigned long MeshLoopPM = 0;
  unsigned long MeshLoopCM = millis();
  if (MeshLoopCM - MeshLoopPM >= 2000) // sending mesh values every 2 seconds
  {
    strlcpy(MeshProbe.name, "Master", sizeof(MeshProbe.name));
    MeshProbe.MPU_Temperature = (millis() * 0.001);
    MeshProbe.TimeStamp = iCount++;

    espNowFloodingMesh_send((uint8_t *)&MeshProbe, sizeof(MeshProbe), ttl); // set ttl to 3

    Serial.printf("Send to Slave (%llu) from %s: Temp: %6.2f\n",
                  MeshProbe.TimeStamp,
                  MeshProbe.name,
                  MeshProbe.MPU_Temperature);

    // -------- MeshLoop end --------
    MeshLoopPM = MeshLoopCM;
  }
}

from espnowfloodingmeshlibrary.

ArminPP avatar ArminPP commented on September 27, 2024

Slave

#include <M5Atom.h>

#include <Arduino.h>
#include <WiFi.h>
#include "esp_wifi.h"
#include "espNowFloodingMeshLibrary2/EspNowFloodingMesh.h"

struct MeshProbe_struct
{
  char name[15]; // name of the mesh slave
  uint64_t TimeStamp;
  float MPU_Temperature;
};
MeshProbe_struct MeshProbe;

unsigned char secredKey[] = {0xB8, 0xF0, 0xF4, 0xB7, 0x4B, 0x1E, 0xD7, 0x1E, 0x8E, 0x4B, 0x7C, 0x8A, 0x09, 0xE0, 0x5A, 0xF1}; // AES 128bit
unsigned char iv[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};

int ESP_NOW_CHANNEL = 11;
int bsid = 0x010101;
const int ttl = 3;

void espNowFloodingMeshRecv(const uint8_t *data, int len, uint32_t replyPrt)
{
  MeshProbe_struct *MeshProbe = (MeshProbe_struct *)data;
  Serial.printf("   >=== received Data from: %s %llu %6.2f\n", MeshProbe->name, MeshProbe->TimeStamp, MeshProbe->MPU_Temperature);
}

void setup()
{
  Serial.begin(115200);
  Serial.println(F("Welcome to ESP-NOW Slave"));

  int8_t power;
  // esp_wifi_set_max_tx_power(20);
  esp_wifi_get_max_tx_power(&power);
  Serial.printf("wifi power: %d \n", power);

  uint64_t chipid;
  char chipname[256];
  chipid = ESP.getEfuseMac();
  sprintf(chipname, "TempHum%04X", (uint16_t)(chipid >> 32));

  espNowFloodingMesh_secredkey(secredKey);
  espNowFloodingMesh_setAesInitializationVector(iv);
  espNowFloodingMesh_disableTimeDifferenceCheck();
  espNowFloodingMesh_setToMasterRole(false, ttl);
  espNowFloodingMesh_setToBatteryNode(false);
  espNowFloodingMesh_RecvCB(espNowFloodingMeshRecv);

  espNowFloodingMesh_ErrorDebugCB([](int level, const char *str)
                                  {
                            if (level == 0) {
                               Serial.printf("ERROR %s", str);
                               
                            }
                            if (level == 1) {
                               Serial.printf("WRN   %s", str);
                               
                            }
                            if (level == 2) {
                               Serial.printf("INFO  %s", str);
                              
                            } });

  espNowFloodingMesh_begin(ESP_NOW_CHANNEL, bsid, true); // disconnect wifi true!

  Serial.println(F("WiFi Settings before setting new channel"));
  WiFi.printDiag(Serial); // shows default channel
  ESP_ERROR_CHECK(esp_wifi_set_channel(ESP_NOW_CHANNEL, WIFI_SECOND_CHAN_NONE));
  Serial.println(F("WiFi Settings after setting new channel"));
  WiFi.printDiag(Serial); // shows chosen EspNow channel

}

void loop()
{
  espNowFloodingMesh_loop();

  static uint64_t iCount = 0;

  static unsigned long MeshLoopPM = 0;
  unsigned long MeshLoopCM = millis();
  if (MeshLoopCM - MeshLoopPM >= 2000) // sending mesh values every 2 seconds

  {

    strlcpy(MeshProbe.name, "TempHum", sizeof(MeshProbe.name));
    MeshProbe.MPU_Temperature = (millis() * 0.001);
    MeshProbe.TimeStamp = iCount++;

    espNowFloodingMesh_send((uint8_t *)&MeshProbe, sizeof(MeshProbe), ttl); // set ttl to 3

    Serial.printf("Send to Master (%llu) from %s: temp: %6.2f\n",
                  MeshProbe.TimeStamp,
                  MeshProbe.name,
                  MeshProbe.MPU_Temperature);

    // -------- MeshLoop end --------
    MeshLoopPM = MeshLoopCM;
  }
}

from espnowfloodingmeshlibrary.

marcopiai avatar marcopiai commented on September 27, 2024

YYYYEEEESSS
now works fine.

Many thanks
Marco

from espnowfloodingmeshlibrary.

314159-r avatar 314159-r commented on September 27, 2024

The second error in the opening post:

and: .pio/libdeps/esp32doit-devkit-v1_COM4/EspNowFloodingMesh/wifi802_11.cpp: In function 'void wifi_802_11_send(const uint8_t*, int)': .pio/libdeps/esp32doit-devkit-v1_COM4/EspNowFloodingMesh/wifi802_11.cpp:125:78: error: cannot convert 'esp_interface_t' to 'wifi_interface_t' esp_wifi_80211_tx(ESP_IF_WIFI_STA, buf, sizeof(raw_HEADER) + len+ 2, true); ^ In file included from .pio/libdeps/esp32doit-devkit-v1_COM4/EspNowFloodingMesh/wifi802_11.cpp:4: C:/Users/marco/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/include/esp_wifi/include/esp_wifi.h:984:46: note: initializing argument 1 of 'esp_err_t esp_wifi_80211_tx(wifi_interface_t, const void*, int, bool)' esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);

is due to a bug in wifi802_11.cpp line 125 in this repo.
Or, until fixed also, in line 136 in @leodesigner 's espNowFloodingMeshLibrary2

The enumerator ESP_IF_WIFI_STA is invalid. It should be: WIFI_IF_STA.

from espnowfloodingmeshlibrary.

Related Issues (6)

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.