'HTTPClient::begin' declared with attribute error: obsolete API

complete noob with a new feather huzzah and trying to send data from an htu21 to domoticz

with this code i get the obsolete api error

i tried substituting

use ::begin(WiFiClient, host, port, uri)

but i get a bunch more errors eg: uri not defined etc

anyone see what i'm doing wrong :slight_smile: ?

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

#include <Wire.h>
#include "Adafruit_HTU21DF.h"

const char* ssid     = "xxxxxx";
const char* password = "xxxxxx";
const char* host = "192.168.1.150";
const int   port = 8080;
const int   watchdog = 10000; // Frequency of sending data to Domoticz
unsigned long previousMillis = millis(); 

Adafruit_HTU21DF htu = Adafruit_HTU21DF();
HTTPClient http;

void setup() {
  Serial.begin(115200);
  Serial.println("HTU21D-F test");

  if (!htu.begin()) {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
  
  Serial.setDebugOutput(true);  
  Serial.println("Connecting Wifi...");

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
   
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.print(WiFi.localIP()); 
}

int value = 0;

void loop() {
  unsigned long currentMillis = millis();

  if ( currentMillis - previousMillis > watchdog ) {
    previousMillis = currentMillis;

    if(WiFi.status() != WL_CONNECTED) {
      Serial.println("WiFi not connected !");
    } else {  
      Serial.println("Send data to Domoticz");
      
    float temp = htu.readTemperature();
    float humidity = htu.readHumidity();
    float zero = 0;

        String url = "/json.htm?type=command&param=udevice&idx=22&nvalue=0&svalue=";
        url += String(temp); url += ";";
        url += String(humidity); url += ";";
        url += String(zero);
     
        sendDomoticz(url);
      }
    }
  }


void sendDomoticz(String url){
  Serial.print("connecting to ");
  Serial.println(host);
  Serial.print("Requesting URL: ");
  Serial.println(url);
  http.begin(host, port, url);
  int httpCode = http.GET();
    if (httpCode) {
      if (httpCode == 200) {
        String payload = http.getString();
        Serial.println("Domoticz response "); 
        Serial.println(payload);
      }
    }
  Serial.println("closing connection");
  http.end();
}

see the examples of the HTTPClient library

thanks to twitter i got an answer

i added

WiFiClient client;

& then swapped in

http.begin(client, host, port, url);

1 Like

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