Hi,
How to implement code to send any information in the custom package for the HD player in node.lua package-hd-player/node.lua at master · info-beamer/package-hd-player · GitHub
Kindly provide the code.
Thanks
Arpit
Hi,
How to implement code to send any information in the custom package for the HD player in node.lua package-hd-player/node.lua at master · info-beamer/package-hd-player · GitHub
Kindly provide the code.
Thanks
Arpit
How can I get some info back from the same package in node.Lua. Actually, I want to get the asset name. What can be a better idea, MQTT or TCP. And how to implement them in node.lua
Please don’t send duplicate requests. This is basically the same question as the one already answered previously in How to retrieve the current playing asset using API?. If you have a followup question, please respond in the same post.
You cannot send MQTT from within info-beamer’s Lua environment. The only way to send data out is to use the node.client_write function, which sends out the given string to all connected clients. Use either the ibquery linked in the other post or implement your own line based TCP client by connecting to localhost:4444 from your running package service.
The protocol is line based with \n
as end of line. >
denoting data you send, <
for data received from info-beamer.
< Info Beamer [more info..]. *help to get help.\n
> *raw/root\n
< ok!\n
from this point onwards, every line (ending in \n
) triggers the input node event.
Once you complete the above handshake, the connect event is triggered and you can for example save the provided client
value in a table and later iterate over that table and use each value as an argument to client_write to send data to each client. Similarly to `connect, the disconnect event is triggered for each client disconnecting from info-beamer.
The minimal implementation to send out data to all connected clients is therefore:
local clients = {}
node.event("connect", function(client, path)
clients[client] = true -- add to list of connected clients
end)
node.event("disconnect", function(client)
clients[client] = nil -- remove from list
end)
local function send_to_all_clients(data)
for client, _ in pairs(clients) do
node.client_write(client, data)
end
end
-- Then later at any point use for example the following.
-- JSON for encoding makes it easy to send structured data and the
-- result will end up being a single line, ending in \n sent to all
-- connected TCP clients.
local json = require "json"
send_to_all_clients(json.encode({"foo" = "bar"}))
Hi, sorry about making a new topic, as I am new, I didn’t know how it works.
I understood the ibquery and the way TCP works, but not sure how to run Python at the backend, as I have to send API messages over the internet upon receiving the TCP messages sent by the node.lua.
kindly guide me on how to use Python at the backend, thanks.
I’m not sure I understand: There is no way to run python code in any kind of info-beamer provided backend. The only way info-beamer allows you to run code is on the device in the form of a package service. If you need a custom central backend for your stuff, you’ll have to operate that on servers you own.
Or maybe I misunderstood your request?
Sorry for the confusion.
I have made a TCP client in Python that runs on the Raspberry Pi itself, and its job is to get the asset name and send the information across via MQTT
Everything is working fine, it’s just that, at this point, I have to manually start the Python script from the remote terminal. I want to start my Python script every time Raspberry Pi boots up automatically.
Kindly guide me
Thanks
Arpit
Sounds good. All you now need to do is use the package service mechanism of info-beamer: Rename your main python code to service
, add the shebang line (the #!/usr/bin/python
as first line in the script), so it’s runnable when marked as executable and include it in your package.
When you deploy this package in the device, info-beamer will mark service
as executable and run it in the background.
It worked. Although, I had to add
“permissions”: {
“network”: “Needed to send data to MQTT”,
“run-as-root”: “Needed to access system resources”
}
to the node.json
Thanks
The network
permission is expected as otherwise the package cannot access the internet or local network. But run-as-root
should not be necessary and I recommend you remove that, for simplicity[1] reboot the device and see if it still works. I expect it does.
[1] Changing the content of permissions
does not immediately update the running package on the device, so you can either temporarily switch to a different package or modify the service
file itself to force it to refresh. Or just reboot the device as that applies the changed values as well.