That works and I can grab the AuthCookie as follows
res:match('(AuthCookie=[^;]+)'..';')
Many thanks!
My previous logic to retrieve info from the various API endpoints on the Powerwall also needs to be updated to pass the AuthCookie.
How can I use client : send to send the cooke as part of a GET request?
And also is there an easy way to return the result to a table to allow easy extraction of the returned data?
Here's the old code I'm trying to update
Many thanks
Kind Regards
James
res:match('(AuthCookie=[^;]+)'..';')
Many thanks!
My previous logic to retrieve info from the various API endpoints on the Powerwall also needs to be updated to pass the AuthCookie.
How can I use client : send to send the cooke as part of a GET request?
And also is there an easy way to return the result to a table to allow easy extraction of the returned data?
Here's the old code I'm trying to update
Code:
requestURL = 'https://POWERWALLGATEWAYIP/api/meters/aggregates'
requestData = ''
requestPostResponse = {}
token = GetUserParam('Wired', 'TeslaPowerwallLocalAccessToken')
res, err, commandPostHeaders, status = https.request
{
url = requestURL,
method = 'GET',
protocol = 'tlsv12',
headers =
{
cookie = token,
['Accept'] = '*/*',
['Content-Type'] = 'application/json',
['Content-Length'] = requestData:len()
},
source = ltn12.source.string(requestURL),
sink = ltn12.sink.table(requestPostResponse)
}
if err == 200 then
mydata = json.pdecode(table.concat(requestPostResponse))
teslaPowerwallPercentCharged = mydata.percentage
else
log('Error retrieving Tesla Powerwall Battery Charge ' .. tostring(err))
getTeslaPowerwallLocalAccessToken();
end
Many thanks
Kind Regards
James