I’m trying to send some very basic Json commands to my Mediaportal HTPC. This is possible after installing ‘wifiremote’ on top of MediaPortal.
Commands are sent from a client to WifiRemote. Depending on the type and content of the message, actions are invoked on MediaPortal or messages are sent back to the client. Each command is a separate JSON object (‘message’) that is delimited by carriage return and line break (\r\n).
Unfortunately it does not accept commands via HTTP but only via TCP/IP.
I’m really new to LUUP programming and TCP/IP sockets.
I’ve searched the fora but very difficult to get started.
Could someone give me an idea on what LUUP code is needed to send (for example) {“type”:“command”, “command”:“pauze”} to wifiremote (on IP: XXX.XXX.XX.XXX:PORT).
Wifiremote can also receive incoming messages but as such these are not important for me.
I have tried to run the code below via 'test luup code" but I get “code failed” (and no pauze).
local wmcCmd = "command:pauze"
local socket = require("socket")
tcp = assert(socket.connect(192.168.1.40, 8017))
tcp:send(wmcCmd .. "\r\n")
tcp:close()
I have checked if the TCP connection is up and this seems the case (from another system):
Last login: Tue Sep 2 20:46:19 on ttys000
telnet 192.168.1.40 8017
Trying 192.168.1.40...
Connected to 192.168.1.40.
Escape character is '^]'.
{"Type":"welcome","Server_Version":12,"AuthMethod":0,"MPExtendedServicesInstalled":{"MAS":true,"TAS":true,"WSS":true}}
First of all adding the quotes and ‘return 0’ made the code run. However still no success. It turns out that I need to authenticate first. Via Telnet I have this working.