Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Recommended Posts

Posted

try to change order

Please login or register to see this code.

to

Please login or register to see this code.

 

Posted
19 minutes ago, marczu_83 said:

try to change order

Please login or register to see this code.

to

Please login or register to see this code.

 

alright i will test in 15 min here, i did not know the order had a impact

Posted

it is correct that the order seems to make a difference and the code proceeds.

 

however i am gettng an error again due to something in the Lua2 code i guess.
sorry for the mess but i am truly quite new at this and to be honest Neato has quite the security compared to other api :-)

 

[08.11.2024] [11:25:18] [TRACE] [QUICKAPP53]: UIEvent: {"values":[],"eventType":"onReleased","elementName":"button_ID_2_1","deviceId":53}[08.11.2024] [11:25:18] [DEBUG] [QUICKAPP53]: ./include/sha2.lua:1551: bad argument #1 to 'gsub' (string expected, got nil)[08.11.2024] [11:25:18] [ERROR] [QUICKAPP53]: QuickApp crashed[08.11.2024] [11:25:18] [ERROR] [QUICKAPP53]: Unknown error occurred: handleJsonRpc

Posted

alright i found out that issue, seems to be the copy past on the signature issue, we are now on line 22 that is failing again which is the authorization.

[08.11.2024] [11:32:46] [DEBUG] [QUICKAPP53]: ./include/Neato_Robot_Info.lua:22: attempt to perform arithmetic on a string value

                ["Authorization"] = "NEATOAPP" + " " + signature,
 
 
Posted

currently stuck on the Authorization part pffff
whatever code i try i keep getting a 404 message at the moment, anyone any advice ?
 

function QuickApp:getrobotinfo()
    local robotserial = "XXXXXXXXX"
    local robotseriallow = string.lower(robotserial)
    local robotsecret = "XXXXXXXXXXXXX"
    local date = tostring(os.date("!%a, %d %b %Y %X GMT"))
    local body = '{"reqId": "77", "cmd": "getRobotState"}'
    local string_to_sign = robotseriallow .. "\n".. date .. "\n" .. body
    local signature = sha.hmac(sha.sha256, robotsecret, string_to_sign)
    local binary_hash = sha.hex2bin(signature)
    local base64_hash = sha.bin2base64(binary_hash)
    self.http = net.HTTPClient({timeout=5000})
   
    self.http:request("https://nucleo.neatocloud.com:4443/vendors/neato/robots/OPS02217-985DADC5A1BA/messages", {
          options = {
              data = json.encode(body),
              method = "POST",
              checkCertificate = false,
              headers = {
                ["Accept"] = "application/vnd.neato.nucleo.v1",
                ["Content-Type"] = "application/json",
                ["Date"] = os.date("!%a, %d %b %Y %X GMT"),
                ["Authorization"] = "NEATOAPP" .. " " .. signature,
              }
          },
          success = function(response)
              self:debug(response.status)
              self:debug(response.data)
          end,
          error = function(message)
              self:debug("error:", net.HTTPClient, message)
          end
      })
end
1 hour ago, marczu_83 said:

try to change order

Please login or register to see this code.

to

Please login or register to see this code.

 

thank you for the tip but it seems i hit the 404 error now hehe , something wrong with the way the Authorization header is formed i guess cause when i mingle there the errors differ

Posted

seems that if changed the Authorization to it accepts, however i am now facing the missing host part for some reason that is also not documented.
i added the Host Header but then i keep getting a 401 error for the moment.
any idea ?

["Authorization"] = "NEATOAPP" .. signature
Posted

host part was due to some internet connection issues, the issue still stays at a 401 error.
is the coding to bash_64 needed to perform the hmac256 ?

i think something is wrong with the signature as i tried to print all the value's and they seem to be responding correctly.
anyway to have a more complete log ?

Posted

No, its not necessary, you should check your api documentation to check how to create token,

code that you used is from switchbot api, 

 

 

Posted
11 hours ago, marczu_83 said:

No, its not necessary, you should check your api documentation to check how to create token,

code that you used is from switchbot api, 

 

 

Hi Marc, i did study it for nearly months which is why i came here cause i can get thingd to work on commandline and postman, just not in fibaro lua so i need some genius of someone cause it should be a small thing that is wrong at this point. 😅


 

Please login or register to see this link.

 

 

Under the Nucleo authentication scheme, the Authorization header has the following form:

Please login or register to see this code.

Following is pseudo-grammar that illustrates the construction of the Authorization request header. In the example, \n means the Unicode code point U+000A, commonly called newline.

Please login or register to see this code.

A Ruby example to compute the signature is as follows:

Please login or register to see this code.

Authenticating with an invalid Authorization or Dateheaders will return appropriate errors with a JSON response in the format:

