Page 4 of 30
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 7:37
by Egregius
One thing I don't understand in the Telegram thing: how is security set?
I installed the bot once but could read and switch instantly everything, just by knowing the name of the bot.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 8:27
by QuasaR
Got everything setup but bot won't start.
pi@raspberrypi /var/tmp $ sudo service dtgbot start
Starting Telegram Bot for Domoticz ... Done.
pi@raspberrypi /var/tmp $ sudo service dtgbot status
[FAIL] dtgbot is not running ... failed!
When I look in the dtb.log I get the following error:
Code: Select all
---------------------------------
Starting Telegram message handler
---------------------------------
DomoticzIP: USERNAME:[email protected]
DomoticzPort: 8080
BotHomePath: /home/pi/dtgbot/
BotLuaScriptPath: /home/pi/dtgbot/lua/
BotBashScriptPath: /home/pi/dtgbot/bash/
TelegramBotToken: botXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
TelegramBotOffset: 1
Loading command modules...
Loading module <list>
found command <list>
function: 0x874238
found command <dump>
function: 0x874238
Loading module <devices>
found command <scenes>
function: 0x865950
found command <devices>
function: 0x865950
Loading module <flick>
found command <flick>
function: 0x866ea0
Loading module <nflick>
found command <nflick>
function: 0x896130
Loading module <on>
found command <on>
function: 0x898500
found command <off>
function: 0x898500
Loading module <battery>
found command <batteries>
function: 0x85bac8
found command <battery>
function: 0x85bac8
Loading module <help>
found command <help>
function: 0x86aa18
Getting 1 the previous Telegram bot message offset from Domoticz
JSON request <http://USERNAME:[email protected]:8080/json.htm?type=command¶m=getuservariables>
Domoticz returned getuservariables after 1 attempts
1 user variable does not exist in Domoticz
The variable TelegramBotOffset does exist because if I run the URL in the browser, I get the following result:
Code: Select all
{
"result" : [
{
"LastUpdate" : "2015-07-29 08:00:16",
"Name" : "TelegramBotOffset",
"Type" : "0",
"Value" : "1",
"idx" : "1"
}
],
"status" : "OK",
"title" : "GetUserVariables"
}
I can't figure out what might go wrong here...
Note.
Username, password and BOT token replaced with fakes
edit, found the problem, I altered the TelegramBotOffset to ="1" in the DomoticzData.sh which caused the error.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 9:23
by Brutus
simonrg wrote:Brutus wrote:Is it possible to get this some how working on Windows?
My doorbel (picture and message) already functions with a LUA and curl using the Telegram Bot. Already happy with that but chatting to Domoticz and receiving info back would be very nice
Brutus, could be easy could be difficult, it depends on whether you have the Lua libraries available for Windows or not. If yes easy, if no then why not move to Linux. So you need to find socket, ssl and json Lua libraries for Windows. Simon
Hi Simonrg,
Thnx for your quick reply.
I will not move to Linux
Have used it serveral times (Ubuntu with domoticz compiled, RPi image domoticz pre installed). Windows gives me the best experience and stability.
- Socket: What do you meen with that?
- SSL: Can't we use the build in SSL webserver from Domoticz? Or do I need to install IIS on my computer so I can run my own webserver?
- LUA for Windows: Domoticz LUA not right? Saw some reply's in this topic that the version 5.2 is included in Domoticz. Or maybe this could do the trick:
https://code.google.com/p/luaforwindows/
Thnks again!
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 10:01
by G3rard
Egregius wrote:One thing I don't understand in the Telegram thing: how is security set?
I installed the bot once but could read and switch instantly everything, just by knowing the name of the bot.
At the moment there is no check, so if you know the name then you can use the bot.
See my earlier post in this topic for a solution I made so the bot only reacts to a known user/group. In the meanwhile simonrg is having a look at this as well.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 12:06
by supergroover
I really don't get it to work. probably it's a simple human mistake, but i can't find it.
dtb.log
Code: Select all
---------------------------------
Starting Telegram message handler
---------------------------------
DomoticzIP: ********:*********@127.0.0.1
DomoticzPort: 8080
BotHomePath: /home/pi/dtgbot/
BotLuaScriptPath: /home/pi/dtgbot/lua/
BotBashScriptPath: /home/pi/dtgbot/bash/
TelegramBotToken: 1234567890:ABCDEFGHIJKLMNOPQRSTUVQ
TelegramBotOffset: TelegramBotOffset
Loading command modules...
Loading module <list>
found command <dump>
function: 0x1384ad0
found command <list>
function: 0x1384ad0
Loading module <devices>
found command <devices>
function: 0x136a268
found command <scenes>
function: 0x136a268
Loading module <flick>
found command <flick>
function: 0x1372368
Loading module <nflick>
found command <nflick>
function: 0x13721a0
Loading module <on>
found command <on>
function: 0x1382b08
found command <off>
function: 0x1382b08
Loading module <battery>
found command <batteries>
function: 0x13b2508
found command <battery>
function: 0x13b2508
Loading module <help>
found command <help>
function: 0x13b3708
Getting TelegramBotOffset the previous Telegram bot message offset from Domoticz
JSON request <http://********:*********@127.0.0.1:8080/json.htm?type=command¶m=getuservariables>
Domoticz returned getuservariables after 1 attempts
9
TBOidx 9
JSON request <http://********:*********@127.0.0.1:8080/json.htm?type=command¶m=getuservariable&idx=9>
Decoded 2
TBO 2
https://api.telegram.org/bot1234567890:ABCDEFGHIJKLMNOPQRSTUVQ/
.Message: 1
update_id *********
?
Handle command function started with ? and *********
dtb.log.errors
Code: Select all
/usr/bin/lua: /home/pi/dtgbot/dtgbot.lua:289: bad argument #1 to 'lower' (string expected, got nil)
stack traceback:
[C]: in function 'lower'
/home/pi/dtgbot/dtgbot.lua:289: in function 'HandleCommand'
/home/pi/dtgbot/dtgbot.lua:375: in function 'on_msg_receive'
/home/pi/dtgbot/dtgbot.lua:440: in main chunk
[C]: in ?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 13:11
by simonrg
G3rard wrote:Egregius wrote:One thing I don't understand in the Telegram thing: how is security set?
I installed the bot once but could read and switch instantly everything, just by knowing the name of the bot.
At the moment there is no check, so if you know the name then you can use the bot.
See my earlier post in this topic for a solution I made so the bot only reacts to a known user/group. In the meanwhile simonrg is having a look at this as well.
I have moved the code for dtgbot to github, so it should be easier to keep updates etc, share development.
The new code catches a lot more of the simple errors and implements security.
By default it works without security, to implement security just create a string user variable in Domoticz called - TelegramBotWhiteListedIDs - the string consists of a series of ids separated by | so either a single id or multiple:
Code: Select all
TelegramBotWhiteListedIDs - 12345678
TelegramBotWhiteListedIDs - 12345678|87654321|28343999
Any unrecognised ids will be captured in the log and unrecognised id command returned.
So if you already have dtgbot and git installed, then to use the new version:
Code: Select all
sudo service dtgbot stop
sleep 60
cd ~
mv dtgbot olddtgbot
git clone https://github.com/steps39/dtgbot.git
cd ~/dtgbot
chmod 755 dtgbot
cd bash
chmod 755 *.sh
sudo service dtgbot start
The sleep 60 is just to make sure old dtgbot has stopped.
Let me know if it works for you, I will then update the wiki accordingly.
I still need to tidy up the code and implement a more intelligent logging system.
Edit: corrected need to set dtgbot to execute state.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 13:29
by simonrg
Brutus wrote:- Socket: What do you meen with that?
- SSL: Can't we use the build in SSL webserver from Domoticz? Or do I need to install IIS on my computer so I can run my own webserver?
- LUA for Windows: Domoticz LUA not right? Saw some reply's in this topic that the version 5.2 is included in Domoticz. Or maybe this could do the trick:
https://code.google.com/p/luaforwindows/
Looks like its difficult then.
In order for dtgbot to work under Windows somebody needs to have translated the libraries that handle connection with the internet from Linux (which is the basis for OSX, IOS, Android, ....) into the Windows way of working, this is non-trivial particularly for https as Windows has a different protocol/security model.
So in order for Lua to control Domoticz by http you need the Lua socket library, in order to talk to Telegram you need https this is the Lua SSL library and you need to JSON to be able to interpret what is recieved from either Telegram or Domoticz.
Lua for Windows doesn't appear to have the LUA SSL library. You need to Google / ask on a Windows forum. This might be somewhere to start -
http://notebook.kulchenko.com/programmi ... and-luasec.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 13:45
by simonrg
supergroover wrote:
dtb.log.errors
Code: Select all
/usr/bin/lua: /home/pi/dtgbot/dtgbot.lua:289: bad argument #1 to 'lower' (string expected, got nil)
stack traceback:
[C]: in function 'lower'
/home/pi/dtgbot/dtgbot.lua:289: in function 'HandleCommand'
/home/pi/dtgbot/dtgbot.lua:375: in function 'on_msg_receive'
/home/pi/dtgbot/dtgbot.lua:440: in main chunk
[C]: in ?
Not sure what's going on here, doesn't seem to like individual non-alphanumeric characters, I have patched the code to ignore them. Installing the new version mentioning in early post using Git should solve this problem.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 15:53
by supergroover
simonrg wrote:supergroover wrote:
dtb.log.errors
Code: Select all
/usr/bin/lua: /home/pi/dtgbot/dtgbot.lua:289: bad argument #1 to 'lower' (string expected, got nil)
stack traceback:
[C]: in function 'lower'
/home/pi/dtgbot/dtgbot.lua:289: in function 'HandleCommand'
/home/pi/dtgbot/dtgbot.lua:375: in function 'on_msg_receive'
/home/pi/dtgbot/dtgbot.lua:440: in main chunk
[C]: in ?
Not sure what's going on here, doesn't seem to like individual non-alphanumeric characters, I have patched the code to ignore them. Installing the new version mentioning in early post using Git should solve this problem.
Thank you.. I did the Git update as described an rebooted the Pi
It won't run and i did not get a new dtb.log or dtb.log.errors.
It wil run in putty with
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 16:03
by Brutus
simonrg wrote:Brutus wrote:- Socket: What do you meen with that?
- SSL: Can't we use the build in SSL webserver from Domoticz? Or do I need to install IIS on my computer so I can run my own webserver?
- LUA for Windows: Domoticz LUA not right? Saw some reply's in this topic that the version 5.2 is included in Domoticz. Or maybe this could do the trick:
https://code.google.com/p/luaforwindows/
Looks like its difficult then.
In order for dtgbot to work under Windows somebody needs to have translated the libraries that handle connection with the internet from Linux (which is the basis for OSX, IOS, Android, ....) into the Windows way of working, this is non-trivial particularly for https as Windows has a different protocol/security model.
So in order for Lua to control Domoticz by http you need the Lua socket library, in order to talk to Telegram you need https this is the Lua SSL library and you need to JSON to be able to interpret what is recieved from either Telegram or Domoticz.
Lua for Windows doesn't appear to have the LUA SSL library. You need to Google / ask on a Windows forum. This might be somewhere to start -
http://notebook.kulchenko.com/programmi ... and-luasec.
Hi simonrg,
Thnx again for your answer. Sorry for my noob questions
but...
I can use https in lua (with CURL) for telegram in domoticz. Isn't this good? because you are refering to a Lua SSL Library?
JSON is also available in Domoticz?
That socket Library isn't but you found it already in the internet.
I'm not good in scripting. So I need some help to get this working. But only when you are willing to!
Greetings
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 16:40
by simonrg
Brutus wrote:I can use https in lua (with CURL) for telegram in domoticz. Isn't this good? because you are refering to a Lua SSL Library?
JSON is also available in Domoticz?
That socket Library isn't but you found it already in the internet.
I'm not good in scripting. So I need some help to get this working. But only when you are willing to!
Greetings
Using Curl could be ok, but from Lua it means making an os.execute call to Curl, storing the results in a file, reading the results back into Lua. So a number of changes to dtgbot.
Are you using JSON via JQ or via a Lua library on Windows?
The link in my last post didn't appear to work for Windows, but I might have missed something.
The first thing to do is to get Lua running on Windows outside of Domoticz and see what is possible.
Then to get dtgbot working, before rewriting the code, I would suggest you find somebody who is using Lua on Windows and can point you at the libraries which are available and confirm the ones which aren't.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 29 July 2015 23:12
by G3rard
supergroover wrote:
Thank you.. I did the Git update as described an rebooted the Pi
It won't run and i did not get a new dtb.log or dtb.log.errors.
It wil run in putty with
Same here. When i run
I get the following error:
Code: Select all
/var/run/dtgbot.pid does not exist, so exiting
Edit: I can still run the old version (did a restart).
Edit2: did the following part from the wiki
Code: Select all
cd ~/dtgbot/service
sudo mv dtgbot /etc/init.d
cd ..
rmdir service
sudo update-rc.d dtgbot remove
sudo update-rc.d dtgbot defaults
sudo service dtgbot start
Still the service is not running and no logs are created.
When I do
it's working because now the pid file is there.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Thursday 30 July 2015 0:16
by simonrg
G3rard wrote:
Still the service is not running and no logs are created.
When I do
it's working because now the pid file is there.
dtgbot.lua checks for the pid file, but the service won't start if the pid file exists, equally if multiple versions of dtgbot are running things won't work, so if something has got out of sequence, then things can seem all wrong.
So my best bet is to try this sequence, basically stop any versions of dtgbot that you are running on the command line, stop the service several time, check to see if dtgbot is still running, kill any versions that are running, then check that the pid file does not exist, delete the pid if it does exist and then try starting the service again. What happens?
Code: Select all
sudo service dtgbot stop
sudo service dtgbot stop
sudo service dtgbot stop
ps -ef | grep -i dtgbot
sudo kill "followed by process number of any dtgbots still displayed above"
ls /var/run/dtgbot.pid
sudo rm /var/run/dtgbot.pid
sudo service dtgbot start
Re: dtgbot - Domoticz TeleGram BOT
Posted: Thursday 30 July 2015 0:31
by G3rard
simonrg wrote:
dtgbot.lua checks for the pid file, but the service won't start if the pid file exists, equally if multiple versions of dtgbot are running things won't work, so if something has got out of sequence, then things can seem all wrong.
So my best bet is to try this sequence, basically stop any versions of dtgbot that you are running on the command line, stop the service several time, check to see if dtgbot is still running, kill any versions that are running, then check that the pid file does not exist, delete the pid if it does exist and then try starting the service again. What happens?
Code: Select all
sudo service dtgbot stop
sudo service dtgbot stop
sudo service dtgbot stop
ps -ef | grep -i dtgbot
sudo kill "followed by process number of any dtgbots still displayed above"
ls /var/run/dtgbot.pid
sudo rm /var/run/dtgbot.pid
sudo service dtgbot start
No pid file there and ps -ef | grep -i dtgbot gave
Code: Select all
pi@raspbmc:~/dtgbot$ ps -ef | grep -i dtgbot
pi 2445 1041 0 00:28 pts/0 00:00:00 grep -i dtgbot
Then started the service but still not working.
Code: Select all
pi@raspbmc:~/dtgbot$ sudo service dtgbot status
[FAIL] dtgbot is not running ... failed!
Edit: when I start the previous version of dtgbot (renaming the folders first) that works.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Thursday 30 July 2015 0:47
by simonrg
G3rard wrote:Then started the service but still not working.
Code: Select all
pi@raspbmc:~/dtgbot$ sudo service dtgbot status
[FAIL] dtgbot is not running ... failed!
Edit: when I start the previous version of dtgbot (renaming the folders first) that works.
I need some sort of error to work out what is wrong, hasn't it produced a dtb.log.errors file?
Renaming the files means that the dtgbot in /etc/init.d is still the same, which is good, if you move /etc/init.d/dtgbot without removing the service, then Linux will still remember the old version and things could get strange.
How do you access your Raspberry Pi, ssh?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Thursday 30 July 2015 0:58
by G3rard
simonrg wrote:
I need some sort of error to work out what is wrong, hasn't it produced a dtb.log.errors file?
Renaming the files means that the dtgbot in /etc/init.d is still the same, which is good, if you move /etc/init.d/dtgbot without removing the service, then Linux will still remember the old version and things could get strange.
How do you access your Raspberry Pi, ssh?
No log file is created. I access the Pi via SSH (Putty) and with WinSCP.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Thursday 30 July 2015 1:05
by simonrg
G3rard wrote:simonrg wrote:
I need some sort of error to work out what is wrong, hasn't it produced a dtb.log.errors file?
Renaming the files means that the dtgbot in /etc/init.d is still the same, which is good, if you move /etc/init.d/dtgbot without removing the service, then Linux will still remember the old version and things could get strange.
How do you access your Raspberry Pi, ssh?
No log file is created. I access the Pi via SSH (Putty) and with WinSCP.
I have no idea, I have just sent you a pm, would need to dig around to spot what is going wrong.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Thursday 30 July 2015 1:57
by simonrg
In moving to github, I have lost the execute permission on ~/dtgbot/dtgbot, so that needs restoring:
All should be well then.
I need to learn how to set up permissions correctly in github, when transferring files from Linux to Windows to github to Linux.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Thursday 30 July 2015 7:54
by supergroover
simonrg wrote:In moving to github, I have lost the execute permission on ~/dtgbot/dtgbot, so that needs restoring:
All should be well then.
I need to learn how to set up permissions correctly in github, when transferring files from Linux to Windows to github to Linux.
That seems to work!!
thanks...
Re: dtgbot - Domoticz TeleGram BOT
Posted: Thursday 30 July 2015 21:10
by G3rard
If the bash scripts aren't working with the new version, then do the following. @simonrg, thanks that did the trick.