Hi,
I’m currently using Ruby to interface Savant home automation systems with Ezlo. I used PTY with cURL to handle it originally, but with the latest macOS it causes issues with forkpty where the terminal stops working after about 3 days. This is due to the constant cURL to the Ezlo for broadcasts that disconnects for some reason every 30 seconds.
I’ve rewritten all of the script to use Net::HTTPS but the broadcasts are causing me headaches. If I use cURL it works fine. If I use Net::HTTPS, it does not. I also attempted to use event machine-websockets and no joy either.
I enabled debug on a separate script that I’m using just to test accessing /v1/broadcasts and this is what I get:
#Net::HTTP::Get:0x00007ffa780b9080
opening connection to 192.168.x.x:17000…
opened
starting SSL for 192.168.x.x:17000…
SSL established
← “GET /v1/broadcasts HTTP/1.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: /\r\nUser-Agent: Ruby\r\nAuthorization: Basic TOKENHERE\r\nConnection: keep-alive\r\nContent-Type: text/event-stream\r\nAccess-Control-Allow-Origin: *\r\nHost: 192.168.x.x:17000\r\n\r\n”
→ “HTTP/1.1 200 OK\r\n”
→ “content-type: text/event-stream\r\n”
→ “connection: close\r\n”
→ “access-control-allow-origin *\r\n”
Conn close because of error wrong header line format
The script tops there. It looks like the access-control-allow-origin is sent back without a colon so Ruby throws an error. Any ideas what’s going on? I’m using an Ezlo Plus Hub.
require 'net/http'
require 'net/https'
require 'uri'
require 'openssl'
request = []
$port = ":17000"
$commandURL = "https://"
$ipaddress = "192.168.x.x"
#uri = URI.parse("https://192.168.x.x:17000/v1/method/hub/items/list")
uri = URI.parse("https://192.168.x.x:17000/v1/broadcasts")
http = Net::HTTP.new(uri.host, 17000)
http.set_debug_output($stderr)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
request['authorization'] = 'Basic TOKENHERE'
request['connection'] = 'keep-alive'
request['Accept-Encoding'] = 'gzip, deflate'
request['content-type'] = 'text/event-stream'
request['Access-Control-Allow-Origin'] = '*'
puts request
response = http.request(request)
puts response
puts response.body
puts response.code