Arduino Nano 33 IOT Rest API Invocation

Hi,

I got a new Nano 33 IOT board and I tried with basic examples like reading Simple Accelerometer value and Simple Gyroscope from the board. I am now trying to push those values through REST API. But the examples I have referred are for other models but I could not make them work for Nano 33 IoT board possibly because those libraries are not compatible with this board. Can someone please guide me with any reference implementation of a POST method invocation on this board to send the Accelerometer values to cloud. Thank you.

My code is below.

#include <ArduinoHttpClient.h>
#include <WiFiNINA.h>
char ssid[] = "mgmt";
char pass[] = "@ccess";
const char serverName[] = "http://192.168.1.131"; // server in local lan
int port = 10030;

WiFiClient wifi;
HttpClient client = HttpClient( wifi, serverName, port );
int status = WL_IDLE_STATUS;

void setup()
{
Serial.begin( 115200 );
while ( !Serial );
while ( status != WL_CONNECTED )
{
Serial.print( "Attempting to connect to Network named: " );
Serial.println( ssid );
status = WiFi.begin( ssid, pass );
}

Serial.print( "SSID: " );
Serial.println( WiFi.SSID() );
IPAddress ip = WiFi.localIP();
Serial.print( "IP Address: " );
Serial.println( ip );
}

void loop()
{
client.get( "/test/test?testid=23" );
// read the status code and body of the response
String response = client.responseBody();
Serial.print( "Response: " );
Serial.println( response );
int statusCode = client.responseStatusCode();
Serial.print( "Status code: " );
Serial.println( statusCode );

Serial.println( "Wait 30 seconds" );
delay( 5000 );
}

My output in serial monitor

Attempting to connect to Network named: mgmt
SSID: mgmt
IP Address: 192.168.1.104
Response:
Status code: -2

ArduinoHttpClient expects a server name and not an URL.

I thought you wanted to POST data, so why are you using the get method of the library?

The library has a SimplePost example. Have you looked at it?

Thanks for you're reply. That was my mistake in the POST and GET. I was trying different options and pasted the wrong code. Based on your inputs, I have fixed it. It is now working fine and I am able to invoke the rest service from the board. Thanks.