Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error sending the data #1

Open
Skywalkerf34 opened this issue Aug 8, 2022 · 7 comments
Open

Error sending the data #1

Skywalkerf34 opened this issue Aug 8, 2022 · 7 comments

Comments

@Skywalkerf34
Copy link

Skywalkerf34 commented Aug 8, 2022

Hello,

thanks for this firmware this helps to understand a little more about espnow
I program the transmitter and receiver on tw esp32 dev
I copy the Mac from receiver into the FW for tranmitter (by the way I add now receiver MAC on Receiver FW in setup such to avoid having to run the GetMac before then flash the receiver FW)
Receiver is rebooting every second obviously no receiving)
Transmitter loop on "Error sending the data"

Any idea about what can be the pb ? I try with 2 other Dev board with same result

SCROLLING SERIAL MONITOR IFOUND OUT THIS :
20:34:28.022 -> Succes: Initialized ESP-NOW
20:34:28.022 -> E (334) ESPNOW: Peer interface is invalid
20:34:28.022 -> Failed to add peer

@un0038998
Copy link
Owner

un0038998 commented Aug 8, 2022 via email

@Skywalkerf34
Copy link
Author

Skywalkerf34 commented Aug 8, 2022 via email

@Skywalkerf34
Copy link
Author

Skywalkerf34 commented Aug 8, 2022 via email

@un0038998
Copy link
Owner

un0038998 commented Aug 8, 2022 via email

@Skywalkerf34
Copy link
Author

now this Tx firmware work good

/*
Francis RIQUET for SmartElectronic

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/

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

// REPLACE WITH YOUR RECEIVER MAC Address
uint8_t receiverMacAddress[] = {0xC8, 0xF0, 0x9E, 0x2F, 0x7F, 0x80};
//uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
// Structure to send data
// Must match the receiver structure
typedef struct struct_message {
byte lxAxisValue;
byte lyAxisValue;
byte rxAxisValue;
byte ryAxisValue;

byte switch1Value;
byte switch2Value;
byte switch3Value;
byte switch4Value;
byte switch5Value;
byte switch6Value;
byte switch7Value;
byte switch8Value;
} struct_message;

// Create a struct_message called myData
struct_message myData;

esp_now_peer_info_t peerInfo;

//***********************************************************************************************************************************
//***********************************************************************************************************************************
//This function is used to map 0-4095 joystick value to 0-254. hence 127 is the center value which we send.
//It also adjust the deadband in joystick.
//Jotstick values range from 0-4095. But its center value is not always 2047. It is little different.
//So we need to add some deadband to center value. in our case 1800-2200. Any value in this deadband range is mapped to center 127.
int mapAndAdjustJoystickDeadBandValues(int value, bool reverse)
{
if (value >= 2200)
{
value = map(value, 2200, 4095, 127, 254);
}
else if (value <= 1800)
{
value = (value == 0 ? 0 : map(value, 1800, 0, 127, 0));
}
else
{
value = 127;
}

if (reverse)
{
value = 254 - value;
}
Serial.println(value);
return value;
}
//***********************************************************************************************************************************
//***********************************************************************************************************************************
// callback when data is sent
void OnDataSent(const uint8_t mac_addr, esp_now_send_status_t status) {
Serial.print("\r\nLast Packet Send Status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
//
**********************************************************************************************************************************
//***********************************************************************************************************************************
void setup() {
// Init Serial Monitor
Serial.begin(115200);

// Set device as a Wi-Fi Station
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 Send CB to
// get the status of Trasnmitted packet
esp_now_register_send_cb(OnDataSent);

// Register peer
memcpy(peerInfo.peer_addr, receiverMacAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;

// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
}
//***********************************************************************************************************************************
//***********************************************************************************************************************************
void loop() {
// Set values to send
myData.lxAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(32), false);
myData.lxAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(32), false);
myData.lyAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(33), false);
myData.rxAxisValue = mapAndAdjustJoystickDeadBandValues(analogRead(34), false);
myData.switch1Value = !digitalRead(15);
myData.switch3Value = !digitalRead(17);
myData.switch5Value = !digitalRead(19);
myData.switch6Value = !digitalRead(21);
myData.switch7Value = !digitalRead(22);
myData.switch8Value = !digitalRead(23);

esp_err_t result = esp_now_send(receiverMacAddress, (uint8_t *) &myData, sizeof(myData));
if (result == ESP_OK)
{
Serial.println("Sent with success");
}
else
{
Serial.println("Error sending the data");
}
delay(50);
}

@un0038998
Copy link
Owner

un0038998 commented Aug 9, 2022 via email

@Skywalkerf34
Copy link
Author

Skywalkerf34 commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants