OPLA IoT Kit - Solar system tracker - no JSON output

Hello!

When creating the demo project "Solar system tracker" (https://opla.arduino.cc/opla/module/iot-starter-kit-maker/lesson/04-solar-system-tracker) I don´t get the JSON data.

Output in monitor is:

Starting connection to server...

connected to server

HTTP/1.0 408 Request Time-out
Cache-Control: no-cache
Connection: close
Content-Type: text/html

The display of the device is pink with text "Update complete Data from: null"

I´ve already tried a lot but get no result.

Code is:

#include <WiFiNINA.h>
#include <Arduino_JSON.h>
 
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
 
char ssid[] = "mywlan"; //  your network SSID (name)
char pass[] = "***";//  your network PASSWORD ()
 
String bodyName;
String planet;
String explorerName;
String explorerDate;
double gravity;
double density;
 
char *planets[] = {"jupiter", "io", "europe",
                   "callisto", "mars", "mercury",
                   "venus", "terre", "uranus", "neptune",
                   "saturne", "phoebe", "ganymede", "titan",
                   "pluton", "triton", "titania", "charon", "ariel",
                   "tethys", "protee"
 
                  };
 
int status = WL_IDLE_STATUS;
char server[] = "api.le-systeme-solaire.net";
 
WiFiClient client;

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial);
 
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    // wait 1 seconds for connection:
    delay(1000);
  }
  Serial.println("Connected to wifi");
 
  //Initialize the  carrier
  CARRIER_CASE = false;
  carrier.begin();
  carrier.display.setRotation(0);
 
}

void loop() {
  delay(100);
  carrier.Buttons.update();
 
  if (carrier.Button0.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_MAGENTA);
    carrier.display.setCursor(30, 60);
    carrier.display.setTextColor(ST77XX_WHITE);
    carrier.display.setTextSize(2);
    carrier.display.print("Searching");
    delay(500);
    carrier.display.print(".");
    delay(500);
    carrier.display.print(".");
    delay(500);
    carrier.display.print(".");
    delay(500);
    carrier.display.print(".");
 
    planetUpdate();
 
    carrier.display.fillScreen(ST77XX_MAGENTA);
    carrier.display.setCursor(30, 60);
    carrier.display.setTextColor(ST77XX_WHITE);
    carrier.display.setTextSize(2);
    carrier.display.print("Update complete");
    carrier.display.setCursor(20, 90);
    carrier.display.print("Data from: ");
    carrier.display.setCursor(20, 130);
    carrier.display.print(bodyName);
 
  }
 
  if (carrier.Button1.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_RED);
    carrier.display.setCursor(20, 60);
    carrier.display.setTextColor(ST77XX_WHITE);
    carrier.display.setTextSize(2);
    carrier.display.print(bodyName);
    carrier.display.setCursor(20, 90);
    carrier.display.print("Is a moon of: ");
    carrier.display.setCursor(20, 110);
    carrier.display.println(planet);
    delay(500);
  }
  if (carrier.Button2.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_GREEN);
    carrier.display.setCursor(20, 60);
    carrier.display.setTextColor(ST77XX_WHITE);
    carrier.display.setTextSize(2);
    carrier.display.print(bodyName);
    carrier.display.setCursor(20, 90);
    carrier.display.print("Discovered by: ");
    carrier.display.setCursor(20, 110);
    carrier.display.println(explorerName);
    carrier.display.setCursor(20, 130);
    carrier.display.print("Date: ");
    carrier.display.print(explorerDate);
    delay(500);
  }
  if (carrier.Button3.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_BLUE);
    carrier.display.setCursor(20, 60);
    carrier.display.setTextColor(ST77XX_WHITE);
    carrier.display.setTextSize(2);
    carrier.display.print(bodyName);
    carrier.display.setCursor(20, 90);
    carrier.display.print("Gravity is: ");
    carrier.display.setCursor(20, 130);
    carrier.display.print(gravity);
    carrier.display.print(" m/s2");
    delay(500);
  }
  if (carrier.Button4.onTouchDown()) {
    carrier.display.fillScreen(ST77XX_BLACK);
    carrier.display.setCursor(20, 60);
    carrier.display.setTextColor(ST77XX_WHITE);
    carrier.display.setTextSize(2);
    carrier.display.print(bodyName);
    carrier.display.setCursor(20, 110);
    carrier.display.print("Density is: ");
    carrier.display.print(density);
    carrier.display.print(" g/cm3");
  }
  
  String line = "";
  while (client.connected()) {
    line = client.readStringUntil('\n');
    Serial.println(line);
    JSONVar myObject = JSON.parse(line);
 
    bodyName = JSON.stringify(myObject["englishName"]);
    planet = JSON.stringify(myObject["aroundPlanet"]["planet"]);
    explorerName = JSON.stringify(myObject["discoveredBy"]);
    explorerDate = JSON.stringify(myObject["discoveryDate"]);
    gravity = myObject["gravity"];
    density = myObject["density"];
    
    delay(100);
 
    if (line.startsWith("{")) {
      break;
    }
  }
}

void planetUpdate() {
 
  int randomPlanet = random(0, 20);
 
  Serial.println("\nStarting connection to server...");
  Serial.println(server);
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected to server");
    // Make a HTTP request:
   /* client.print("GET ");
    client.print("/rest/bodies/");
    client.print(planets[randomPlanet]);
    client.println(" HTTP/1.0");*/
    
    client.println("GET /rest/bodies/mars HTTP/1.0");
 
    client.println("Host: api.le-systeme-solaire.net");
    client.println("Connection: close");
    client.println();
  } else {
    Serial.println("unable to connect");
  }
  delay(1000);
  
  
  
}

Any idea what may cause this?

The server you're connecting to is has a rather short timeout (a few seconds). But nevertheless I would expect that code to be able to get the response given you have a working internet connection and your display is not blocking too long.

I don't see why your response parsing code is not part of the planetUpdate() routine. Move it there and add a

client.flush();

after you sent the request.