Issue with libraries but where ?

Hi All,

I'm struggling with this code whose aim is to get temperature from DS18B20 and to stream it to mqtt server.
Arduino IDE is 1.8.13
Libraries are up to date

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Streaming.h>

#define SLEEP_DELAY_IN_SECONDS  30
#define ONE_WIRE_BUS            2      // DS18B20 data

const char* ssid = "xxxx";      // Nom du wifi
const char* password = "xxxx";    // Mot de passe wifi

const char* mqtt_server = "192.168.x.x";   // Adresse IP du brovker MQTT
const char* mqtt_username = "jeedom";     // User MQTT
const char* mqtt_password = "";    // Password MQTT
const char* mqtt_topic = "temp";   // Nom du topic MQTT

WiFiClient espClient;
PubSubClient client(espClient);

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);

char temperatureString[6];

void setup() {
  // setup serial port
  Serial.begin(115200);

  // setup WiFi
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);

  // setup OneWire bus
  DS18B20.begin();
}

void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (unsigned int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("ESP8266Client", mqtt_username, mqtt_password)) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

float getTemperature() {
  Serial << "Requesting DS18B20 temperature..." << endl;
  float temp;
  do {
    DS18B20.requestTemperatures(); 
    temp = DS18B20.getTempCByIndex(0);
    delay(100);
  } while (temp == 85.0 || temp == (-127.0));
  return temp;
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  float temperature = getTemperature();
  // convert temperature to a string with two digits before the comma and 2 digits for precision
  dtostrf(temperature, 2, 2, temperatureString);
  // send temperature to the serial console
  Serial << "Sending temperature: " << temperatureString << endl;
  // send temperature to the MQTT topic
  client.publish(mqtt_topic, temperatureString);
}

// #### OPTIONS ####

  //Serial << "Closing MQTT connection..." << endl;
  //client.disconnect();

  //Serial << "Closing WiFi connection..." << endl;
  //WiFi.disconnect();
  //delay(100);

  //Serial << "Entering deep sleep mode for " << 60 << " seconds..." << endl;
  //ESP.deepSleep(30 * 1000000);

the error code is :

In file included from C:\Users\cedri\OneDrive\Documents\Arduino\temp_\Temp_.ino:5:0:
C:\Users\cedri\OneDrive\Documents\Arduino\libraries\Streaming-6.0.4\src/Streaming.h:51:10: error: redefinition of 'struct std::is_signed<Tp>'
struct is_signed { static const bool value = false; };
^
In file included from c:\users\cedri\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\move.h:57:0,
from c:\users\cedri\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\bits\stl_pair.h:59,
from c:\users\cedri\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\utility:70,
from c:\users\cedri\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\algorithm:60,
from C:\Users\cedri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\cores\esp8266/Arduino.h:238,
from C:\Users\cedri\AppData\Local\Temp\arduino_build_242792\sketch\Temp
.ino.cpp:1:
c:\users\cedri\appdata\local\arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-4-b40a506\xtensa-lx106-elf\include\c++\4.8.2\type_traits:569:12: error: previous definition of 'struct std::is_signed<_Tp>'
struct is_signed
^
Plusieurs bibliothèque trouvées pour "ESP8266WiFi.h"
Utilisé : C:\Users\cedri\OneDrive\Documents\Arduino\libraries\ESP8266WiFi
Non utilisé : C:\Users\cedri\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4\libraries\ESP8266WiFi
Utilisation de la bibliothèque ESP8266WiFi version 1.0 dans le dossier: C:\Users\cedri\OneDrive\Documents\Arduino\libraries\ESP8266WiFi
Utilisation de la bibliothèque PubSubClient version 2.8 dans le dossier: C:\Users\cedri\OneDrive\Documents\Arduino\libraries\PubSubClient
Utilisation de la bibliothèque OneWire version 2.3.5 dans le dossier: C:\Users\cedri\OneDrive\Documents\Arduino\libraries\OneWire
Utilisation de la bibliothèque DallasTemperature version 3.8.0 dans le dossier: C:\Users\cedri\OneDrive\Documents\Arduino\libraries\DallasTemperature
Utilisation de la bibliothèque Streaming-6.0.4 version 6.0.4 dans le dossier: C:\Users\cedri\OneDrive\Documents\Arduino\libraries\Streaming-6.0.4
exit status 1
Erreur de compilation pour la carte Generic ESP8266 Module
[/code]

Hope s.o can help

Why are you using the Streaming.h library on a board that supports standard iostreams?

This is a bug in the Steaming library. It adds declarations to the std namespace, which is not allowed.

Pieter

Thank you PieterP for you quick reply !

May I abuse of your time and ask for the changes I should make in the script to make it work with the std iostreams ?

More to the point, why are you mixing the "Serial.print" and the "Serial <<" techniques in the same sketch?

dr400:
Thank you PieterP for you quick reply !

May I abuse of your time and ask for the changes I should make in the script to make it work with the std iostreams ?

Just like any standard C++ program:

#include <iostream>

void setup() {
  Serial.begin(115200);
  std::cout << "Hello, world!" << std::endl;
}
void loop() {}

The sketch was just a C/P of someone else's program. I had no time to dig into it. Appears I have now ... Thanks for the tips ! Work now !

gfvalvo:
More to the point, why are you mixing the "Serial.print" and the "Serial <<" techniques in the same sketch?

Don't ask me ... ask the owner of the sketch ... Just kidding ... I'm just at the starting point of programing. My bad !