Added Pagianation for Sending Payload
- Cut of 1 Byte for Pagination - Now we can send 256 Datapackages without chaning any logic from sending and receiving - We have 250 Bytes from ESP NOW - We use 10 Byte for Meta Data, 1 for Pagination - We have 239 Bytes for Real Payload
This commit is contained in:
parent
6d383e43b4
commit
7f1369f1cf
10
main/main.c
10
main/main.c
@ -13,6 +13,7 @@
|
||||
#include "nvs_flash.h"
|
||||
#include "portmacro.h"
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -71,7 +72,6 @@ void espnow_data_prepare(espnow_send_param_t *send_param) {
|
||||
espnow_data_t *buf = (espnow_data_t *)send_param->buffer;
|
||||
|
||||
ESP_LOGI(tag, "Example_Data_SIZE: %u, send_param_len: %d\n", sizeof(espnow_data_t), send_param->len);
|
||||
|
||||
assert(send_param->len >= sizeof(espnow_data_t));
|
||||
|
||||
buf->type = IS_BROADCAST_ADDR(send_param->dest_mac)
|
||||
@ -81,10 +81,8 @@ void espnow_data_prepare(espnow_send_param_t *send_param) {
|
||||
buf->seq_num = s_espnow_seq[buf->type]++;
|
||||
buf->crc = 0;
|
||||
buf->magic = send_param->magic;
|
||||
buf->payload.isMaster = isMaster;
|
||||
/* Fill all remaining bytes after the data with random values */
|
||||
/* esp_fill_random(buf->payload,
|
||||
send_param->len - sizeof(espnow_data_t)); */ // wieso sollte ich das mit random daten füllen
|
||||
buf->unionPage = UNION_STATUS;
|
||||
buf->realPayload.status.isMaster = isMaster;
|
||||
|
||||
buf->crc = esp_crc16_le(UINT16_MAX, (uint8_t const *)buf, send_param->len);
|
||||
}
|
||||
@ -161,7 +159,7 @@ int espnow_data_parse(uint8_t *data, uint16_t data_len, uint8_t *state,
|
||||
buf->crc = 0;
|
||||
crc_cal = esp_crc16_le(UINT16_MAX, (uint8_t const *)buf, data_len);
|
||||
|
||||
if(buf->payload.isMaster) {
|
||||
if(buf->realPayload.status.isMaster) {
|
||||
ESP_LOGI(tag, "Recived Data from Master");
|
||||
} else {
|
||||
ESP_LOGI(tag, "Recived Data from Slave");
|
||||
|
||||
25
main/main.h
25
main/main.h
@ -1,6 +1,7 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include <stdint.h>
|
||||
#define Master_SlavePin 23
|
||||
#define MAX_PAYLOAD_SIZE 250
|
||||
|
||||
@ -42,9 +43,23 @@ enum {
|
||||
EXAMPLE_ESPNOW_DATA_MAX,
|
||||
};
|
||||
|
||||
enum {
|
||||
UNION_STATUS,
|
||||
UNION_SENSORDATA,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
bool isMaster;
|
||||
} __attribute__((packed)) payloadData;
|
||||
} __attribute__((packed)) payloadStatus;
|
||||
|
||||
typedef struct {
|
||||
uint8_t dataPoint;
|
||||
} __attribute__((packed)) payloadSensorData;
|
||||
|
||||
union realPayload {
|
||||
payloadStatus status;
|
||||
payloadSensorData sensorData;
|
||||
};
|
||||
|
||||
/* User defined field of ESPNOW data in this example. */
|
||||
typedef struct {
|
||||
@ -54,11 +69,13 @@ typedef struct {
|
||||
uint16_t crc; // CRC16 value of ESPNOW data.
|
||||
uint32_t magic; // Magic number which is used to determine which device to
|
||||
// send unicast ESPNOW data.
|
||||
payloadData payload; // Real payload of ESPNOW data.
|
||||
uint8_t unionPage;
|
||||
union realPayload realPayload; // Real payload of ESPNOW data.
|
||||
} __attribute__((packed)) espnow_data_t;
|
||||
|
||||
static_assert(sizeof(espnow_data_t) <= MAX_PAYLOAD_SIZE, "payloadData struct is too big to be sent in one part, keep it under 250 Bytes!");
|
||||
|
||||
static_assert(sizeof(espnow_data_t) <= MAX_PAYLOAD_SIZE,
|
||||
"payloadData struct is too big to be sent in one part, keep it "
|
||||
"under 250 Bytes!");
|
||||
|
||||
typedef struct {
|
||||
bool unicast; // Send unicast ESPNOW data.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user