The error is here:
expected unqualified-id before '{' token
Program:
#include<Arduino.h>
#include<WiFi.h>
#include<Firebase_ESP_Client.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"
#define WIFI_SSID " My ssid "
#define WIFI_PASSWORD " My password"
#define API_KEY "AIzaSyAnwoF810DeaZfK17a6CKxq-R4z0TKO0XM"
#define DATABASE_URL " https://kontrollere-to-led-default-rtdb.europe-west1.firebasedatabase.app"
#define LED1_PIN 12
#define LED2_PIN 14
#define LDR_PIN 36
#define PWMChannel 0
const int freq = 5000;
const int resolution = 8;
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;
unsigned long sendDataPrevMillis = 0;
bool signupOK = false;
int ldrData = 0;
float voltage = 0.0;
int pmwValue = 0;
bool ledstatus = false;
void setup() {
pinMode(LED2_PIN, OUTPUT);
ledcSetup(PWMChannel, freq, resolution);
ledcAttachPin(LED1_PIN, PWMChannel);
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();
config.api_key = API_KEY;
config.database_url = DATABASE_URL;
if (Firebase.signUp(&config, &auth, "", "")) {
Serial.println("signUp OK");
signupOK = true;
} else {
Serial.printf("%s\n", config.signer.signupError.message.c_str());
}
config.token_status_callback = tokenStatusCallback;
Firebase.begin(&config, &auth);
Firebase.reconnectWiFi(true);
}
void loop(); {
if (Firebase.ready() && signupOK && (millis() - sendDataPrevMillis > 5000 || sendDATAPrevMillis == 0)) {
sentDataPrevMillis = millis();
//--------------------------Store data to a RTDB -----
ldrData = analogRead(LDR_PIN);
voltage = (float)analogReadMilliVolts(LDR_PIN) / 1000;
if (Firebase.RTDB.setInt(&fbdo, "Sensor/ldr_data", ldrData)) {
Serial.println();
Serial.print(ldrData);
Serial.print(" - successfully saved to:" + fbdo.dataPath());
Serial.print(" (" + fbdo.dataType() + ")");
} else {
Serial.print("FAILED:" + fbdo.errorReason());
}
if (Firebase.RTDB.setFloat (&fbdo, "Sensor/voltage",voltage)) {
Serial.print(voltage));
Serial.print(" - succesfully saved to:" + fbdo.dataPath());
Serial.println("(" + fbdo.dataType() + ")");
} else {
Serial.println ("FAILED: " + fbdo.errorReason());
}
// ------------------------------- READ from a RTDB to control devices attached to the ESP32
if (Firebase.RTDB.getInt(&fbdo, "LED/analog")) {
if (fbdo.dataType() == "int") {
pwmValue = fbdo.intData();
Serial.println("Successful Read from" + fbdo.dataPath() + ":" + pwmValue + "(" + fbdo.dataType() + ")");
ledcWrite(PWMchannel, pwmValue);
}
} else {
Serial.println("FAILED:" + fbdo.errorReason());
}
if (Firebase.RTDB.getBool(&fbdo, "LED/digital")); {
if (fbdo.dataType() == "boolean") {
ledStatus = fbdo.boolData();
Serial.println("Successful Read from RTDB" + fbdo.dataPath() + ":" + ledStatus + "(" + fbdo.dataType() + ")");
digitalWrite(LED2_PIN, ledStatus);
}
} else {
Serial.println("FAILED:" + fbdo.errorReason());
}
}
}