(04.03.2021, 17:17)admin Wrote: See this example: https://forum.logicmachine.net/showthrea...4#pid17944
Replace name/filename as needed, set ctype to text/csv and finally replace /sendPhoto with /sendDocument in the URL.
hello admin
but how to attach the CSV file in the script?
I tried mentioned code but I got this in the logs :
thank you admin for your time
I want to insert the log object script such as this one
I tried but I still not tough in LUA
logtime = os.time() - 60 * 60
-- Список объектов по id
objects = {}
-- получаем объекты по которым ведется запись действий
query = 'SELECT address, datatype, name FROM objects WHERE disablelog=0'
for _, object in ipairs(db:getall(query)) do
objects[ tonumber(object.address) ] = {
datatype = tonumber(object.datatype),
name = tostring(object.name or ''),
}
end
-- получаем список действий по объектам
query = 'SELECT src, address, datahex, logtime, eventtype FROM objectlog WHERE logtime >= ? ORDER BY id DESC'
for _, row in ipairs(db:getall(query, logtime)) do
object = objects[ tonumber(row.address) ]
-- находим соответствие между объектом и типом события – запись по групповому адресу
if object and row.eventtype == 'write' then
datatype = object.datatype
-- проверяем что тип данных установлен
if datatype then
-- раскодируем данные
data = knxdatatype.decode(row.datahex, datatype)
-- удаляем null символы из char/string типов
if datatype == dt.char or datatype == dt.string then
data = data:gsub('%z+', '')
-- конвертируем date в формат DD.MM.YYYY
elseif datatype == dt.date then
data = string.format('%.2d.%.2d.%.2d', data.day, data.month, data.year)
-- time в HH:MM:SS
elseif datatype == dt.time then
data = string.format('%.2d:%.2d:%.2d', data.hour, data.minute, data.second)
end
else
data = ''
end
3. Once in BotFather type /newbot and follow instructions. As a result you will get your token and your own bot link like t.me/yourname_bot Click on the link and type any message there
4. Open browser (preferably Firefox as it converts JSON automatically) and go here https://api.telegram.org/bot<token>/getUpdates. Replace <token> with your token. As a result you should have something like that. Save your chat ID
5. Create a user library called telegram. paste this code and replace your token and chat ID
Code:
12345678910
require('ssl.https')
localtoken = 'token'-- your tokenlocalchat_id = '1234567'-- your chat idfunctiontelegram(message)
localurl = 'https://api.telegram.org/bot' .. token .. '/sendMessage'localdata = 'chat_id=' .. chat_id .. '&text=' .. socket.url.escape(message)
returnssl.https.request(url, data)
end
6. Create an event based script and use this code to send message to Telegram app:
Hi, Daniel
I just performed above recommendations. All stages were OK. But during attempt to send telegram message I obtained error - see attachments. Could you explain me the reason and how to resolve it. Thank you in advance. KR Oleg Razumovskyi.
Modify the function to run your actions based on revived text. UserID is a unique number which can be used for authorization/restrictions. username is not a unique as it is just name in your telegram account. It can be duplicated.
Hello, Daniel!
I have LM2 upgraded to 20181002 version.
I used your code for older fw.
Unfortunately, I have reply:
------------
TGtest 06.01.2024 18:30:00
* arg: 1
* nil
* arg: 2
* string: Try again
* arg: 3
* nil
TGtest 06.01.2024 18:30:04
* arg: 1
* nil
* arg: 2
* string: Try again
* arg: 3
* nil
--------------
Could you advice me the right way :-)
Thank you in advance,
KR, Oleg
Hello, Daniel!
I have LM2 upgraded to 20181002 version.
I used your code for older fw.
Unfortunately, I have reply:
------------
TGtest 06.01.2024 18:30:00
* arg: 1
* nil
* arg: 2
* string: Try again
* arg: 3
* nil
TGtest 06.01.2024 18:30:04
* arg: 1
* nil
* arg: 2
* string: Try again
* arg: 3
* nil
--------------
Could you advice me the right way :-)
Thank you in advance,
KR, Oleg
Hello Daniel!
I've found solution in your previous post "Check that you have DNS and gateway configured correctly in System config > Network > Interfaces. "
It works! Have a nice day! KR Oleg