Can't read api result on Arduino Uno

Hello all, I'm new to Arduino and I'm facing a problem. I have an Arduino Uno that calls an API on a local server, and it connects two it. However, it gets an empty result even though I test my API on postman and it works perfectly fine. on the serial I get an empty string Here is my API response on Postman:

{
    "access:": 0
}

Here is my Arduino code:

#include <Ethernet.h>
#include <HttpClient.h>
#include <ArduinoJson.h> 

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 
IPAddress ip(10, 10, 10, 100); 
IPAddress server(10, 10, 10, 102); 
EthernetClient ethernetClient;
HttpClient httpClient(ethernetClient, server, 8000);

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac, ip);
  while (Ethernet.begin(mac) != 1) {
    Serial.println("Failed to configure Ethernet");
    delay(5000);
  }
  Serial.println("Connected to Ethernet");
}

void loop() {
  String url = "/pob/"; 
  httpClient.get(url);

  String response = httpClient.responseBody(); 
  
  DynamicJsonDocument jsonDoc(1024); 
  deserializeJson(jsonDoc, response); 

  int value = jsonDoc["access"];
  Serial.println(value);
  

}

Any ideas where my problem is?

DynamicJsonDocument jsonDoc(1024);

Arduino Uno has 2048 bytes of RAM in total. Asking to allocate 1024 bytes at run time is direct way to program crash.

Json is a great, but way too memoryconsuming for Uno. Try to change the board to ESP8266, ESP32 or RP2040 W

I have moved your topic to an appropriate forum category @shwanaya.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an essential part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Thanks a lot. Net time will do.

1 Like

Thanks for your recommendation. I will definitely look into that. But do you know what is wrong with my code?

Lacking of the memory.
see the post#2

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