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

UDP.parsePacket() is returning wrong values #263

Open
1 task done
mardecker opened this issue Feb 20, 2025 · 3 comments
Open
1 task done

UDP.parsePacket() is returning wrong values #263

mardecker opened this issue Feb 20, 2025 · 3 comments
Labels
no-issue-activity pending It is a feature/bug-fix request, currently on hold

Comments

@mardecker
Copy link

Boards

BW16

External Hardware

Ai-Thinker BW16 (RTL8720DN)

Hardware Configuration

just connected to WPA2/WPA3 Wifi

Version

latest master (checkout manually)

IDE Name

Arduino 1.8.19

Operating System

Ubuntu

Auto Flash Mode

Disable

Erase All Flash Memory (4MB)

Disable

Standard Lib

Arduino_STD_PRINTF

Upload Speed

1500000

Description

I was trying to use a CoAP Library when I noticed, that no CoAP packages were recieved correctly. It seems like, that the funktion udp.parsePacket() just returns a solid 1, when Data is recieved.

Sketch

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <coap-simple.h>

#define MAX_SEND_SIZE 256
#define MAX_RECV_SIZE 1500
#define UDP_SERVER_PORT 5683

char ssid[] = "wland";       // dein WLAN-SSID
char password[] = "Asylantrag2020";  // dein WLAN-Passwort

IPAddress coapServer(192, 168, 178, 82);  // CoAP-Server-IP
int coapPort = 5683;  // CoAP-Standard-Port

WiFiUDP udp;  // UDP-Objekt für CoAP
Coap coap(udp, MAX_SEND_SIZE);  // CoAP-Client-Instanz

// **Callback-Funktion vorher deklarieren**
void callback(CoapPacket &packet, IPAddress ip, int port);

void setup() {
    Serial.begin(115200);
    
    // WLAN-Verbindung herstellen
    Serial.print("Verbinde mit WLAN...");
    WiFi.begin(ssid, password);
    
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println(" Verbunden!");

    // CoAP-Client starten
    coap.start();

    // Antwort-Callback setzen
    coap.response(callback);

    
    // CoAP GET Anfrage senden
    Serial.println("Sende CoAP GET-Anfrage...");
    coap.get(coapServer, coapPort, "temp/1");
}

void loop() {
    int packetSize = udp.parsePacket();
    if (packetSize) {
        Serial.print("UDP-Paket empfangen: ");
        Serial.println(packetSize);
        
        char packetBuffer[512];  // Puffer für eingehende Daten
        int len = udp.read(packetBuffer, 512);
        if (len > 0) {
            packetBuffer[len] = '\0';  // String terminieren
        }

        Serial.print("Daten: ");
        Serial.println(packetBuffer);
    }

    coap.loop();  // CoAP-Verarbeitung
}
// **Callback für die Antwort des CoAP-Servers**
void callback(CoapPacket &packet, IPAddress ip, int port) {
    Serial.print("Antwort erhalten von: ");
    Serial.println(ip);
    
    Serial.print("Port: ");
    Serial.println(port);

    Serial.print("Daten: ");
    for (int i = 0; i < packet.payloadlen; i++) {
        Serial.print((char)packet.payload[i]);
    }
    Serial.println();
}

Error/Debug Message

I got no explicit message.
I just debugged the data via Serial.println (see provided Ino)

Reproduce remarks

if you add CoAP Simple Library, you have to change ' #include "Udp.h" ' to ' #include "WiFiUdp.h" '.

I have checked online documentation, FAQ, GitHub Wiki and existing/closed issues.

  • I confirm I have checked online documentation, FAQ, GitHub Wiki and existing/closed issues.
@mardecker mardecker added the pending It is a feature/bug-fix request, currently on hold label Feb 20, 2025
@mardecker
Copy link
Author

Same Problem with the WiFiUdpSendReceiveString example

@fastfourier666
Copy link

I am finding this too, although udp.read does return the correct length.

Copy link

github-actions bot commented Mar 9, 2025

This issue is stale because it has been open for 14 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-issue-activity pending It is a feature/bug-fix request, currently on hold
Projects
None yet
Development

No branches or pull requests

2 participants