[EDGE] Awair Air Quality Sensor using Local API: Connection Closed issue (link to driver in post #39)

Yes. I get same error as the original post when I use cosock http

Below is the code, which fails to parse the Awair’s http response

local cosock = require "cosock"
local socket = require "cosock.socket"
local http = cosock.asyncify "socket.http"
local ltn12 = require "ltn12"
local json = require "st.json"
local utils = require "st.utils"
local log = require "log"

local function http_get(url)
	local host, path = string.match(url, "http://([^/]+)(/.*)")
	local res_body = {}
	local _, code = http.request({
			method="GET",
			url=url,
			sink=ltn12.sink.table(res_body),
			headers={
			["HOST"] = host,
			["Connection"] = "close"
		},
	})
	log.debug('[http response code] '..code)
	log.debug('[http response body] '..utils.stringify_table(res_body))
	return res_body, code
end

-- below is how you use this http_get function.
local air_json, err = http_get(device.preferences.url..'/air-data/latest')

and below is the hub log (with hub version 45.11)

2023-01-21T03:51:31.745627422+09:00 DEBUG Awair http  [http response code] [string "socket"]:1553: closed
2023-01-21T03:51:31.756460737+09:00 DEBUG Awair http  [http response body] {}

I’ve already posted raw TCP data from the Awair device, which fails to be parsed with the built in cosock http libaray.