Http GET requests *with* iot cloud (33 nano iot)

I (hope) I'm just being a complete idiot, but I can't find a single way of actually getting HTTP requests to work with the iot cloud. Correct me if I'm wrong, but its somewhat the first thing I'd expect an iot device to do, and with arduino I was hoping for it to just work.

After a few weeks of trying random stuff on and off, I've made enough progress that it can just fail to connect now :slight_smile:
(I got past all the millions of compile fails with the crappy non functional libraries)

I'm currently running out of a new unmodified (apart from the main file) arduino IOT cloud "thing". I need to still be in the iot cloud, because I've got other things running through it.

here is my code so far, please help asap

#include "thingProperties.h"

uint8_t httpGet(char result[], int len, char* server, char* path, uint16_t read_timeout) {
  // Prepare the client
  WiFiSSLClient client;
  
  // Connect to the server
  Serial.print(F("Attempt to connect "));
  Serial.print(server);
  Serial.println(F(":443 ..."));
  
  if(client.connect(server, 443)) {
    // Connection established
    Serial.println(F("Connection to server established"));
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("User-Agent: ArduinoWiFiNINA/1.4.0");
    client.println("Connection: close");
    client.println();
  } else {
    Serial.println(F("Unable to connect to the server"));
    return 2;
  }

  // Listen and manage a timeout
  unsigned long startTime = millis();
  bool received = false;

  int index = 0;
  while ((millis() - startTime < read_timeout) && !received) {
    while(client.available() && index < len - 1) {
      received = true;
      char c = client.read();
      Serial.write(c);
      result[index] = c;
    }
  }


  if(!received) {
    Serial.println(F("Read timeout"));
    return 1;  
  } else {
    // Return OK
    return 0;
  }
}

void setup() {
  Serial.begin(9600);
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  setDebugMessageLevel(4);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  
  char url[256]; // Adjust size as needed
  strcpy(url, "/v1/forecast?latitude=50.0000&longitude=-0.0000&hourly=temperature_2m,relative_humidity_2m,precipitation,weather_code,wind_speed_10m&forecast_days=1");
  
  char response[512];
  httpGet(response, 512, "api.open-meteo.com", url, 1000); 

  Serial.print("Response: ");
  Serial.println(strlen(response));
  Serial.println(response);
  delay(1000);
}

this is the vague "stuff doesn't work" output mess of combinations of all the connections failing that it outputs currently
Attempt to connect api.open-meteo.com:443 ...

Unable to connect to the server

Response: 1

,

ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to iot.arduino.cc:8883

ArduinoIoTCloudTCP::handle_ConnectMqttBroker 3 connection attempt at tick time 387694

Attempt to connect api.open-meteo.com:443 ...

Unable to connect to the server

Response: 1

,

WiFi.status(): 6

Have you uploaded the root SSL certificates for the hosts you are trying to reach using the appropriate plugin provided in the Arduino IDE?

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