Hi Sara !! Hope they are ok.
I’m having trouble when I implement the item 3.3 – Send Data to the Database: Sensor Readings with DHT22 sensor, as the following concatenation error has appeared:
Serial.println(“PATH: ” + fbdo.dataPath());
more than one operator “+” matches these operands:C/C++(350)
main.cpp(77, 25): function “operator+(const StringSumHelper &lhs, const String &rhs)” (declared at line 174 of “C:\Users\Sucen-DCV\.platformio\packages\framework-arduinoespressif32\cores\esp32\WString.h”)
main.cpp(77, 25): function “operator+(MB_String &&lhs, const MB_String &rhs)” (declared at line 2048 of “C:\Users\Sucen-DCV\Documents\PlatformIO\Projects\Firebase_Send\.pio\libdeps\heltec_wifi_lora_32_V2\Firebase Arduino Client Library for ESP8266 and ESP32\src\json\MB_String.h”)
main.cpp(77, 25): operand types are: const char [7] + String
Thanks
Look the full skech
#include <Arduino.h>
#include <WiFi.h>
#include <Wire.h>
#include <Firebase_ESP_Client.h>
#include <DHT.h>
// Provide the token generation process info.
#include “addons/TokenHelper.h”
// Provide the RTDB payload printing info and other helper functions.
#include “addons/RTDBHelper.h”
// Insert your network credentials
#define WIFI_SSID “”
#define WIFI_PASSWORD “”
// Insert Firebase project API Key
#define API_KEY “”
// Insert Authorized Email and Corresponding Password
#define USER_EMAIL “”
#define USER_PASSWORD “”
// Insert RTDB URLefine the RTDB URL
#define DATABASE_URL “”
// Define Firebase objects
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
// Variable to save USER UID
String uid;
// Variables to save database paths
String databasePath;
String tempPath;
String humPath;
String presPath;
//define GPIO do DHT22
#define pinDHT 16
#define tipoDHT DHT22
// DHT22 sensor
DHT dht(pinDHT, tipoDHT);
float temperatura;
float umidade;
float pressure;
// Timer variables (send new readings every three minutes)
unsigned long sendDataPrevMillis = 0;
unsigned long timerDelay = 180000;
// Initialize WiFi
void initWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(“Connecting to WiFi ..”);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(‘.’);
delay(1000);
}
Serial.println(WiFi.localIP());
Serial.println();
}
// Write float values to the database
void sendFloat(String path, float value){
if (Firebase.RTDB.setFloat(&fbdo, path.c_str(), value)){
Serial.print(“Writing value: “);
Serial.print (value);
Serial.print(” on the following path: “);
Serial.println(path);
Serial.println(“PASSED”);
Serial.println(“PATH: ” + fbdo.dataPath());
Serial.println(“TYPE: ” + fbdo.dataType());
}
else {
Serial.println(“FAILED”);
Serial.println(“REASON: ” + fbdo.errorReason());
}
}
void setup() {
Serial.begin(115200);
// Initialize DHT22 sensor
dht.begin();
initWiFi();
// Assign the api key (required)
config.api_key = API_KEY;
// Assign the user sign in credentials
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;
// Assign the RTDB URL (required)
config.database_url = DATABASE_URL;
Firebase.reconnectWiFi(true);
fbdo.setResponseSize(4096);
// Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h
// Assign the maximum retry of token generation
config.max_token_generation_retry = 5;
// Initialize the library with the Firebase authen and config
Firebase.begin(&config, &auth);
// Getting the user UID might take a few seconds
Serial.println(“Getting User UID”);
while ((auth.token.uid) == “”) {
Serial.print(‘.’);
delay(1000);
}
// Print user UID
uid = auth.token.uid.c_str();
Serial.print(“User UID: “);
Serial.println(uid);
// Update database path
databasePath = “/UsersData/” + uid;
// Define database path for sensor readings
// –> UsersData/<user_uid>/sensor/temperature
tempPath = databasePath + “/sensor/temperature”;
// –> UsersData/<user_uid>/sensor/humidity
humPath = databasePath + “/sensor/humidity”;
// –> UsersData/<user_uid>/sensor/pressure
presPath = databasePath + “/sensor/pressure”;
}
void loop(){
// Send new readings to database
if (Firebase.ready() && (millis() – sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0)){
sendDataPrevMillis = millis();
// Get latest sensor readings
temperatura = dht.readTemperature();
umidade = dht.readHumidity();
// Send readings to database:
sendFloat(tempPath, temperatura);
sendFloat(humPath, umidade);
}
}
🇧🇷
Hi.
Can you please share your code using github gist or pastebin?
So that the formatting is not messed up and I can test the code.
Thank you.
Regards,
Sara
Hi Sara,
I upload the same sketch into the arduino IDE and it worked fine. I think the problem is in my visual studio. Do you have any tips to fix it. Follow the github link of the files: Your Repositories (github.com)
I’m not sure what might be the issue.
What does your platformio.ini file look like?
Regards
Sara
[env:heltec_wifi_lora_32_V2]
platform = espressif32
board = heltec_wifi_lora_32_V2
framework = arduino
monitor_speed = 115200
lib_deps =
  mobizt/Firebase Arduino Client Library for ESP8266 and ESP32@^4.2.7
  adafruit/Adafruit Unified Sensor@^1.1.7
  adafruit/DHT sensor library@^1.4.4
Are you using the same library versions in Arduino IDE?
Maybe there is some incompatibility between library versions…
Sorry. The libraries Firebase is same, but adafruit libraries aren’t equals versions. How to put the same version in the VS.
Hi again.
I tried your code, and even though Intelisense marks the “+” as an error, the code compiles just fine.
Did you try compiling the code?
Regards,
Sara