#ESP32 Now Package sent, but not received. I need someone to verify whether or not my code is wrong

15 messages · Page 1 of 1 (latest)

keen zincBOT
#

@thick iron

File Attachments Not Allowed

For safety reasons we do not allow files with certain file extensions.

summurialeclipse.9290 Said

I know that the problem is either hardware or code. My code is not throwing up errors, but I just want someone else to look at it. I also couldn't tag with other for some reason, my apologies.

Code Formatting

You can share your code using triple backticks like this:
```
YOUR CODE
```

Large Portions of Code

For longer scripts use a code hosting platform like GitHub Gists and share the link here

Ignored these files due to them having disallowed file extensions
  • send_code.ino
  • receive-code.ino
thick iron
#
#include <WiFi.h>
#include <ezButton.h>

//add global variables, defines, etc. here
#define A1 8
unsigned int delaytime = 10;
//---------------------------------------------

//2 ledc attatch, ledc writes

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
    int right;
    int left;
    int bVal;
} struct_message;

// Create a struct_message called myData
struct_message myData;

//espnow function, all loop code goes here instead of in loop
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
  //add loop code below 
  Serial.print("Bytes received: ");
  Serial.println(len);
  Serial.print("Right Speed: ");
  Serial.println(myData.right);
  Serial.print("Left Speed: ");
  Serial.print(myData.left);
  //end loop code
}




void setup() {
  pinMode(A1, OUTPUT);
  // put your setup code here, to run once:
  //Include pinmodes, ledcAttach,etc.



  //Setup for espNow
  Serial.begin(115200);
  Serial.println(1);//Not in other code
  WiFi.mode(WIFI_STA);
  
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  
  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
  // leave empty, put code that would go her into OnDataRecv
  
}```
#
#include <WiFi.h>
#include <ezButton.h>

//add global variables, defines, etc. here
#define A1 8
unsigned int delaytime = 10;
//---------------------------------------------

//2 ledc attatch, ledc writes

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
    int right;
    int left;
    int bVal;
} struct_message;

// Create a struct_message called myData
struct_message myData;

//espnow function, all loop code goes here instead of in loop
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  memcpy(&myData, incomingData, sizeof(myData));
  //add loop code below 
  Serial.print("Bytes received: ");
  Serial.println(len);
  Serial.print("Right Speed: ");
  Serial.println(myData.right);
  Serial.print("Left Speed: ");
  Serial.print(myData.left);
  //end loop code
}




void setup() {
  pinMode(A1, OUTPUT);
  // put your setup code here, to run once:
  //Include pinmodes, ledcAttach,etc.



  //Setup for espNow
  Serial.begin(115200);
  Serial.println(1);//Not in other code
  WiFi.mode(WIFI_STA);
  
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  
  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
  // leave empty, put code that would go her into OnDataRecv
  
}```
#

Both are .ino, first is the sending code. I believe that it works. Second is the receiving code that probably has the problem

south plume
#

lets see

#

So what part works / doesn't? No errors I guess?

thick iron
#

It will compile once then it fails. This happens on both my machine and my teammate's

south plume
#

Compile once then fail at runtime?

thick iron
#

In VSCode with the PlatformIO extension, it works fine

south plume
#

Where does it fail?

thick iron
#

That only happens in the ArduinoIDE

#

recieve: main.main() arduino.cc/arduino-builder/main.go:338 +0x988 arduino-builder returned 2 Error compiling for board ESP32 Dev Module.

#

send:

    arduino.cc/arduino-builder/main.go:338 +0x988
arduino-builder returned 2
Error compiling for board ESP32 Dev Module.```