hi, i just got an error and need to fix it it, can you please help me with it please.
here's the whole code
ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h> // Universal Telegram Bot Library written by Brian Lough: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>
#include "CTBot.h" //Pendeklarasian Library
#define lamp 25
#define LDR 13
CTBot myBot;
TBMessage msg;
String ssid = "xx"; //nama ssid wifi
String pass = "xx"; //password wifi
String token = "xx"; //token bot baru
const int id = xx; //id telegram kalian
void setup() { //Pengaturan Variabel
Serial.begin(9600);
pinMode(lamp,OUTPUT);
pinMode(LDR,INPUT);
Serial.println("Starting TelegramBot...");
myBot.wifiConnect(ssid, pass);
myBot.setTelegramToken(token);
if (myBot.testConnection()) {
Serial.println("Koneksi Bagus");
} else {
Serial.println("Koneksi Jelek");
}
myBot.sendMessage(msg.sender.id, (String)"Untuk Menghidupkan Lampu" +
"\nKirimkan pesan >>> hidup" +
"\n \nUntuk Mematikan Lampu" +
"\nKirimkan pesan >>> mati" +
"\n\nMengecek Kondisi Lampu"+
"\nKirimkan pesan >>> cek"
);
}
void loop() { //Perulangan Programvoid setup() {
int nilai = analogRead(LDR);
int kondisi = 0;
Serial.print("Nilai LDR: ");
Serial.println(nilai);
if (nilai <500) {
digitalWrite(lamp, HIGH); //lampu akan menyala
kondisi = 1;
}
else {
digitalWrite(lamp, LOW); //lampu akan mati
kondisi = 0;
}
if (myBot.getNewMessage(msg)) {
if (msg.text.equalsIgnoreCase("hidup")) { //Perintah dari telegram ke perangkat
digitalWrite(lamp, HIGH); //lampu akan menyala
kondisi = 1;
myBot.sendMessage(msg.sender.id, (String)"Lampu Halaman Menyala"); //Balasan dari perangkat ke Bot Telegram
}
if else(msg.text.equalsIgnoreCase("mati")) { //Perintah dari telegram ke perangkat
digitalWrite(lamp, LOW); //lampu akan mati
kondisi = 0;
myBot.sendMessage(msg.sender.id, (String)"Lampu Halaman Mati"); //Balasan dari perangkat ke Bot Telegram
}
if else(msg.text.equalsIgnoreCase("cek")) { //Perintah dari telegram ke perangkat
if (kondisi == 0) {
myBot.sendMessage(msg.sender.id, (String)"Lampu Halaman Mati"); //Balasan dari perangkat ke Bot Telegram
}
else {
myBot.sendMessage(msg.sender.id, (String)"Lampu Halaman Hidup"); //Balasan dari perangkat ke Bot Telegram
}
}
else {
myBot.sendMessage(msg.sender.id, (String)"Untuk Menghidupkan Lampu" +
"\nKirimkan pesan >>> hidup" +
"\n \nUntuk Mematikan Lampu" +
"\nKirimkan pesan >>> mati"
);
}
}
}
and here's the error output
C:\Users\MSI GF63\AppData\Local\Temp\.arduinoIDE-unsaved20221123-8628-153v5mv.hwp1\sketch_dec23a\sketch_dec23a.ino:28:16: error: 'xx' was not declared in this scope
const int id = xx; //id telegram kalian
^~
C:\Users\MSI GF63\AppData\Local\Temp\.arduinoIDE-unsaved20221123-8628-153v5mv.hwp1\sketch_dec23a\sketch_dec23a.ino: In function 'void loop()':
C:\Users\MSI GF63\AppData\Local\Temp\.arduinoIDE-unsaved20221123-8628-153v5mv.hwp1\sketch_dec23a\sketch_dec23a.ino:70:8: error: expected '(' before 'else'
if else(msg.text.equalsIgnoreCase("mati")) { //Perintah dari telegram ke perangkat
^~~~
(
C:\Users\MSI GF63\AppData\Local\Temp\.arduinoIDE-unsaved20221123-8628-153v5mv.hwp1\sketch_dec23a\sketch_dec23a.ino:75:8: error: expected '(' before 'else'
if else(msg.text.equalsIgnoreCase("cek")) { //Perintah dari telegram ke perangkat
^~~~
(
C:\Users\MSI GF63\AppData\Local\Temp\.arduinoIDE-unsaved20221123-8628-153v5mv.hwp1\sketch_dec23a\sketch_dec23a.ino:84:5: error: expected '}' before 'else'
else {
^~~~
C:\Users\MSI GF63\AppData\Local\Temp\.arduinoIDE-unsaved20221123-8628-153v5mv.hwp1\sketch_dec23a\sketch_dec23a.ino:64:34: note: to match this '{'
if (myBot.getNewMessage(msg)) {
^
C:\Users\MSI GF63\AppData\Local\Temp\.arduinoIDE-unsaved20221123-8628-153v5mv.hwp1\sketch_dec23a\sketch_dec23a.ino: At global scope:
C:\Users\MSI GF63\AppData\Local\Temp\.arduinoIDE-unsaved20221123-8628-153v5mv.hwp1\sketch_dec23a\sketch_dec23a.ino:92:1: error: expected declaration before '}' token
}
^
exit status 1
Compilation error: 'xx' was not declared in this scope
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
hi, i just got an error and got confused need to fix it it, can you please help me with it please.
here's the whole code
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h> // Universal Telegram Bot Library written by Brian Lough: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>
#include "CTBot.h" //Pendeklarasian Library
#define lamp 25
#define LDR 13
CTBot myBot;
TBMessage msg;
String ssid = "xx"; //nama ssid wifi
String pass = "xx"; //password wifi
String token = "xx"; //token bot baru
const int id = 3232; //id telegram kalian
void setup() { //Pengaturan Variabel
Serial.begin(9600);
pinMode(lamp,OUTPUT);
pinMode(LDR,INPUT);
Serial.println("Starting TelegramBot...");
myBot.wifiConnect(ssid, pass);
myBot.setTelegramToken(token);
if (myBot.testConnection()) {
Serial.println("Koneksi Bagus");
} else {
Serial.println("Koneksi Jelek");
}
myBot.sendMessage(msg.sender.id, (String)"Untuk Menghidupkan Lampu" +
"\nKirimkan pesan >>> hidup" +
"\n \nUntuk Mematikan Lampu" +
"\nKirimkan pesan >>> mati" +
"\n\nMengecek Kondisi Lampu"+
"\nKirimkan pesan >>> cek"
);
}
void loop() { //Perulangan Programvoid setup() {
int nilai = analogRead(LDR);
int kondisi = 0;
Serial.print("Nilai LDR: ");
Serial.println(nilai);
if (nilai <500) {
digitalWrite(lamp, HIGH); //lampu akan menyala
kondisi = 1;
}
else {
digitalWrite(lamp, LOW); //lampu akan mati
kondisi = 0;
}
if (myBot.getNewMessage(msg)) {
if (msg.text.equalsIgnoreCase("hidup")) { //Perintah dari telegram ke perangkat
digitalWrite(lamp, HIGH); //lampu akan menyala
kondisi = 1;
myBot.sendMessage(msg.sender.id, (String)"Lampu Halaman Menyala"); //Balasan dari perangkat ke Bot Telegram
}
if else(msg.text.equalsIgnoreCase("mati")) { //Perintah dari telegram ke perangkat
digitalWrite(lamp, LOW); //lampu akan mati
kondisi = 0;
myBot.sendMessage(msg.sender.id, (String)"Lampu Halaman Mati"); //Balasan dari perangkat ke Bot Telegram
}
if else(msg.text.equalsIgnoreCase("cek")) { //Perintah dari telegram ke perangkat
if (kondisi == 0) {
myBot.sendMessage(msg.sender.id, (String)"Lampu Halaman Mati"); //Balasan dari perangkat ke Bot Telegram
}
else {
myBot.sendMessage(msg.sender.id, (String)"Lampu Halaman Hidup"); //Balasan dari perangkat ke Bot Telegram
}
}
else {
myBot.sendMessage(msg.sender.id, (String)"Untuk Menghidupkan Lampu" +
"\nKirimkan pesan >>> hidup" +
"\n \nUntuk Mematikan Lampu" +
"\nKirimkan pesan >>> mati"
);
}
}
}
and here's the error output
C:\Users\MSI GF63\OneDrive\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino: In function 'void loop()':
C:\Users\MSI GF63\OneDrive\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino:70:8: error: expected '(' before 'else'
if else(msg.text.equalsIgnoreCase("mati")) { //Perintah dari telegram ke perangkat
^~~~
(
C:\Users\MSI GF63\OneDrive\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino:75:8: error: expected '(' before 'else'
if else(msg.text.equalsIgnoreCase("cek")) { //Perintah dari telegram ke perangkat
^~~~
(
C:\Users\MSI GF63\OneDrive\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino:84:5: error: expected '}' before 'else'
else {
^~~~
C:\Users\MSI GF63\OneDrive\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino:64:34: note: to match this '{'
if (myBot.getNewMessage(msg)) {
^
C:\Users\MSI GF63\OneDrive\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino: At global scope:
C:\Users\MSI GF63\OneDrive\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino:92:1: error: expected declaration before '}' token
}
^
exit status 1
Compilation error: expected '(' before 'else'
Your two topics on the same or similar subject have been merged.
Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.
Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.
Repeated duplicate posting could result in a temporary or permanent ban from the forum.
Could you take a few moments to Learn How To Use The Forum
It will help you get the best out of the forum in the future.