hello every body
im using universal telegram bot library for control a relay.
my problem is when a user with a un regular name(like : ^៛:̤̈G̤̤̈̈Ö̤̤̈D̤̤̈̈ ̤̤̈̈ï̤̤̈s̤̤̈̈ ̤̤̈̈ä̤̤̈l̤̤̈̈ẅ̤̤̈ä̤̤̈ÿ̤̤̈s̤̤̈̈ ̤̤̈̈Ḧ̤̤̈v̤̤̈̈ä̤̤̈ẗ̤̤̈v̤̈:₹^) send a message to bot , the bot broke down and my esp dont resive the message and bot dont work for 5 or 6 hours.
can you help me whats the problem?
this my code:
#include <FS.h>
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <DNSServer.h> //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h> //Local WebServer used to serve the configuration portal
#include <ESP8266HTTPClient.h> //-----------HTTP Client to Communicate to Apache Server
#include <ESP8266FtpServer.h> //-------Library for FTP Server to put Files IN SPIFFS Memory
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#define BOTtoken "xxxxxxx" // توکن ربات تلگرام
#include <WS2812FX.h>
int PIN =5;
int NUM_LEDS =1;
WS2812FX ws2812fx = WS2812FX(NUM_LEDS,PIN, NEO_GRB + NEO_KHZ400);
#include <WiFiManager.h>
HTTPClient http;
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
ESP8266WebServer server(80); ////server instance
String response;
IPAddress IP(192,168,2,111);
IPAddress SUBNET(255,255,255,0);
IPAddress GATEWAY(192,168,2,1);
IPAddress DNS(217,218,127,127);
char ssid[] = "taradod"; // your network SSID (name)
char password[] = "Sepanta$Taradod123"; // your network key
int Bot_mtbs =500; //mean time between scan messages
long Bot_lasttime; //last time messages' scan has been done
bool Start = false;
void setup(){
ledblue();
Serial.begin(115200);
WiFi.config(IP,GATEWAY,SUBNET,DNS);
WiFi.begin(ssid,password); //////connecting to wifi
while (WiFi.status() != WL_CONNECTED) {//wait 15 seconds
Serial.print(">");
delay(500);
}
Serial.println("wifi connected");
}
void loop(){
ws2812fx.service();
server.handleClient();
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();
}
}
void handleNewMessages(int numNewMessages) {
Serial.println("handleNewMessages");
Serial.println(String(numNewMessages));
for (int i=0; i<numNewMessages; i++) {
String chat_id = String(bot.messages[i].chat_id);
String text = bot.messages[i].text;
String from_id = bot.messages[i].from_username;
Serial.print("bot id is: "+from_id);
if (text =="/opendoor") {
http.begin("http://192.168.57.253/rfid.php");
http.setUserAgent("ESP8266-http-Client");
http.addHeader("Content-Type"," application/x-www-form-urlencoded");
int respcode=http.POST("cardid="+from_id+"&mode=normal");
Serial.println("");
Serial.println(respcode);
if(respcode==200){
response= http.getString();
Serial.println("");
Serial.println(response);
http.end();
}else{
Serial.println("");
Serial.print("Error : ");
Serial.println(respcode);
http.end();
bot.sendMessage(chat_id,"مشکل در ارتباط با سرور", "Markdown");
return;
}
StaticJsonBuffer<350> jsonBuffer;
JsonObject& json = jsonBuffer.parseObject(response);
if (!json.success())
{
Serial.println("parseObject() failed");
return;
}
if (json["auth"]=="")
{
Serial.println("not Defined");
bot.sendMessage(chat_id,"دسترسی غیر مجاز", "Markdown");
}else if(json["auth"]=="Allowed" && json["permit"]=="yes"){
http.begin("http://192.168.2.110/opendoor");
int respcode=http.POST("");
Serial.println("response is:");
Serial.println(respcode);
if(respcode==200){
response= http.getString();
Serial.println("response is: ");
Serial.println(response);
http.end();
bot.sendMessage(chat_id, "درب باز شد", "");
ledgreen();
}
}else if(json["auth"]=="notAllowed" || json["permit"]=="no"){
bot.sendMessage(chat_id, "خارج از محدوده ی زمانی");
ledred();
}
}
if (text == "/start") {
Serial.println("text is start");
String welcome="به سپنتا خوش آمدید";
String welcome2="تاریخچه استفاده از ربات ثبت میشود .لطفا از استفاده بی مورد خودداری کنید ";
bot.sendMessage(chat_id, welcome, "Markdown");
bot.sendMessage(chat_id, welcome2, "Markdown");
String keyboardJson = "[[\"/opendoor\"]]";
bot.sendMessageWithReplyKeyboard(chat_id, "برای باز شدن درب کلید زیر را لمس کنید", "", keyboardJson, true);
}
}
}