Please login or register to see this code.

 

 

Posted (edited)

try

 

Please login or register to see this code.

 

and 

 

Please login or register to see this code.

change to

Please login or register to see this code.

 

Edited by marczu_83
Posted
2 hours ago, marczu_83 said:

try

 

Please login or register to see this code.

 

and 

 

Please login or register to see this code.

change to

Please login or register to see this code.

 

i just tried as i think this was a good suggestion but it is still giving me an error 401, which i think means there is something wrong in the authorization header or calculation of it.


current error:

09.11.2024] [16:35:01] [TRACE] [QUICKAPP53]: onAction: {"args":["onReleased","button_ID_2_1"],"actionName":"UIAction","manual":true,"deviceId":53}[09.11.2024] [16:35:01] [TRACE] [QUICKAPP53]: UIEvent: {"eventType":"onReleased","values":[],"deviceId":53,"elementName":"button_ID_2_1"}[09.11.2024] [16:35:01] [DEBUG] [QUICKAPP53]: onInit[09.11.2024] [16:35:02] [DEBUG] [QUICKAPP53]: 401[09.11.2024] [16:35:02] [DEBUG] [QUICKAPP53]:

this is the current code i am testing with :

 

function QuickApp:getrobotinfo()
self:debug("onInit")
    local robotserial = "OPS02217-985DADC5A1BA"
    local robotseriallow = string.lower(robotserial)
    local robotsecret = "A4A5B85AF336F2E7B3876DED5AC4A5F4A"
    local date = tostring(os.date("!%a, %d %b %Y %X GMT"))
    local body = '{"reqId": "77", "cmd": "getRobotState"}'
    local string_to_sign = robotseriallow .. "\n".. date .. "\n" .. body
    local signature = sha.hmac(sha.sha256, robotsecret, string_to_sign)
    local binary_hash = sha.hex2bin(signature)
    local base64_hash = sha.bin2base64(binary_hash)
    self.http = net.HTTPClient({timeout=5000})
   
    self.http:request("https://nucleo.neatocloud.com:4443/vendors/neato/robots/OPS02217-985DADC5A1BA/messages", {
          options = {
              data = body,
              method = "POST",
              checkCertificate = false,
              headers = {
                ["Accept"] = "application/vnd.neato.nucleo.v1",
                ["Content-Type"] = "application/json",
                ["Date"] = date,
                ["Authorization"] = "NEATOAPP" .. signature,
                --["Host"] = "nucleo.neatocloud.com:4443",
              }
          },
          success = function(response)
              self:debug(response.status)
              self:debug(response.data)
          end,
          error = function(message)
              self:debug("error:", message)
          end
      })
end
 
Posted
2 hours ago, marczu_83 said:

try

 

Please login or register to see this code.

 

and 

 

Please login or register to see this code.

change to

Please login or register to see this code.

 

Glad to say we are successfull !!!!!!!!
the issue was indeed in the authorization header :-)

by changing the code to contain the correct amount of spaces it works !

working code below. :-)
 

function QuickApp:getrobotinfo()
self:debug("onInit")
    local robotserial = "OPS02217-985DADC5A1BA"
    local robotseriallow = string.lower(robotserial)
    local robotsecret = "A4A5B84AF346F2E7B3876DED5AC4A5F4A"
    local date = tostring(os.date("!%a, %d %b %Y %X GMT"))
    local body = '{"reqId": "77", "cmd": "getRobotState"}'
    local string_to_sign = robotseriallow .. "\n".. date .. "\n" .. body
    local signature = sha.hmac(sha.sha256, robotsecret, string_to_sign)
    local binary_hash = sha.hex2bin(signature)
    local base64_hash = sha.bin2base64(binary_hash)
    self.http = net.HTTPClient({timeout=5000})
   
    self.http:request("https://nucleo.neatocloud.com:4443/vendors/neato/robots/OPS02217-985DADC5A1BA/messages", {
          options = {
              data = body,
              method = "POST",
              checkCertificate = false,
              headers = {
                ["Accept"] = "application/vnd.neato.nucleo.v1",
                ["Content-Type"] = "application/json",
                ["Date"] = date,
                ["Authorization"] = "NEATOAPP" .. " " .. signature,
                ["Host"] = "nucleo.neatocloud.com:4443",
              }
          },
          success = function(response)
              self:debug(response.status)
              self:debug(response.data)
          end,
          error = function(message)
              self:debug("error:", message)
          end
      })
end
  • Like 1
Posted (edited)

Hello.
I also needed HMAC_SHA256 in a scene, so I managed to create implementation of the algorithm which works on HC3

Please login or register to see this link.


I hope it helps you.

Edit: deleted copy of the code from my answer because it was taking too much space.

Edited by Wojtekb30
  • Like 2

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...