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.

Fibaro HC3 to homeLYnk
#1
I try to past some data from the Fibaro HC3 gateway (also LUA) to a homeLYnk (2.5.1) but received an error 401.

The same credentials and url works in my browser or from HL to HL. 

Anyone a idea why the HL doesn't accept data in that way?

Code:
1234567891011121314151617181920212223242526
function testHttp(self)     local address = "http://XXX:XXX@XX.XX.XX.XX/scada-remote/request.cgi?m=json&r=grp&fn=write&alias='32/1/1'&value=true"     self.http = net.HTTPClient({timeout=3000})     self.http:request(address, {         options={             headers = {                 Accept = "application/json"             },             checkCertificate = false,             method = 'GET'         },         success = function(response)             self:debug("response status:", response.status)             self:debug("headers:", response.headers["Content-Type"])             local data = json.decode(response.data)         end,         error = function(error)             self:debug('error: ' .. json.encode(error))         end     }) end function QuickApp:onInit()     self:debug("onInit")     testHttp(self) end
Reply
#2
Don't use single quotes in alias parameter. Also try replacing each / in alias with %2F
Reply
#3
(15.09.2020, 14:54)admin Wrote: Don't use single quotes in alias parameter. Also try replacing each / in alias with %2F

solved, using a basic authorization header
Reply
#4
I am trying to make a simple integration between HC3 and LM5.
With Home Center 2 it was working fine but, now since I migrated to Home Center 3, HTTP method just doesn't work as before.
I know I have success on the HTTP communication because it debugs the success response. but I always get the following response as "success message":

[DEBUG] [RESPONSE ]: Unknown parameter "m" (mode)

Here is my code:
Code:
123456789101112131415161718192021222324252627282930313233
local ip = "192.168.1.100"; -- Logic Machine IP Address local address = "1/1/2"; -- Group Address to be written on Logic Machine local http = net.HTTPClient(); -- Http connection request local zwIdStatus = fibaro.getValue(38, "value") -- Fibaro Device current value local zwDevStatus = 0 -- Numeric variable for the string concatenation if zwIdStatus == "true" then zwDevStatus = 1 elseif zwIdStatus == "false" then zwDevStatus = 0 end http : request('http://'.. ip ..'/scada-remote?m=json&r=grp&fn=write&alias='..address..'&value='..zwDevStatus,  {     options = {         method = "GET",         checkCertificate = false,             headers = {             ['Authorization'] = 'Basic cmVtb3RlOlRlY25vcnRlMjAxNA==',             Accept = "application/json",                       },         data = ""     },     success = function(response) fibaro.debug ("RESPONSE ", response.data)     fibaro.debug("HEADERS:", response.headers["Content-Type"])      end,     error = function(err) fibaro.debug ("Error:" .. err) end }); fibaro.debug('DEVICE VALUE = ', zwDevStatus)

Can anyone see what's wrong?
Reply
#5
1. Correctly escape address: "/" should be replaced with "%2f":
Code:
1
local address = "1%2f1%2f2"
2. Try removing data = "" field
3. You can also try sending the same request to httpbin, it will return the list of variables that were passed so you can at least check if GET arguments are sent correctly:
Code:
1
http:request('http://httpbin.org/get?m=json&r=grp&fn=write&alias='..address..'&value='..zwDevStatus,
Reply
#6
Send you a pm with my working code
Reply
#7
(08.10.2020, 07:11)admin Wrote: 1. Correctly escape address: "/" should be replaced with "%2f":
Code:
1
local address = "1%2f1%2f2"
2. Try removing data = "" field
3. You can also try sending the same request to httpbin, it will return the list of variables that were passed so you can at least check if GET arguments are sent correctly:
Code:
1
http:request('http://httpbin.org/get?m=json&r=grp&fn=write&alias='..address..'&value='..zwDevStatus,

The problem seems to be the recognition of the query param m=json.
By testing with "postman" software, I can get the same "response body" (Unknown parameter "m" (mode)), everytime I remove the query param m=json.

See picture below.

Notice the GET request without the parameter on top and the response on bottom.



As soon as I insert the param on the GET request, I get the correct response body, in this case "true".

This means that the result I am having on the Home Center 3, is due to the query param m=json, that is not being sent correctly from the Home Center 3.

I understand that this is more like a HC3 problem and not the LM5 problem, but maybe I can "encode" the request in any other way... I am not very experienced in LUA...
Thaks in advance.
Reply


Forum Jump: