arttupii/espNowFloodingMeshLibrary

error compiling example

marcopiai opened this issue · 16 comments

i'm trying to compile example in platformio
i get this errors:
src/main.cpp: In function 'void setup()':
src/main.cpp:20:43: error: too few arguments to function 'void espNowFloodingMesh_begin(int, int)'
espNowFloodingMesh_begin(ESP_NOW_CHANNEL);
^
In file included from src/main.cpp:3:
.pio/libdeps/esp32doit-devkit-v1_COM4/EspNowFloodingMesh/EspNowFloodingMesh.h:19:10: note: declared here
void espNowFloodingMesh_begin(int channel, int bsid);

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);

can anyone help me?
thanks

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.

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

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;
  }
}

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);
}

Many thanks, tomorrow i will test it.

Marco

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?

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...)

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

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

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

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>

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;
  }
}

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;
  }
}

YYYYEEEESSS
now works fine.

Many thanks
Marco

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.