使用Lua传递参数控制树莓派3执行脚本

我正在尝试使用Telegram CLI来“控制”我的虚拟树莓派3。我通过参考https://pimylifeup.com/raspberry-pi-telegram-bot/在手机上向Telegram CLI发送消息并成功接收到“Pong”作为“Ping”的响应。

我创建了这个脚本: https://www.raspberrypi.org/forums/viewtopic.php?t=252300 所以我可以在我的树莓派上播放视频(当直接从CMD调用时可以执行)。

我的想法是以PLAY-YouTube链接的格式向树莓派发送消息,在LUA中捕获该消息并调用脚本播放YouTube视频。

播放YouTube视频的脚本保存为“ytplayvlc”:

#!bin/bash
youtube-dl - U -f $2 -o - "$1" | vlc -

动作脚本保存在子文件夹/tg中,并命名为“actions.lua”:

function on_msg_receive (msg)
     if msg.out then
         return
     end
     if (msg.text == 'ping') then
         send_msg (msg.from.print_name, 'pong', ok_cb, false)
     end
     local message = msg.text
     if (message.match(message, "PLAY-")) then
         send_msg (msg.from.print_name, 'Okay! This might take a second..', ok_c$, ok_cb, false)
         local link = string.match(message, "-(.*)")
         local command = [["../ytplayvlc " .. link .. " 18"]]
         os.execute(command)
     end
end
function on_our_id(id)
end
function on_secret_chat_update(user, what_changed)
end
function on_user_update(user_what_changed)
end
function on_chat_update(user, what_changed)
end
function on_get_difference_end()
end
function on_binlog_replay_end()
end

我使用以下命令启动Telegram CLI:

bin/telegram-cli -k -N --enable-msg-id tg-server.pub -W -a actions.lua

Ping-Pong运行良好,但当我发送播放YouTube视频的命令时,我会收到“好的!这可能需要一些时间。”的消息,但之后什么也没有发生。在使用Ping-Pong或YouTube命令时,我在CMD中接收到上述提到的消息后立即收到一条消息:“lua:尝试调用空值”。

我不知道为什么,如果有任何想法,请告诉我。我对上述技术毫无经验,如果我错过了一些信息,请谅解。谢谢。

点赞
用户88888888
用户88888888

我解决了这个问题!!我删除了命令周围的方括号。现在那一行是:local command = "../ytplayvlc " .. link .. " 18"

2020-06-09 09:38:59