ich habe einen Arduino Uno Wifi Rev 2 und benutze das Wifinina Example "WifiUdpSendReceiveString".
/*
WiFi UDP Send and Receive String
This sketch wait an UDP packet on localPort using the WiFi module.
When a packet is received an Acknowledge packet is sent to the client on port remotePort
created 30 December 2012
by dlf (Metodo2 srl)
*/
#include <SPI.h>
#include <WiFiNINA.h>
#include <WiFiUdp.h>
int status = WL_IDLE_STATUS;
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
unsigned int localPort = 2390; // local port to listen on
char packetBuffer[256]; //buffer to hold incoming packet
char ReplyBuffer[] = "acknowledged"; // a string to send back
WiFiUDP Udp;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
Udp.begin(localPort);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remoteIp = Udp.remoteIP();
Serial.print(remoteIp);
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
int len = Udp.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0;
}
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
Im Packetbuffer werden egal wie groß er ist, nur 64 Byte vom empfangenen String gespeichert.
Wobei im Beispiel von Anfang an 256 Byte verwendet werden.
Liegt das an meinem Netzwerk, dass nicht mehr ankommt, oder ist da ein Fehler drin?
Das kommt im Seriellen Monitor an:
16:04:05.999 -> Attempting to connect to SSID: FRITZ!Box 7590 SC
16:04:17.237 -> Connected to WiFi
16:04:17.284 -> SSID: FRITZ!Box 7590 SC
16:04:17.284 -> IP Address: 192.168.178.57
16:04:17.331 -> signal strength (RSSI):-45 dBm
16:04:17.378 ->
16:04:17.378 -> Starting connection to server...
16:04:27.479 -> Received packet of size 681
16:04:27.526 -> From 192.168.178.20, port 63741
16:04:27.573 -> Contents:
16:04:27.573 -> {"MessageType":"Event","MessageVerb":"Shot","Sequential":true,"R
Und so würde der String weitergehen:
{"MessageType":"Event","MessageVerb":"Shot","Sequential":true,"Ranges":1,"Objects":[....
Eine Warnung kommt nach dem kompilieren:
avrdude: WARNING: invalid value for unused bits in fuse "fuse5", should be set to 1 according to datasheet
Egal wie, die falsche Anzahl bei der Paketlänge deutet auf ein grundlegendes Problem (evtl. in der WiFiNina-Firmware) hin, ich setze sie selbst nicht ein, kann dazu also keine Erfahrung mitteilen.
Und einen Payload von 1058 Zeichen kannst Du nicht mit einem Puffer von 256 empfangen.
Was passiert, wenn Du mit dem Paketsender 50 Bytes überträgst? Wird dann die richtige Länge angezeigt? Wenn ja, dann erhöhe die Länge schrittweise, bis die Länge falsch wird bzw. der Text abgeschnitten wird.
Pardon ich habe 49 verschickt, aber auch die Packetsize ist dann 49. Und wenn ich 65 verschicke ist die Packetsize auch 65 aber nur 64 werden angezeigt. Bei 63 kommen 63 an und 63 ist die Packetsize.
17:35:26.061 -> Received packet of size 49
17:35:26.107 -> From 192.168.178.20, port 50786
17:35:26.154 -> Länge: 49
17:35:26.154 -> Contents:
17:35:26.154 -> {"MessageType":"Event","MessageVerb":"Shot","Sequ
17:35:53.933 -> Received packet of size 65
17:35:53.933 -> From 192.168.178.20, port 50786
17:35:53.979 -> Länge: 64
17:35:53.979 -> Contents:
17:35:54.026 -> {"MessageType":"Event","MessageVerb":"Shot","Sequential":true,"R
17:37:27.157 -> Received packet of size 63
17:37:27.157 -> From 192.168.178.20, port 50786
17:37:27.204 -> Länge: 63
17:37:27.204 -> Contents:
17:37:27.204 -> {"MessageType":"Event","MessageVerb":"Shot","Sequential":true,"
Ich glaube noch immer, das nach 64bytes ein \0 oder anderes Control drin ist, was das Ende der Übernahme des Inhaltes bewirkt oder das payload dort zwangsgetrennt wird.
Die Größe wird ja richtig erkannt, der Inhalt verworfen.
Wie sieht das denn auf der Senderseite Codemäßig aus?
Der String wird aus einer Software herausgesendet, da habe ich keinen Zugriff auf den Code.
Die Versuche habe ich aus der Software "PacketSender" verschickt.
Und die großen Packets wurden aus der eigentlichen Software, die den JSON-Broadcast als Schnitstelle verwendet, gesendet.
// read the packet into packetBufffer
int len = Udp.read(packetBuffer, 255);
if (len > 0)
{
Serial.println("Contents:");
for (byte b = 0; b < packetsize - 1; b++)
Serial.print(packetBuffer[b], HEX); Serial.print(' ');
if (b % 8 == 0) Serial.println();
}
Serial.println();
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received