gerasdf / esp8266 Goto Github PK
View Code? Open in Web Editor NEWESP8266 code
ESP8266 code
Sometimes devices become unresponsive, find a way to automatically recover from that.
only authenticated users should be able to do it.
also enable WiFi OTA if available in the libraries
If on first startup (or missconfiguration), the user opens a specific AP (ToI:Love) the device connects to it, and uses it for accessing internet.
This could be used for automatic configuration, see #29
Think about it:
Today each call to getUpdates()
only retrieves 1 update (HANDLE_MESSAGES = 1
).
This makes the bot have a longer response time, since it's only doing one getUpdates()
pero loop iteration.
Using getPendingUpdatesCount()
(gerasdf/Universal-Arduino-Telegram-Bot#7) it's possible to bring them all looping. This is preferred to just looping, specially when using long-polls
Commands must be directed to the particular device, otherwise they won't be answered
Some possibilities to identify messages:
reply_to_message
to the last message sent by the device.reply_to_message
to a message starting with the device's namecallback_query.message.message_id
from the last inline keyboard sent by the device (see #6 )show all available commands and current status.
automatically call it on startup
When in a group, commands are automatically competed with @botName, as in ʼ/status@toi_botʼ. This as to be supported
Commands to reconfigure the device?
/config token blah
and /config name blah
or
/token blah
and /name blah
?
Or maybe via a webpage?
If the token is wrong the user may completely lose control of the bot.
Implement a confirmation mechanism over the new bot token.
dupplicate of #7 (different approach?)
If all devices use a single Telegram bot to communicate, it's not clear how the user can talk to them independently.
It may be possible to filter the incoming messages by using the name of the devices in the messages, such as changing
polarity
for
caldera_1 polarity
and then even shortening the names.
But I'm not sure it's possible, as if one device pops the message from Telegram, the other devices won't see it. And if devices just peek the messages (is it even possible?) who will finally pop it and remove it from the list?
so maybe we need one different Telegram Bot per device? or is there anything like telegram-users-for-devices?
if /settoken doesn't clean updates, and the device is the only one in the bot, the /settoken command will persist and will be again effective on next reconnection to the same token.
Specially when coming back from a timeout. It's kind of needed or it otherwise enters in a bouncing loop going form one to the other.
sometimes the module reboots after reconnecting to WiFi
[321] numNewMessages: 0 last: 888666378 mem: 30960 - 31 - 20312
[321] .[322] .[323] .[324] .[325] .[326] .[327] .[328] .[329] .[330] .[331] .[332] .[333] .[334] .[335] .[336] .[337] .[338] .[339] .[340] .[341] .[342] .[343] .[344] .[345] .[346] .[347] .[348] .[349] .[350] .[351] .[352] .[353] .[354] .[355] .[356] .[357] .[358] .[359] .[360] .[361] .[362] .[363] .[364] .[365] .[366] .[367] .[368] .[369] .[370] .[371] .[372] .[373] .[374] .[375] .[376] .Connected!
[381] numNewMessages: 1 last: 888666380 mem: 11016 - 30 - 7400
[381] Received "allstatus" from 25235518
[381] *ex-Caldera2*: status: *Ok* relay: *Off* polarity: *+*
Exception (29):
epc1=0x4021cfd2 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000008 depc=0x00000000
>>>stack>>>
3fffffa0: feefeffe feefeffe feefeffe 40226c88
<<<stack<<<
last failed alloc call: 4021E111(288)
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld
I'm ex-Caldera2
It seems to be an out of memory issue
This info will answer information about the device itself, not the sensors
Persist configuration
More info about OSS licenses found here
A possible solution is to maintain a list of the last 20 messages in the servers. The offset
in a getUpdates
call retrieve messages starting at that update_id
, and clears all preceding. Incrementing updates_id
late by 20 updates will keep 20 in the server.
In this way all devices/instances will always see the last 20 (configurage), and the user can talk to any of them... I think.
Devices need to know if a message is for them or not, see issue #6 for an idea.
Additionally, a device could clean all consecutive message for it starting on the first of the 20. This minimize the number of message in the server. Also, if too many messages for one device are accumulated, other devices can detect a device is failing (or at least have a hint).
Unify how messages are sent (refactor). Start all messages with device name, such as
Termometer_1: Temperature is 25°C
See #10
Make it possible to configure light sensor polarity
Telegram command
Report current polarity on status and startup
When WiFi is lost, any alarm is lost.
Count and save them (save also time?) and report when WiFi comes back.
Also report that WiFi was gone (for how long?)
Decide what's better. To support a single user, who needs to be registered, or to simultaneously support multiple users, if at least to command the devices.
One user:
Many users:
Answer something so the pending icon goes away.
See if better answers are switable
Maybe don't answer messages at all
decide whether to use it or not,
see https://core.telegram.org/bots/api#getting-updates, timeout
parameter is suggested to be greater than 0
, and the default for TelegramBot is 0
. It has to be changed using:
bot.longPoll = 1
longPoll
is in seconds
See https://core.telegram.org/bots/api#setmycommands
When commands are used, the UI for the bot is a bit better, commands are auto completed, help and settings are shown on bot's description and welcome messages, etc.
Though this is not compatible with issue #7, it may still be usefull for global configuration things
When the user first plugs in a device (or on missconfiguration or factory reset), there should be an easy setup procedure.
Internet access can be assumed (see #28 and as now implemented using AutoConnect portal)
It should change the name of the device as it reports it in the messages.
It must be persistent across boots
This command sholuld let the user change the bot token. Is used to install new devices.
It has to be persistent. Mabe it can only come fom a hardcoded user id?
maybe use chipID?
ToI %08x?
When a new user requests ownership, send the old user a message to validate the change.
Also, have a owner (instead of default_user
)
If compiled out it should save memory space, and should unify logging.
Maybe using a helper function
To save memory.
Try first to connect using regular wifi and saved credentials.
The, allocate, use and destroy portal on success
on
off
toggle ?
If only one of the bot (tokens) is invited to a group chat, it won't be possible to send messages to the chat for the other token, so the process is kind of broken.
Related to Issue #22
See AutoConnect documentation on how to do it
Once /settoken is received, show the keyobard and then do not accept any other command other than /confirmtoken until it's confirmed, or timeout and go back to previous token and continue accepting commands as usual
Originally posted by @gerasdf in #22 (comment)
help
message (automatically invoked on startup) should answer with an Keyboard (https://core.telegram.org/bots#keyboards) with all available commands. The user then clicks on the keyboard to talk to a specific instance. The help message message_id
serves to identify to what instance the user is speaking.
https://api.telegram.org/bot648272766:AAEkW5FaFMeHqWwuNBsZJckFEOdhlSVisEc/sendMessage?chat_id=25235518&text=hola&&reply_markup={%22inline_keyboard%22:[[{%22text%22:%22hola%22,%22callback_data%22:%22hola%22},{%22text%22:%22chau%22,%22callback_data%22:%22chau%22}]]}
https://api.telegram.org/bot648272766:AAEkW5FaFMeHqWwuNBsZJckFEOdhlSVisEc/getUpdates?offset=0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.