witnessmenow / Universal-Arduino-Telegram-Bot

Use Telegram on your Arduino (ESP8266 or Wifi-101 boards)
MIT License
1.09k stars 302 forks source link

Location: longitude and latitude are always 0 even though location is enabled on the bot. #234

Open arbasel opened 3 years ago

arbasel commented 3 years ago

I was asked permission once or twice but still no longitude or latitude was displayed. Now I am never asked permission and the result is the same.

`/ An example of receiving location Data By Brian Lough /

include

include

include

include

const unsigned long BOT_MTBS = 1000; // mean time between scan messages

// Wifi network station credentials

define WIFI_SSID "WIFI_SSID "

define WIFI_PASSWORD "WIFI_PASSWORD"

// Telegram BOT Token (Get from Botfather)

define BOT_TOKEN "BOT_TOKEN "

unsigned long bot_lasttime; // last time messages' scan has been done X509List cert(TELEGRAM_CERTIFICATE_ROOT); WiFiClientSecure secured_client; UniversalTelegramBot bot(BOT_TOKEN, secured_client);

void handleNewMessages(int numNewMessages) { for (int i = 0; i < numNewMessages; i++) { String chat_id = bot.messages[i].chat_id; String text = bot.messages[i].text;

String from_name = bot.messages[i].from_name;
if (from_name == "")
  from_name = "Guest";
Serial.print("Chat ID: ");
Serial.println(chat_id);
Serial.print("From: ");
Serial.println(from_name);    
Serial.print("Message: ");
Serial.println(text);    
Serial.print("Long: ");
Serial.println(String(bot.messages[i].longitude, 6));
Serial.print("Lat: ");
Serial.println(String(bot.messages[i].latitude, 6));

String message = "Chat ID: " + chat_id + "\n";
message += "From: " + from_name + "\n";
message += "Message: " + text + "\n";
message += "Long: " + String(bot.messages[i].longitude, 6) + "\n";
message += "Lat: " + String(bot.messages[i].latitude, 6) + "\n";
bot.sendMessage(chat_id, message, "Markdown");
if (text == "/start")
{
  String welcome = "Welcome to Universal Arduino Telegram Bot library, " + from_name + ".\n";
  welcome += "Share a location or a live location and the bot will respond with the co-ords\n";

  bot.sendMessage(chat_id, welcome, "Markdown");
}

} }

void setup() { Serial.begin(115200); Serial.println();

// attempt to connect to Wifi network: configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP secured_client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org Serial.print("Connecting to Wifi SSID "); Serial.print(WIFI_SSID); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } Serial.print("\nWiFi connected. IP address: "); Serial.println(WiFi.localIP());

// Check NTP/Time, usually it is instantaneous and you can delete the code below. Serial.print("Retrieving time: "); time_t now = time(nullptr); while (now < 24 * 3600) { Serial.print("."); delay(100); now = time(nullptr); } Serial.println(now);

}

void loop() { if (millis() - bot_lasttime > BOT_MTBS) { int numNewMessages = bot.getUpdates(bot.last_message_received + 1);

while (numNewMessages)
{
  Serial.println("got response");
  handleNewMessages(numNewMessages);
  numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}

bot_lasttime = millis();

} }`