This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Remote control of Philips TV with json
#1
Hi,

I'm trying to write a script to control a Philips TV with json.
Based on an example in thread: http://forum.logicmachine.net/showthread...light=POST

I'm trying the following:


Code:
require('json')
require('socket.url')
require('socket.http')

fields = {key = "CursorLeft",}
data = json.encode(fields)
print(data)
post = 'data=' .. socket.url.escape(data)
print (post)
ip = '192.168.0.232:1925'

res, err = socket.http.request('http://'.. ip .. '/1/input/key', post)

print(res)
print( err)

This fails:


Code:
{"key":"CursorLeft"}
data=%7b%22key%22%3a%22CursorLeft%22%7d
<html><head><title>Bad Request</title></head><body>Bad Request</body></html>
400


Philips TV use Jointspace. Manual page for POST: http://jointspace.sourceforge.net/projec...-POST.html

Any  tips?
Reply
#2
Can you check if any GET methods are working?
Reply
#3
After a long session with Wireshark I gave up on this script...

I now use the following script which works:


Code:
require('json')
require('socket.url')
require('socket.http')
local ltn12 = require("ltn12")

path = "http://192.168.0.232:1925/1/input/key"
local payload = [[{"key" : "CursorLeft"}]]
print(payload)
local response_body = { }
local res, code, response_headers, status = socket.http.request
 {
   url = path,
   method = "POST",
   headers =
   {
         ["Content-Type"] = "application/json",
         ["Content-Length"] = payload:len()
   },
  source = ltn12.source.string(payload),
   sink = ltn12.sink.table(response_body)
 }

print('Response: = ' .. table.concat(response_body) .. ' code = ' .. code .. '   status = ' .. status,1,'Sample POST request with JSON data',-1)
Reply
#4
Probably it didn't work without proper Content-Type header.
Reply


Forum Jump: