Cannot get data from arduino json UDP

Hi, I feel really stupid need to post this question.

I'm trying to get value from a Json UDP string. The string, serialized using ArduinoJson looks in the UDP receive buffer like:

However, I cannot extract the values (value, lat and lon).
My code below:
#include <ArduinoJson.h>
#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)
IPAddress myIP(192, 168, 68, 77);
IPAddress remoteIP(192, 168, 68, 78); // Top unit
unsigned short remotePort = 2390; // Top unit port
unsigned int localPort = 2290; // local port to listen on
const int capacity = JSON_OBJECT_SIZE(3);
StaticJsonDocument doc;

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:
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);

// attempt to connect to WiFi network:
WiFi.config(myIP); // configur static IP address
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to 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:

Serial.println("Conn=ected to WiFi");
Serial.print("capacity is: ");

Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:


void loop() {
// Use Assistant | ArduinoJson 6 to compute the capacity.

// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize) {
Serial.print("Received packet of size ");
Serial.print("From ");
IPAddress remoteIp = Udp.remoteIP();
Serial.print(", port ");

// read the packet into packetBufffer
int len =, 255);
if (len > 0) {
  packetBuffer[len] = 0;
Serial.print("packetlengt is: ");

DeserializationError error = deserializeMsgPack(doc, packetBuffer);
// char[] = {"value":42,"lat":48.74801,"lon":2.293491}

Serial.print("Json error is: ");
if (error) {
Serial.print(F("deserializeJson() failed with code: "));
// Log
// Serial.print(F("Sending to "));
// Serial.print(remoteIP);
// Serial.print(F(" on port "));
// Serial.println(remotePort);
// serializeJson(doc, Serial);

// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(remoteIP, remotePort);
//serializeJson(doc, Udp);

const char* retrievedValue = doc["value"];
long retrievedLat = doc["lat"];
long retrievedLon = doc["lon"];
Serial.print("Value is: ");
Serial.print("Lat is: ");
Serial.print("Lon is: ");


void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");

// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(" dBm");
void waitForSerial(){
while (!Serial.available()) {

You have to put this in code tags </> to avoid bits of your code getting lost or misinterpreted. In this case, you meant:

char ReplyBuffer[]  = “acknowledged”; // a string to send back

Ah, ok. Thanks’.

Haven’t actually checked that yet.

My main problem is reading the value from the received Json-file. I do not get any of the values lut from the ”packetBuffer” to my Json doc.

Any hela on that is appreciated.

_/) P-L

Maybe I didn't explain myself very well. Because you did not put your entire code in code tags, when making your post, it is not very readable and important information is incorrectly presented. Can you correct this.
Here is a guide which should help: How to get the best out of this forum

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.