Hello,
I am attempting to send a monitored value from an Arduino WiFi Rev 2 to a secure REST server. I have tested that the REST request with both CURL and SOAPUI, both of which work correctly. Here is the functioning CURL statement where I've substituted the Arduino SECRETS for the actual values:
curl "https://<SECRET_SERVER>/api/now/table/incident/9c2490731bcc1010da4bfd9c0a4bcbc2"
--request GET
--header "Accept:application/json"
--user <SECRET_AUTHUSER>:<SECRET_AUTHPW>
Here is the code that I'm using to perform this activity:
#include <WiFiNINA.h>
#include <ArduinoHttpClient.h>
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASSWORD;
int status = WL_IDLE_STATUS;
int port = 443;
WiFiClient wifi;
HttpClient client = HttpClient(wifi, SECRET_SERVER, port);
void setup() {
Serial.begin(9600);
Serial.print("Attempting to connect to Network named: ");
Serial.print(ssid);
while (status != WL_CONNECTED) {
status = WiFi.begin(ssid, pass);
delay(1000);
Serial.print(".");
}
Serial.println();
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
IPAddress gateway = WiFi.gatewayIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println("Connecting...");
// Connect to HTTP server
wifi.setTimeout(5000);
if (!wifi.connect(SECRET_SERVER, 443)) {
Serial.println("Connection failed");
return;
}
Serial.println("Connected!");
Serial.println("making GET request");
client.beginRequest();
client.sendHeader("Accept", "application/json");
client.sendBasicAuth(SECRET_AUTHUSER, SECRET_AUTHPW);
client.get("/api/now/table/incident/9c2490731bcc1010da4bfd9c0a4bcbc2");
client.endRequest();
int statusCode = client.responseStatusCode();
String response = client.responseBody();
Serial.print("GET Status code: ");
Serial.println(statusCode);
Serial.print("GET Response: ");
Serial.println(response);
wifi.stop();
}
void loop() {
// not used in this example
}
When I run this code I get the following responses:
Attempting to connect to Network named: <SECRET_SSID>.
SSID: <SECRET_SSID>
IP Address: XXX.XXX.X.XX
Connecting...
Connected!
making GET request
GET Status code: -3
GET Response:
Any suggestions would be greatly appreciated. Thank you in advance!
Bob