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.

http post/request
#1
I'm trying to sent a command to a homewizzard socket, to put him on and off, but really don't know how to sent the command.

I can read the value's but don;t know to sent it on and off.

hope someone can help me?

this is what i use to read
Code:
require('socket.http')

ip = '192.168.99.73'         --Ip adres of the socket

socket.http.TIMEOUT = 5
data = socket.http.request('http://'..ip..'/api/v1/state')

--{"power_on":true,"switch_lock":true,"brightness":0}
if data then
log('HW socket: Televisie: State'..data)
        end

this is what the site said about the command.
Code:
Turn on socket

<Request>
PUT http://{IP address}/api/v1/state HTTP/1.1
Content-Type: application/json
Content-Length: <length>
{
   "power_on": true
}

<Response>
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: <length>

{[url=https://homewizard-energy-api.readthedocs.io/endpoints.html]page of HomeWizzard[/url]
   "power_on": true
}


what i get when read the url:
P1 HomeWizzard TEST 08.08.2023 12:57:02
* string: HW socket: Televisie: State{"power_on":true,"switch_lock":false,"brightness":0}
Reply
#2
Try this:
Code:
json = require('json')
http = require('socket.http')

body = json.encode({
  power_on = true
})

resp, code, hdrs, stat = http.request({
  url = 'http://{IP address}/api/v1/state',
  method = 'PUT',
  headers = {
    ['Content-Type'] = 'application/json',
    ['Content-Length'] = #body,
  },
  body = body
})

log(resp, code, hdrs, stat)
Reply
#3
Thanks a lot, this is working.
Reply


Forum Jump: