call to ‘HTTPClient::begin’ declared with attribute error: obsolete API, use ::begin(WiFiClient, url)


  • Hi,
    i have a problem in :

    //Hier wird der Wert an die Smarthome-Umgebung übertragen
    if (sender.begin(“http://makesmart-server:51828/?accessoryId=temperatur&value=” + String(temperature))){

    i recive this message

    call to ‘HTTPClient::begin’ declared with attribute error: obsolete API, use ::begin(WiFiClient, url)

    can somebody help mi, thanks
    Renato


  • It seems that you have to pass in your wifiClient like:

    if (sender.begin(wifiClient, "http://makesmart-server:51828/?accessoryId=temperatur&value=" + String(temperature))){
      // ...
    }
    

    Maybe there was an update in the library or the issue is somewhere else.
    Could you share your whole code?


  • Thanks very much, but there is another problem in the same line:

    //Hier wird der Wert an die Smarthome-Umgebung übertragen
    if (sender.begin(wifiClient, “http://makesmart-server:51828/?accessoryId=temperatur&value=” + String(temperature))){

    now receive this message:
    extended character “ is not valid in an identifier


  • @renato Because these “ are not double quotes. Use ".

    Share your whole code that we can see how your client is named. 👍🏻


  • Yes thank you, I had thought this and I corrected the error but I had not seen that before ‘http’ there was another wrong double quotes.

    unfortunately there is another problem

    // Wenn alles abgeschlossen ist, wird die Verbindung wieder beendet
    sender.end();
    }else {

    I receive this message:
    expected unqualified-id before ‘else’

    …without you I would not be able to compile this sketch


  • Share your whole code! And please use code tags if you post. 👍


  • Hi
    I took the complete sketch from this page,

    https://makesmart.net/homekit-thermometer-diy-esp8266-d1-mini/#Einbidung-in-das-Smarthome-Homebridge

    WLAN TERMOMETER GET-Request
    GET-Request an einen HTTP-Server
    Created by cooper, 2020

    but when I load it on Arduino IDE and I do a verification I get many mistakes and I am not capable of correcting them, unfortunately I know little Java language, I am starting now, I have little experience, sorry . I copy sketches that are useful and I use them, everything is fine, sometimes not. This sketch is good for me
    Thank you


  • @renato I tested it right now. Copied the code 1:1 - it works. So maybe you have some mistakes in our own code. Share the while thing otherwise nobody can help you.


  • Let’s start with order
    first I copied the sketches from the page:

    https://makesmart.net/homekit-thermometer-diy-esp8266-d1-mini/

    /*
        WLAN TERMOMETER GET-Request
        GET-Request an einen HTTP-Server
        Created by cooper, 2020
        makesmart.net
    */
    
    #include <ESP8266WiFi.h>
    #include <ESP8266HTTPClient.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #define ONE_WIRE_BUS 2
    
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    
    HTTPClient sender;
    
    // WLAN-Daten
    const char* ssid = "WLAN_SSID";
    const char* password = "WLAN_PASSWD";
    
    //Messintervall in Sekunden
    int wait = 5;
    
    //Temperatur
    float temperature;
    
    
    void push(){
    
      //Hier wird der Wert an die Smarthome-Umgebung übertragen
      
      if (sender.begin("http://makesmart-server:51828/?accessoryId=temperatur&value=" + String(temperature))){
    
        // HTTP-Code der Response speichern
        int httpCode = sender.GET();
       
    
        if (httpCode > 0) {
          
          // Anfrage wurde gesendet und Server hat geantwortet
          // Info: Der HTTP-Code für 'OK' ist 200
          if (httpCode == HTTP_CODE_OK) {
    
            // Hier wurden die Daten vom Server empfangen
    
            // String vom Webseiteninhalt speichern
            String payload = sender.getString();
    
            // Hier kann mit dem Wert weitergearbeitet werden
             // ist aber nicht unbedingt notwendig
            Serial.println(payload);
            
            
            
          }
          
        }else{
          // Falls HTTP-Error
          Serial.printf("HTTP-Error: ", sender.errorToString(httpCode).c_str());
        }
    
        // Wenn alles abgeschlossen ist, wird die Verbindung wieder beendet
        sender.end();
        
      }else {
        Serial.printf("HTTP-Verbindung konnte nicht hergestellt werden!");
      }
    
    }
    
    
    void setup() {
      Serial.begin(115200);
      
      WiFi.begin(ssid, password);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(200);
        Serial.print(".");
      }
    
      Serial.println("Verbunden!");
      wait = wait * 1000;
      sensors.begin();
      
    }
    
    
    void loop() {
      
      sensors.requestTemperatures();
      Serial.print(sensors.getTempCByIndex(0));
      Serial.println(" °C");
      
      temperature = sensors.getTempCByIndex(0);
      push();
      delay(wait);
    
    }
    

    At the line 34

    if (sender.begin("http://makesmart-server:51828/?accessoryId=temperatur&value=" + String(temperature))){
    

    ArduinoINO reports an error

    ‘HTTPClient::begin’ declared with attribute error: obsolete API, use ::begin(WiFiClient, url)

    So I added (line 13)

    #include <WiFiClient.h>
    

    and edited ex line 34 now line 35, this is the whole schetch:

    /*
        WLAN TERMOMETER GET-Request
        GET-Request an einen HTTP-Server
        Created by cooper, 2020
        makesmart.net
    */
    
    #include <ESP8266WiFi.h>
    #include <ESP8266HTTPClient.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #define ONE_WIRE_BUS 2
    #include <WiFiClient.h>
    
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature sensors(&oneWire);
    
    HTTPClient sender;
    
    // WLAN-Daten
    const char* ssid = "WLAN_SSID";
    const char* password = "WLAN_PASSWD";
    
    //Messintervall in Sekunden
    int wait = 5;
    
    //Temperatur
    float temperature;
    
    
    void push(){
    
      //Hier wird der Wert an die Smarthome-Umgebung übertragen
      
     if (sender.begin(WiFiClient, "http://makesmart-server:51828/?accessoryId=temperatur&value=" + String(temperature))){
     
    
        // HTTP-Code der Response speichern
        int httpCode = sender.GET();
       
    
        if (httpCode > 0) {
          
          // Anfrage wurde gesendet und Server hat geantwortet
          // Info: Der HTTP-Code für 'OK' ist 200
          if (httpCode == HTTP_CODE_OK) {
    
            // Hier wurden die Daten vom Server empfangen
    
            // String vom Webseiteninhalt speichern
            String payload = sender.getString();
    
            // Hier kann mit dem Wert weitergearbeitet werden
             // ist aber nicht unbedingt notwendig
            Serial.println(payload);
            
            
            
          }
          
        }else{
          // Falls HTTP-Error
          Serial.printf("HTTP-Error: ", sender.errorToString(httpCode).c_str());
        }
    
        // Wenn alles abgeschlossen ist, wird die Verbindung wieder beendet
        sender.end();
        
      }else {
        Serial.printf("HTTP-Verbindung konnte nicht hergestellt werden!");
      }
    
    }
    
    
    void setup() {
      Serial.begin(115200);
      
      WiFi.begin(ssid, password);
    
      while (WiFi.status() != WL_CONNECTED) {
        delay(200);
        Serial.print(".");
      }
    
      Serial.println("Verbunden!");
      wait = wait * 1000;
      sensors.begin();
      
    }
    
    
    void loop() {
      
      sensors.requestTemperatures();
      Serial.print(sensors.getTempCByIndex(0));
      Serial.println(" °C");
      
      temperature = sensors.getTempCByIndex(0);
      push();
      delay(wait);
    
    }
    
    

    Now at the line 35 Arduino report:

    expected primary-expression before ‘,’ token

    help me thanks


  • Which board do you use?

    As I said before. I copied the code and it works for me.

    #include <ESP8266WiFi.h>
    #include <ESP8266HTTPClient.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #define ONE_WIRE_BUS 2
    #include <WiFiClient.h>
    

    You already have a WiFi Client imported: #include <ESP8266WiFi.h>.

    Maybe you can tell which board do you use and which version of libraries / arduino ide.
    This sketch is meant to be for ESP8266 boards.


  • I use a

    WeMos D1 Mini ESP8266 ESP-12F

    But I have the report

    “expected primary-expression before ‘,’ token”

    During the check


  • I also deleted

    #include <WiFiClient.h>


  • Which Arduino / ESP Version do you use?

    For me it’s:
    Arduino IDE: 1.8.13
    ESP8266: 2.7.4

    You can find ESP8266 Boardversion under Tools -> Board -> Boards manager -> Search for ESP8266

    Maybe there was an update or you are outdated.


  • For me ArduinoIDE 1.8.15

    ESP8266 board: 3.0.0

    I tried

    LOLIN (WEMOS) D1 mini(clone) - Generic EPS 8266 Module - NodeMCU 1.0 (ESP 12E Module)

    but I have always had the same result


  • Now I download Arduino IDE: 1.8.13 and I try


  • I trie: nothing has changed (unfortunately)


  • @renato try to use older esp Version. Arduino IDE Version shouldn’t matter here I think.

    ESP8266 Version 2.7.4 as cooper said. Maybe you can try this?


  • Good idea but it is not possible, now I use Arduino IDE: 1.8.13 but the possible choice of ESP8266 Version is only the version.3.0.0, previously I renamed tho old folder “Arduino” that of the precedent Arduino IDE 1.8.15installed, so that Arduino IDE: 1.8.13 shuld have it own folder, without interference


  • I managed to set ESP8266 Version 2.7.4, (still little beginner’s practice), set IP address, installed plugin, changed config.json, now everything works. Thank you all

Ähnliche Themen

  • 3
  • 1
  • 9
  • 9
  • 1