Build SHA-256 for authentication in Shelly PRO 2

  • Hello,

    I'm trying to build a script running on a Shelly pro 2, that uses power measurement from a remote Shelly EM.

    This shelly EM has a password set to secure its accessibility

    I try to use a "Shelly.call" function with digest authentication from the Shelly Pro 2, but fail to connect.

    I understood that the digest authentication should be performed following those steps :

    1 - A first call to Shelly EM, that recieve 401 error. The device response especially contains a specific value called 'nonce'.

    2 - Shelly pro2 shall calculate a SHA-256 value based on Shelly EM username and password, and on the previously got 'nonce' value as well.

    3 - The "Shelly.call" request shall be repeated, including this SHA-256 value in its header.

    - My issue : That process means that Selly PRO 2 shall calculate SHA-256 in step 2, but I was not able to find this feature : Shelly scripts doesn't seem to hold such a function.... I've tried pure javascript SHA-256 scripts, but none of them works due to lack of some features in shelly script to run them.

    - My Questions :

    1 / Is there a way to easily calculate SHA-256 in shelly scripts ?

    2 / If not possible, What is the suitable way to communicate between shelly devices using authentication ?

    Thanks a lot to anybody who can help me,

    Thomas

  • Hello,

    My work progresses, my difficulties too... :)

    I'm still struggling with authentication issues, but now on my Shelly PRO2 2.

    The context is still the same as in my first question (explained above). I'm now able to get datas from my shelly EM, but i need to get datas (and set actions) on the Shelly pro2 itself. I tried to look in both following directions :

    • Use "Sehelly.call" method to reach the shelly pro2 and get datas ==> In that cas, I'm still unable to build the SHA-256 hash neded to authenticate on it (as this is a gen-2 device, basic authentication does'nt work - Thanks to Devil for the tip)
    • As the script runs on the device i'm querying, I looked for a scripting keyword like "this" or "self" or something that cas refer to the current device (meaning device on which the script is running), to allow usage of "Shelly.Status" method (for example) without authentication.

    ... But I didn't succeed in any of those ways, does anybody have an idea on how to manage that ?

    Thanks by advance,

    Thomas