espnow - does OnDataSent guarante packet to be fully received in unicast

smarq8
Posts: 7
Joined: Sat Mar 06, 2021 5:33 pm

espnow - does OnDataSent guarante packet to be fully received in unicast

Postby smarq8 » Sat Apr 02, 2022 9:33 pm

In case of unicast then what exatcly OnDataSent mean? Is it "receiver receive message (hardware)" or "receiver receive message (hardware) and process OnDataRecv (application)"? If unicast use ACK and does not care about OnDataRecv then whats the point of ACK?

For example my transmitter send stream of 28bytes at 1kHZ, rarely its not capable to transmitt so its buffered with FIFO and then there is sequence of 250,250,32,28,28 bytes, in this case my receiver receive only 250,28,28 seqence so there are 2 missing pockets. Also its begin missing only when "Serial.write(data,len);" is active. Im wonder how even OnDataRecv might be missing as it is called from higher prio task than my SerialNow_USB_passthru.

Code: Select all

// transmitter
xTaskCreatePinnedToCore(SerialNowTaskTX,"SerialNowTaskTX",XT_STACK_MIN_SIZE*3,NULL,4,&taskHandleTX,0);

static void OnDataSent(const uint8_t *MAC, esp_now_send_status_t status) {
    if(status==ESP_NOW_SEND_FAIL){
        Serial.printf("something went wrong on sending data\n");
    }
    xSemaphoreGive(esp_now_send_mutex);
}

static void SerialNowTaskTX(void *p){
    uint8_t dataToSend[ESP_NOW_MAX_DATA_LEN];
    size_t dataMaxLen = sizeof(dataToSend);
    while(1){
        size_t len = bufTX.available();
        if( len>=dataMaxLen ){
            len = len>dataMaxLen ? dataMaxLen : len;
            bufTX.pop(dataToSend,len);
            xSemaphoreTake(esp_now_send_mutex,portMAX_DELAY);
            esp_err_t result = esp_now_send(NULL, dataToSend, len);
        } else {
            delay(1);
        }
    }
    vTaskDelete(NULL);
}

Code: Select all

// receiver
static IRAM_ATTR int OnDataRecv(const uint8_t *MAC, const uint8_t *incomingData, int len) {
    for(int i=0;i<4;i++){
        if(compareMAC(MAC,myDev[i].mac)){
            client[i].fifo.push(incomingData,len);
            xTaskNotifyGive( SerialNow_USB_passthru_task );
        }
    }
}

Code: Select all

// retransmission
xTaskCreatePinnedToCore(SerialNow_USB_passthru,"SerialNow_USB_passthru",4096,NULL,3,&SerialNow_USB_passthru_task,0);

void IRAM_ATTR SerialNow_USB_passthru(void *p){
    const size_t dataLen = 4096;
    static uint8_t data[dataLen];
    while(1){
        size_t len;
        ulTaskNotifyTake(pdTRUE,pdMS_TO_TICKS(1));
        for(int i=0;i<4;i++){
            if((len=client[i].fifo.available())>0){
                len = len>dataLen?dataLen:len;
                client[i].fifo.pop(data,len); // internally guearded by semaphore\
                Serial.printf("FACE:FIFO %u %u %u %u %u\n",myDevId,i,len,checkSum(data,len));
                Serial.write(data,len); // retransmission to USB 1M baud rate
            }
        }
    }
    vTaskDelete(NULL);
}

A001FF
Posts: 12
Joined: Sat Apr 02, 2022 3:41 pm

Re: espnow - does OnDataSent guarante packet to be fully received in unicast

Postby A001FF » Wed Apr 06, 2022 4:48 pm

OnDataSent , "status" parameter == ESP_NOW_SEND_SUCCESS means the pair answered with ACK.

Who is online

Users browsing this forum: No registered users and 77 guests