How do I let two ESP8266’s in my home network listen to the same Telegram bot (the same chat_id) at the same time? I am using bot.getUpdates
on both ESP’s to check for new messages now, but then only the ESP which happens to perform a getUpdates before the other ESP does, receives the new messages. The second ESP receives none. So I think I need to use something besides, or in stead of, getUpdates but I don’t know what.
What I would like to achieve is that one ESP (device 1) must only receive and respond to messages which are addressed to him, based on the message text: “1” on the first position of the message text means it’s meant for device 1. Messages which don’t start with “1” (they’ll start with “2”) are not meant for him must stay available on the Telegram server for the other ESP (device 2).
More details about the project:
I have a simple ESP8266 project running fine. When the frontdoor of my house opens, a reedcontact opens and a message is sent from the ESP in my home network to my Telegram bot and then I receive a notification in the Telegram app on my phone saying that door 1 has opened. The other way around, when I type “1” in the app, the bot returns the current state of the door. But when I add a second ESP8266 to control the backdoor (door 2), the problem starts: there is one random ESP which receives the messages. which may not be the ESP/door I am asking for.
I am using:
Arduino IDE
clone nodemcu ESP8266 (ESP-12E)
clone wemos d1 r1
3
Answers
Use the
offset
parameter of getUpdates method. As the documentation states:You need to pass the last update_id through your ESP8266s, but this is kind of tricky.
I advise you to build a central system (or a master-slave system) that reads and processes the updates from Telegram and sends to the two ESP8266s the relative commands (like “open the door 1”, etc…). In my opinion this is the easiest way to do what you want to do.
Would it be easier to have one bot for the frontdoor and one for the backdoor?
They can both send messages and you can send a command to the respective bot to get the state of the door.
Was looking for a similar resolution and stopped here. Thought you would be interested to know how I eventually did.
Create a new Tlgr group and add your bots there.
Demote your bots to simple users, not group admins.
Through BotFather change settings on both bots (if not done by default) and set them into privacy mode (set to on).
Now your bots will only receive messages addressed to them and will not see other exchange.
To address to a particular bot in the group:
/your_command@bot_name
That’s it!