fbpx

Membuat Notifikasi Telegram Menggunakan NodeMCU

Melanjutkan tutorial dari postingan sebelumnya tentang cara memulai menggunakan telegram pada NodeMCU, kali kita akan membahas cara membuat notifikasinya dengan parameter suhu menggunakan sensor DHT11.  Jadi untuk notifikasinya nanti akan masuk ke telegram kita jika suhu melebihi batas maksimalnya yang sudah ditentukan sebelumnya.

Langsung saja di bawah ini dijelaskan lebih lengkapnya.

Alat dan bahan

Alat dan bahan yang digunakan :

  • NodeMCU, BELI
  • Sensor DHT11, BELI
  • Kabel jumper, BELI
  • Library ArduinoJson, download
  • Library UniversalTelegrambot, download
  • Library sensor dht11, download

Rangkaian

Keterangan :

  • Pin Out dihubungkan ke pin D2
  • Pin + dihubungkan ke 3.3V
  • Pin – dihubungkan ke GND

Sketch Program

#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include "DHT.h"

#define DHTPIN D1

char ssid[] = "xxxxx"; //nama wifi
char password[] = "xxxxxx"; //password wifi
#define BOTtoken "875891059:AAGt0weweweweqw343rs353geDw333" //token bot telegram
#define idChat "433434231" //idbot

WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);

#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  Serial.print("Connecting Wifi: ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  dht.begin();
  delay(5000);
}

void loop() {
  delay(2000);
  
  float t = dht.readTemperature();
  Serial.print("Suhu : ");
  Serial.print(t);
  Serial.println(" *C");
  
  if (t > 35.00) {
    bot.sendChatAction(idChat, "Sedang mengetik...");
    Serial.print("Suhu saat ini : ");
    Serial.println(t);
    delay(3000);

    String suhu = "Intensitas suhu : ";
    suhu += int(t);
    suhu += " *C\n";
    suhu += "Suhu maksimal!\n";
    bot.sendMessage(idChat, suhu, "");
    Serial.print("Mengirim data sensor ke telegram");
  }
}

Pada tutorial sebelumnya kita sudah mendapatkan API token dan idchat, nah sekarang saatnya kita masukkan keduanya pada sketch program di atas. Jangan lupa untuk mengganti nama wifi dan password. 

Masukkan juga library yang digunakan, kemudian upload sketch program sampai selesai.

Sekarang saatnya membuka telegramnya, ketik nama bot yang sudah di buat sebelumnya > Mulai/Start.

Buka Serial monitor dengan baudrate 115200, disini kita tetapkan suhu maksimal adalah 35. Jadi ketika suhu dia atas 35 nanti akan ada notifikasi pada telegram seperti gambar di bawah ini.

Demikan pembahan kali ini, semoga berhasil.

