WiFi API Help - Status Code -2

Im trying to make a get request using an Arduino Nano 33 IoT, here is my code:
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h>

WiFiSSLClient wifiClient;
HttpClient client = HttpClient(wifiClient, "https://statsapi.mlb.com", 443);

char ssid[] = "Private"; // your WPA2 enterprise network SSID (name)
char user[] = "Private"; // your WPA2 enterprise username
char pass[] = "Private"; // your WPA2 enterprise password
int status = WL_IDLE_STATUS; // the WiFi radio's status

bool printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI): ");
if (rssi < -5) {
Serial.println("GOOD");
return true;
} else {
Serial.println("BAD");
return false;
}
}

void setup() {
Serial.begin(9600);
while (!Serial) {};

// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
while (true);
}

String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please update the firmware");
}

// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);

// wait 5 seconds for connection:
delay(5000);
}
}
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h>

WiFiSSLClient wifiClient;
HttpClient client = HttpClient(wifiClient, "https://statsapi.mlb.com", 443);

char ssid[] = "Private"; // your WPA2 enterprise network SSID (name)
char user[] = "Private"; // your WPA2 enterprise username
char pass[] = "Private"; // your WPA2 enterprise password
int status = WL_IDLE_STATUS; // the WiFi radio's status

bool printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());

// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI): ");
if (rssi < -5) {
Serial.println("GOOD");
return true;
} else {
Serial.println("BAD");
return false;
}
}

void setup() {
Serial.begin(9600);
while (!Serial) {};

// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
while (true);
}

String fv = WiFi.firmwareVersion();
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
Serial.println("Please update the firmware");
}

// attempt to connect to WiFi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);

// wait 5 seconds for connection:
delay(5000);
}
}
1 Reply
Armed.py
Armed.pyOP4w ago
void loop() {
if (printCurrentNet()) {
Serial.println("making GET request");
client.get("/api/v1/standings?leagueId=103&season=2024&standingsTypes=regularSeason&date=2024-07-04");

// read the status code and body of the response
int statusCode = client.responseStatusCode();
Serial.print("Status code: ");
Serial.println(statusCode);
String response = client.responseBody();
Serial.print("Response: ");
Serial.println(response);
Serial.println("Wait five seconds");
delay(5000);
} else {
update_display_data("**********", 0);
}
update_display();
}
void loop() {
if (printCurrentNet()) {
Serial.println("making GET request");
client.get("/api/v1/standings?leagueId=103&season=2024&standingsTypes=regularSeason&date=2024-07-04");

// read the status code and body of the response
int statusCode = client.responseStatusCode();
Serial.print("Status code: ");
Serial.println(statusCode);
String response = client.responseBody();
Serial.print("Response: ");
Serial.println(response);
Serial.println("Wait five seconds");
delay(5000);
} else {
update_display_data("**********", 0);
}
update_display();
}
And I keep getting -2 as a status code Dont worry about the updating display data, its for an LED matrix that I made. Bump I figured it out. I should have changed the initial link from "https://statsapi.mlb.com" to "statsapi.mlb.com"

Did you find this page helpful?