witnessmenow/Universal-Arduino-Telegram-Bot

C:\Users\Rohith\Desktop\tgf\tgf.ino: In function 'void setup()': C:\Users\Rohith\Desktop\tgf\tgf.ino:50:7: error: 'class UniversalTelegramBot' has no member named 'begin' bot.begin(TELEGRAM_BOT_TOKEN); ^ C:\Users\Rohith\Desktop\tgf\tgf.ino: In function 'void loop()': C:\Users\Rohith\Desktop\tgf\tgf.ino:56:29: error: 'class UniversalTelegramBot' has no member named 'message_count' for (int i = 0; i < bot.message_count; i++) { ^ exit status 1 Compilation error: 'class UniversalTelegramBot' has no member named 'begin'

rohithmanivarma123 opened this issue · 0 comments

I m getting the ERROR : C:\Users\Rohith\Desktop\tgf\tgf.ino: In function 'void setup()':
C:\Users\Rohith\Desktop\tgf\tgf.ino:50:7: error: 'class UniversalTelegramBot' has no member named 'begin'
bot.begin(TELEGRAM_BOT_TOKEN);
^
C:\Users\Rohith\Desktop\tgf\tgf.ino: In function 'void loop()':
C:\Users\Rohith\Desktop\tgf\tgf.ino:56:29: error: 'class UniversalTelegramBot' has no member named 'message_count'
for (int i = 0; i < bot.message_count; i++) {
^

exit status 1

Compilation error: 'class UniversalTelegramBot' has no member named 'begin'

Here's My code:

#include <WiFi.h>
#include <UniversalTelegramBot.h>
#include <HX711.h>
#include <WiFiClient.h>

// Telegram Bot token and credentials
#define WIFI_SSID "esp32"
#define WIFI_PASSWORD "999999999"
#define TELEGRAM_BOT_TOKEN "6268364540:AAHHr1YeLoFpahG-3hsAARn3FvwQA9JSjbI"
#define CHAT_ID "347329961"

// HX711 Load Cell
#define LOADCELL_DOUT_PIN 32
#define LOADCELL_CLK_PIN 33

// Initialize Telegram bot
WiFiClient client;
UniversalTelegramBot bot(TELEGRAM_BOT_TOKEN, client);

// Initialize HX711
HX711 scale;
float calibration_factor = -7050.0; // Calibration factor for load cell

// Variables to store last feed weight and remaining load
float lastFeedWeight = 0.0;
float remainingLoad = 0.0;

// Digital pin to control feed operation
const int DIGITAL_PIN = 13;

void setup() {
// Connect to Wi-Fi
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}

// Initialize serial communication
Serial.begin(115200);
Serial.println("Connected to WiFi.");

// Set up the HX711 load cell
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_CLK_PIN);
scale.set_scale(calibration_factor);
scale.tare();

// Start the Telegram bot
bot.begin(TELEGRAM_BOT_TOKEN);
}

void loop() {
// Check for new messages
if (bot.getUpdates(bot.last_message_received + 1)) {
for (int i = 0; i < bot.message_count; i++) {
String chat_id = String(bot.messages[i].chat_id);
String text = bot.messages[i].text;

  // Process different commands
  if (text == "/feed") {
    bot.sendMessage(chat_id, "Enter the number of KGs to feed:");
  } else if (text == "/lastfeed") {
    bot.sendMessage(chat_id, "Last feed weight: " + String(lastFeedWeight) + " KG");
  } else if (text == "/remainingload") {
    float weight = scale.get_units();
    if (weight < 0) {
      bot.sendMessage(chat_id, "Error reading weight.");
    } else {
      remainingLoad = weight;
      bot.sendMessage(chat_id, "Remaining load: " + String(remainingLoad) + " KG");
    }
  } else if (text.toFloat() != 0) {
    float feedWeight = text.toFloat();
    digitalWrite(DIGITAL_PIN, HIGH);
    delay(feedWeight * 1000); // Convert KGs to milliseconds
    digitalWrite(DIGITAL_PIN, LOW);
    lastFeedWeight = feedWeight;
    bot.sendMessage(chat_id, "Feed weight: " + String(feedWeight) + " KG");
  } else {
    bot.sendMessage(chat_id, "Unknown command.");
  }
}

}
}