40 komentar untuk “Membuat Notifikasi Telegram Menggunakan NodeMCU”

    1. library wificlientsecure.h itu fungsinya sama dengan wificlient.h tapi support TLS (Three Layer Security). Nah ini cocok untuk telegram yang menggunakan security token dan SSL

        1. cara terbaik untuk tahu adalah dengan ‘mencoba’ :). Kalo ada error silahkan disampaikan ke sini untuk diskusi lebih lanjut

  1. bang mau tanya kalau cara mencari library universaltelegrambot di mana yah bisa bagi link nya

    soalnya saya error exit status 1
    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    1. googling aja kak, pasti ketemu. Untuk warning errornya apa ya? (yang lengkap). Kalo dari message error di atas belum bisa disimpulkan

    1. kemungkinan saat itu sensor dht11 gagal mengambil sensor, sehingga saat dikonversi ke integer (baris 54) terjadi kegagalan sehingga muncul ‘nan’

    2. Siap ka sudah bisa.. dan tampil notifnya juga.
      tetapi ini bot cuma untuk 1 telegram atau bisa di akses untuk public yah? Di telegram teman saya dengan bot yang sama tidak bisa menampilkan notifnya…
      Cara setting untuk bisa menampilkan notif di user lain gimana yah?

  2. ka. program udah done dan berjalan di serial monitorpun lancar, tapi ko dia ga ngirim pesan ke telegram nya ya padahal sudah di cek kalo sudah 1 jaringan dan juga suhu nya sudah sampe 37 derajat. padahal di serial monitor dituliskan kalo sedang mengirim pesan ke telegram. tapi tidak ada 1 pun pesanmasuk ke telegram nya

      1. upload done,serial monitor lancar,>35’c sedang mengirim data suhu ke telegram..tapi pesannya tdk sampai ke telegram??

        1. koneksi internet apakah sudah dipastikan bagus? kemudian cek juga token API bot telegram-nya, apakah sudah sesuai belum

          1. jaringan internet ok 4g,API bot lengkap dgn ID..tapi tidak bisa mengirim ke telegram gan,apa solusi??

  3. Siap ka sudah bisa.. dan tampil notifnya juga.
    tetapi ini bot cuma untuk 1 telegram atau bisa di akses untuk public yah? Di telegram teman saya dengan bot yang sama tidak bisa menampilkan notifnya…
    Cara setting untuk bisa menampilkan notif di user lain gimana yah? Koneksi internet juga bagus..

      1. oh jadi telegram di orang lain tidak bisa dapat notifnya ya.. walaupun botnya sama hanya si pembuat Bot yang dapat notifnya..
        solusi agar telegram orang lain bisa dapat notifnya gimana yah kak?

    1. bot nya masukkan ke dalam grup, kemudian set privacy bot menjadi disable. Caranya, masuk ke bot father dulu, kemudian ketik /setprivacy, kmf pilih DISABLE

      1. sudah tak masukan grub, settingan botnya juga sudah di set seperti yang di atas sebelum dimasukan ke grub.. tetapi tetap tidak ada pesan atau notif dari botnya

      2. Sudah disable ka… tpi tetap tidak bisa mengirim notif.nya ke grub yang sudah di buat
        Apakah pada script idChat //idbot di ganti dengan id chat grub

          1. //inclde library CTB
            #include “CTBot.h”;
            //variabel untuk bot telegram
            CTBot myBot;
            String ssid = “KOS ETAM”;
            String pass = “KosEtamm”;
            //variabel token dan id telegram
            String token = “1165770085:AAEPd0KpDZ2KCo4Rm8Wrl-IKKaaZp7AsbVk”;
            const int id = 910667026 ;

            void setup() {
            Serial.begin(9600);
            Serial.println(“memulai telegram bot. koneksi ke Wifi”);

            //koneksi ke wifi
            myBot.wifiConnect(ssid, pass);
            //set token telegram
            myBot.setTelegramToken(token);

            //cek koneksi wifi
            if (myBot.testConnection())
            Serial.println(“koneksi Berhasil”);
            else
            Serial.println(“koneksi Gagal”);

            }

            void loop() {
            String db = “”;
            while(Serial.available())
            {
            db += char(Serial.read());
            }

            myBot.sendMessage(id, db,” “);
            delay(3000);
            //baca pesan masuk dari telegram
            TBMessage msg ;
            if(myBot.getNewMessage(msg))
            {

            //tampilkan di serial monitor
            Serial.println(“pesan Masuk : ” + msg.text);

            //variabel penampung isi pesan
            String pesan = msg.text;
            if(pesan == “cek”)
            {
            //kirim pesan balasan

            myBot.sendMessage(id, db);
            data.trim();
            }
            }
            }

            Ini apa yang ditambahi atau dikurangin supaya tidak spam ngirim ke telegram

  4. Silvi Rahmawati

    siang bang izin bertanya, apakah pernah membuat program notif telegram yang menggunkanan sensor load cell? terima kasih

  5. Ni errornya bang? Kalo sy masukkan “#include ” errornya ini bang Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: “NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200”

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘String UniversalTelegramBot::sendPostToTelegram(const String&, ArduinoJson::JsonObject)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:167:37: error: ‘measureJson’ was not declared in this scope

    int length = measureJson(payload);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:174:31: error: ‘serializeJson’ was not declared in this scope

    serializeJson(payload, out);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::getMe()’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:305:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument doc(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:305:23: error: expected ‘;’ before ‘doc’

    DynamicJsonDocument doc(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:306:3: error: ‘DeserializationError’ was not declared in this scope

    DeserializationError error = deserializeJson(doc, ZERO_COPY(response));

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:306:24: error: expected ‘;’ before ‘error’

    DeserializationError error = deserializeJson(doc, ZERO_COPY(response));

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:309:8: error: ‘error’ was not declared in this scope

    if (!error) {

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:310:9: error: ‘doc’ was not declared in this scope

    if (doc.containsKey(“result”)) {

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:311:51: error: expected primary-expression before ‘>’ token

    name = doc[“result”][“first_name”].as();

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:311:53: error: expected primary-expression before ‘)’ token

    name = doc[“result”][“first_name”].as();

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:312:53: error: expected primary-expression before ‘>’ token

    userName = doc[“result”][“username”].as();

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:312:55: error: expected primary-expression before ‘)’ token

    userName = doc[“result”][“username”].as();

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::setMyCommands(const String&)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:327:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:327:23: error: expected ‘;’ before ‘payload’

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:328:3: error: ‘payload’ was not declared in this scope

    payload[“commands”] = serialized(commandArray);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:328:48: error: ‘serialized’ was not declared in this scope

    payload[“commands”] = serialized(commandArray);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:337:82: error: expected primary-expression before ‘>’ token

    response = sendPostToTelegram(BOT_CMD(“setMyCommands”), payload.as());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:337:84: error: expected primary-expression before ‘)’ token

    response = sendPostToTelegram(BOT_CMD(“setMyCommands”), payload.as());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘int UniversalTelegramBot::getUpdates(long int)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:386:5: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument doc(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:386:25: error: expected ‘;’ before ‘doc’

    DynamicJsonDocument doc(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:387:5: error: ‘DeserializationError’ was not declared in this scope

    DeserializationError error = deserializeJson(doc, ZERO_COPY(response));

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:387:26: error: expected ‘;’ before ‘error’

    DeserializationError error = deserializeJson(doc, ZERO_COPY(response));

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:389:10: error: ‘error’ was not declared in this scope

    if (!error) {

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:395:11: error: ‘doc’ was not declared in this scope

    if (doc.containsKey(“result”)) {

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:402:54: error: use of deleted function ‘ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)’

    if (processResult(result, newMessageIndex)) newMessageIndex++;

    ^

    In file included from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:11:0,

    from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,

    from C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.h:29,

    from C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:36:

    C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/JsonObject.hpp:40:7: note: ‘ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)’ is implicitly deleted because the default definition would be ill-formed:

    class JsonObject : public Internals::JsonPrintable,

    ^

    In file included from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/../JsonBuffer.hpp:11:0,

    from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/JsonParser.hpp:7,

    from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/JsonBufferBase.hpp:7,

    from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/DynamicJsonBuffer.hpp:7,

    from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:9,

    from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,

    from C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.h:29,

    from C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:36:

    C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Deserialization/../Data/NonCopyable.hpp:17:3: error: ‘ArduinoJson::Internals::NonCopyable::NonCopyable(const ArduinoJson::Internals::NonCopyable&)’ is private

    NonCopyable(const NonCopyable&);

    ^

    In file included from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:11:0,

    from C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,

    from C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.h:29,

    from C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:36:

    C:\Users\azamk\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/JsonObject.hpp:40:7: error: within this context

    class JsonObject : public Internals::JsonPrintable,

    ^

    In file included from C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:36:0:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.h:137:8: error: initializing argument 1 of ‘bool UniversalTelegramBot::processResult(ArduinoJson::JsonObject, int)’

    bool processResult(JsonObject result, int messageIndex);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::processResult(ArduinoJson::JsonObject, int)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:454:44: error: use of deleted function ‘ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)’

    JsonObject message = result[“message”];

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:485:49: error: use of deleted function ‘ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)’

    JsonObject message = result[“channel_post”];

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:494:51: error: use of deleted function ‘ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)’

    JsonObject message = result[“callback_query”];

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:507:51: error: use of deleted function ‘ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)’

    JsonObject message = result[“edited_message”];

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::sendMessage(const String&, const String&, const String&, int)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:565:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:565:23: error: expected ‘;’ before ‘payload’

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:566:3: error: ‘payload’ was not declared in this scope

    payload[“chat_id”] = chat_id;

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:575:47: error: expected primary-expression before ‘>’ token

    return sendPostMessage(payload.as(), message_id); // if message id == 0 then edit is false, else edit is true

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:575:49: error: expected primary-expression before ‘)’ token

    return sendPostMessage(payload.as(), message_id); // if message id == 0 then edit is false, else edit is true

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::sendMessageWithReplyKeyboard(const String&, const String&, const String&, const String&, bool, bool, bool)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:582:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:582:23: error: expected ‘;’ before ‘payload’

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:583:3: error: ‘payload’ was not declared in this scope

    payload[“chat_id”] = chat_id;

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:591:48: error: ‘serialized’ was not declared in this scope

    replyMarkup[“keyboard”] = serialized(keyboard);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:604:47: error: expected primary-expression before ‘>’ token

    return sendPostMessage(payload.as());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:604:49: error: expected primary-expression before ‘)’ token

    return sendPostMessage(payload.as());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::sendMessageWithInlineKeyboard(const String&, const String&, const String&, const String&, int)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:613:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:613:23: error: expected ‘;’ before ‘payload’

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:614:3: error: ‘payload’ was not declared in this scope

    payload[“chat_id”] = chat_id;

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:624:55: error: ‘serialized’ was not declared in this scope

    replyMarkup[“inline_keyboard”] = serialized(keyboard);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:625:47: error: expected primary-expression before ‘>’ token

    return sendPostMessage(payload.as(), message_id); // if message id == 0 then edit is false, else edit is true

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:625:49: error: expected primary-expression before ‘)’ token

    return sendPostMessage(payload.as(), message_id); // if message id == 0 then edit is false, else edit is true

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::sendPostMessage(ArduinoJson::JsonObject, bool)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:644:115: error: use of deleted function ‘ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)’

    String response = sendPostToTelegram((edit ? BOT_CMD(“editMessageText”) : BOT_CMD(“sendMessage”)), payload); // if edit is true we send a editMessageText CMD

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:140:8: error: initializing argument 2 of ‘String UniversalTelegramBot::sendPostToTelegram(const String&, ArduinoJson::JsonObject)’

    String UniversalTelegramBot::sendPostToTelegram(const String& command, JsonObject payload) {

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘String UniversalTelegramBot::sendPostPhoto(ArduinoJson::JsonObject)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:668:66: error: use of deleted function ‘ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)’

    response = sendPostToTelegram(BOT_CMD(“sendPhoto”), payload);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:140:8: error: initializing argument 2 of ‘String UniversalTelegramBot::sendPostToTelegram(const String&, ArduinoJson::JsonObject)’

    String UniversalTelegramBot::sendPostToTelegram(const String& command, JsonObject payload) {

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘String UniversalTelegramBot::sendPhoto(const String&, const String&, const String&, bool, int, const String&)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:708:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:708:23: error: expected ‘;’ before ‘payload’

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:709:3: error: ‘payload’ was not declared in this scope

    payload[“chat_id”] = chat_id;

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:723:50: error: ‘serialized’ was not declared in this scope

    replyMarkup[“keyboard”] = serialized(keyboard);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:726:45: error: expected primary-expression before ‘>’ token

    return sendPostPhoto(payload.as());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:726:47: error: expected primary-expression before ‘)’ token

    return sendPostPhoto(payload.as());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::checkForOkResponse(const String&)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:731:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument doc(response.length());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:731:23: error: expected ‘;’ before ‘doc’

    DynamicJsonDocument doc(response.length());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:732:19: error: ‘doc’ was not declared in this scope

    deserializeJson(doc, response);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:732:32: error: ‘deserializeJson’ was not declared in this scope

    deserializeJson(doc, response);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::getFile(String&, long int&, const String&)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:786:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument doc(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:786:23: error: expected ‘;’ before ‘doc’

    DynamicJsonDocument doc(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:787:3: error: ‘DeserializationError’ was not declared in this scope

    DeserializationError error = deserializeJson(doc, ZERO_COPY(response));

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:787:24: error: expected ‘;’ before ‘error’

    DeserializationError error = deserializeJson(doc, ZERO_COPY(response));

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:790:8: error: ‘error’ was not declared in this scope

    if (!error) {

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:791:9: error: ‘doc’ was not declared in this scope

    if (doc.containsKey(“result”)) {

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:794:49: error: expected primary-expression before ‘long’

    file_size = doc[“result”][“file_size”].as();

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:794:49: error: expected ‘;’ before ‘long’

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp: In member function ‘bool UniversalTelegramBot::answerCallbackQuery(const String&, const String&, bool, const String&, int)’:

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:802:3: error: ‘DynamicJsonDocument’ was not declared in this scope

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:802:23: error: expected ‘;’ before ‘payload’

    DynamicJsonDocument payload(maxMessageLength);

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:804:3: error: ‘payload’ was not declared in this scope

    payload[“callback_query_id”] = query_id;

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:811:93: error: expected primary-expression before ‘>’ token

    String response = sendPostToTelegram(BOT_CMD(“answerCallbackQuery”), payload.as());

    ^

    C:\Users\azamk\Documents\Arduino\libraries\Universal-Arduino-Telegram-Bot-master\src\UniversalTelegramBot.cpp:811:95: error: expected primary-expression before ‘)’ token

    String response = sendPostToTelegram(BOT_CMD(“answerCallbackQuery”), payload.as());

    ^

    Multiple libraries were found for “FirebaseArduino.h”

    Used: C:\Users\azamk\Documents\Arduino\libraries\FirebaseArduino

    Not used: C:\Users\azamk\Documents\Arduino\libraries\firebase-arduino-master

    exit status 1

    Error compiling for board NodeMCU 1.0 (ESP-12E Module).

    This report would have more information with
    “Show verbose output during compilation”
    option enabled in File -> Preferences.

    1. ada warning ‘Multiple libraries were found for “FirebaseArduino.h”’, kemungkinan ada lebih dari satu library ‘FirebaseArduino.h’ di folder library arduino. COba dihapus semua dulu kemudian instal lagi

      1. #include
        #include
        #include
        #include

        #define FIREBASE_HOST “co-gas-detection-78adf-default-rtdb.firebaseio.com”
        #define FIREBASE_AUTH “WTe1uyFAdVNOMoIaerOQ2KXLWn0q8d8nMpvJLsJU”
        #define WIFI_SSID “SheilaFarhan@unifi”
        #define WIFI_PASSWORD “Kusanagi14”

        char ssid[] = “SheilaFarhan@unifi”;
        char password[] = “Kusanagi14”;
        #define BOTtoken “1725189417:AAFidALs3ncXKMP4g6opM2dnEujF9ALm_ZE”
        #define idChat “346401657”

        WiFiClientSecure client;
        UniversalTelegramBot bot(BOTtoken, client);

        void setup() {
        Serial.begin(9600);

        // connect to wifi.
        WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
        Serial.print(“connecting”);
        while (WiFi.status() != WL_CONNECTED) {
        Serial.print(“.”);
        delay(500);
        }
        Serial.println();
        Serial.print(“connected: “);
        Serial.println(WiFi.localIP());

        Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
        delay(200);

        Serial.begin(9600);
        Serial.print(“Connecting Wifi: “);
        Serial.println(ssid);
        WiFi.mode(WIFI_STA);
        WiFi.begin(ssid, password);
        while (WiFi.status() != WL_CONNECTED) {
        Serial.print(“.”);
        delay(500);
        }
        Serial.println(“”);
        Serial.println(“WiFi connected”);
        Serial.print(“IP address: “);
        Serial.println(WiFi.localIP());
        delay(5000);
        }

        int n = 0;

        void loop() {

        int sensorValue = analogRead(A0);
        Serial.print(“Carbon Monoxide Level (PPM): “);
        Serial.println(sensorValue);
        delayMicroseconds(2);

        if (sensorValue 200) && (sensorValue 800)
        {
        bot.sendChatAction(idChat, “Typing…”);
        Serial.print(“Current CO value (PPM): “);
        Serial.println(sensorValue);
        delayMicroseconds(2);

        String co = “CO intensity (PPM): “;
        co += int(sensorValue);
        co += “ALARM CO high!\n”;
        bot.sendMessage(idChat, co, “”);
        Serial.print(“Sending sensor data to Telegram”);
        }
        else
        {
        Serial.println(“MQ-7 – cant read any value – check the sensor!”);
        }

        // set value
        Firebase.setFloat(“value”, sensorValue);
        // handle error
        if (Firebase.failed()) {
        Serial.print(“setting /number failed:”);
        Serial.println(Firebase.error());
        return;
        }
        delayMicroseconds(2);

        // set string value
        Firebase.setString(“Message”, “Carbon Monoxide Detection (PPM):”);
        // handle error
        if (Firebase.failed()) {
        Serial.print(“setting /message failed:”);
        Serial.println(Firebase.error());
        return;
        }
        delayMicroseconds(2);
        }
        Codenya udah bisa di verify. Tapi jika value gas sensor saya diatas 800 masih tiada notification di telegram. Bagaimana ya?

        1. bikin 2 program sederhana dulu, satu buat tes kirim telegram, satu buat ambil data sensor. PAstikan dua-duanya berfungsi. Kalo sudah yakin benar baru digabungkan

  6. #include
    #include
    #include
    #include

    #define FIREBASE_HOST “co-gas-detection-78adf-default-rtdb.firebaseio.com”
    #define FIREBASE_AUTH “WTe1uyFAdVNOMoIaerOQ2KXLWn0q8d8nMpvJLsJU”
    #define WIFI_SSID “SheilaFarhan@unifi”
    #define WIFI_PASSWORD “Kusanagi14”

    char ssid[] = “SheilaFarhan@unifi”;
    char password[] = “Kusanagi14”;
    #define BOTtoken “1725189417:AAFidALs3ncXKMP4g6opM2dnEujF9ALm_ZE”
    #define idChat “346401657”

    WiFiClientSecure client;
    UniversalTelegramBot bot(BOTtoken, client);

    void setup() {
    Serial.begin(9600);

    // connect to wifi.
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print(“connecting”);
    while (WiFi.status() != WL_CONNECTED) {
    Serial.print(“.”);
    delay(500);
    }
    Serial.println();
    Serial.print(“connected: “);
    Serial.println(WiFi.localIP());

    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
    delay(200);

    Serial.begin(9600);
    Serial.print(“Connecting Wifi: “);
    Serial.println(ssid);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
    Serial.print(“.”);
    delay(500);
    }
    Serial.println(“”);
    Serial.println(“WiFi connected”);
    Serial.print(“IP address: “);
    Serial.println(WiFi.localIP());
    delay(5000);
    }

    int n = 0;

    void loop() {

    int sensorValue = analogRead(A0);
    Serial.print(“Carbon Monoxide Level (PPM): “);
    Serial.println(sensorValue);
    delayMicroseconds(2);

    if (sensorValue 200) && (sensorValue 800)
    {
    bot.sendChatAction(idChat, “Typing…”);
    Serial.print(“Current CO value (PPM): “);
    Serial.println(sensorValue);
    delayMicroseconds(2);

    String co = “CO intensity (PPM): “;
    co += int(sensorValue);
    co += “ALARM CO high!\n”;
    bot.sendMessage(idChat, co, “”);
    Serial.print(“Sending sensor data to Telegram”);
    }
    else
    {
    Serial.println(“MQ-7 – cant read any value – check the sensor!”);
    }

    // set value
    Firebase.setFloat(“value”, sensorValue);
    // handle error
    if (Firebase.failed()) {
    Serial.print(“setting /number failed:”);
    Serial.println(Firebase.error());
    return;
    }
    delayMicroseconds(2);

    // set string value
    Firebase.setString(“Message”, “Carbon Monoxide Detection (PPM):”);
    // handle error
    if (Firebase.failed()) {
    Serial.print(“setting /message failed:”);
    Serial.println(Firebase.error());
    return;
    }
    delayMicroseconds(2);
    }

    Salam bang. Ni code saya. Kenapa ya tiada notification dihantar apabila value gas sensor saya melepasi 800 ppm? Terima kasih atas bantuannya

  7. #include
    #include
    #include
    #include

    #define FIREBASE_HOST “co-gas-detection-78adf-default-rtdb.firebaseio.com”
    #define FIREBASE_AUTH “WTe1uyFAdVNOMoIaerOQ2KXLWn0q8d8nMpvJLsJU”
    #define WIFI_SSID “SheilaFarhan@unifi”
    #define WIFI_PASSWORD “Kusanagi14”

    char ssid[] = “SheilaFarhan@unifi”;
    char password[] = “Kusanagi14”;
    #define BOTtoken “1725189417:AAFidALs3ncXKMP4g6opM2dnEujF9ALm_ZE”
    #define idChat “346401657”

    WiFiClientSecure client;
    UniversalTelegramBot bot(BOTtoken, client);

    void setup() {
    Serial.begin(9600);

    // connect to wifi.
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print(“connecting”);
    while (WiFi.status() != WL_CONNECTED) {
    Serial.print(“.”);
    delay(500);
    }
    Serial.println();
    Serial.print(“connected: “);
    Serial.println(WiFi.localIP());

    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
    delay(200);

    Serial.begin(9600);
    Serial.print(“Connecting Wifi: “);
    Serial.println(ssid);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
    Serial.print(“.”);
    delay(500);
    }
    Serial.println(“”);
    Serial.println(“WiFi connected”);
    Serial.print(“IP address: “);
    Serial.println(WiFi.localIP());
    delay(5000);
    }

    int n = 0;

    void loop() {

    int sensorValue = analogRead(A0);
    Serial.print(“Carbon Monoxide Level (PPM): “);
    Serial.println(sensorValue);
    delayMicroseconds(2);

    if (sensorValue 200) && (sensorValue 800)
    {
    bot.sendChatAction(idChat, “Typing…”);
    Serial.print(“Current CO value (PPM): “);
    Serial.println(sensorValue);
    delayMicroseconds(2);

    String co = “CO intensity (PPM): “;
    co += int(sensorValue);
    co += “ALARM CO high!\n”;
    bot.sendMessage(idChat, co, “”);
    Serial.print(“Sending sensor data to Telegram”);
    }
    else
    {
    Serial.println(“MQ-7 – cant read any value – check the sensor!”);
    }

    // set value
    Firebase.setFloat(“value”, sensorValue);
    // handle error
    if (Firebase.failed()) {
    Serial.print(“setting /number failed:”);
    Serial.println(Firebase.error());
    return;
    }
    delayMicroseconds(2);

    // set string value
    Firebase.setString(“Message”, “Carbon Monoxide Detection (PPM):”);
    // handle error
    if (Firebase.failed()) {
    Serial.print(“setting /message failed:”);
    Serial.println(Firebase.error());
    return;
    }
    delayMicroseconds(2);
    }

    Maaf bang ini code sebenarnya.. yg diatas salah

  8. Mas mw nanya, saya sudah ngikutin petunjuk diatas. kenapa masih belum bisa ngirim k telegram nya ya ?
    mohon bimbingan nya