Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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' #331

Open
ghost opened this issue May 29, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented May 29, 2023

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.");
  }
}

}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants