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

  • Topic Author
  • Posted

    v0.150 uploaded.

    Added experimental support for net.WebSocketClient() and net.WebSocketClientTLS()  

    It's no difference between TLS and non-TLS, it's decided by the url, ws: or wss:

     

    It's still experimental, but it works enough to control my Samsung Q7FN from 2018.

    Here is my test QA

    Please login or register to see this attachment.

    • Thanks 1
    • 3 weeks later...
    Posted

    @jgab

    I'm trying to use HC3 emulator and have find something interesting:

    Code below works perfectly in QA and in HC2

    jGps={user={}}
    for _,j in ipairs(api.get("/users/")) do 
    jGps.user[j.id]=j.name 
    end 
    print(json.encode(jGps.user))
     
    but fails using HC3 emulator ( invalid table: mixed or invalid key types )
    What interesting that the same code fails also in HC3 scene with the same error...
     
    Everything works when using jGps.user[tostring(j.id)]=j.name 
    Any idea what's going on ?
  • Topic Author
  • Posted (edited)
    2 hours ago, cag014 said:

    @jgab

    I'm trying to use HC3 emulator and have find something interesting:

    Code below works perfectly in QA and in HC2

    jGps={user={}}
    for _,j in ipairs(api.get("/users/")) do 
    jGps.user[j.id]=j.name 
    end 
    print(json.encode(jGps.user))
     
    but fails using HC3 emulator ( invalid table: mixed or invalid key types )
    What interesting that the same code fails also in HC3 scene with the same error...
     
    Everything works when using jGps.user[tostring(j.id)]=j.name 
    Any idea what's going on ?

    It’s the same issue as 

     

    you create an lua table that doesn't have a valid json representation (a lua table with index holes as user ids are not sequentially). Converting the indexes to keys by making strings of them solves the problem. Most json encoders are strict in this sense.

    The emulator has such a strict encoder too (like HC3 scenes)... I’m not sure it makes sense to relax it as it makes code more portable by not allowing it.

    I could maybe provide a flag to emulate the buggy behavior of QAs ( I do emulate other bugs ?)

    Edited by jgab
  • Topic Author
  • Posted

    M

    1 hour ago, jgab said:

    It’s the same issue as 

     

    you create an lua table that is an ”invalid” json table (a lua table with index holes as user ids are not sequentially). Converting the indexes to keys by making strings of them solves the problem. Most json encoders are strict in this sense.

    The emulator has such a strict encoder too (like HC3 scenes)... I’m not sure it makes sense to relax it as it makes code more portable by not allowing it.

    I could maybe provide a flag to emulate the buggy behavior of QAs ( I do emulate other bugs ?)

     

    More specifically. This is the json spec:

    JSON's basic data types are:

    • Number: a signed decimal number that may contain a fractional part and may use exponential 

      Please login or register to see this link.

      , but cannot include non-numbers such as 

      Please login or register to see this link.

      . The format makes no distinction between integer and floating-point. JavaScript uses a 

      Please login or register to see this link.

       for all its numeric values (until later also supports 

      Please login or register to see this link.

      Please login or register to see this link.

      ), but other languages implementing JSON may encode numbers differently.
    • Please login or register to see this link.

      : a sequence of zero or more 

      Please login or register to see this link.

       characters. Strings are delimited with double-quotation marks and support a backslash 

      Please login or register to see this link.

       syntax.
    • Please login or register to see this link.

      : either of the values true or false
    • Please login or register to see this link.

      : an 

      Please login or register to see this link.

       of zero or more values, each of which may be of any type. Arrays use 

      Please login or register to see this link.

       notation with comma-separated elements.
    • Please login or register to see this link.

      : a collection of 

      Please login or register to see this link.

       where the names (also called keys) are strings. Objects are intended to represent 

      Please login or register to see this link.

      ,

      Please login or register to see this link.

       where each key is unique within an object. Objects are delimited with 

      Please login or register to see this link.

       and use commas to separate each pair, while within each pair the colon ':' character separates the key or name from its value.
    • Please login or register to see this link.

      : an empty value, using the word null

    So the Lua table {[7]=8, [10]=9} is neither a json array or an json object.

    Arrays should be encoded [x,y,z,...] where the indexes are sequential from start.

    Objects requires the keys to be strings.

    Unfortunately lua tables are a bit more powerful...

  • Topic Author
  • Posted (edited)
    23 minutes ago, jgab said:

    So the Lua table {[7]=8, [10]=9} is neither a json array or an json object.

    Arrays should be encoded [x,y,z,...] where the indexes are sequential from start.

    Objects requires the keys to be strings.

    Unfortunately lua tables are a bit more powerful...

     

    Actually, the QA encoder "help you" by making strings out of your sparse indexes... which leads to the interesting result:

    a = {}

    a[10]=99

    b = json.encode(a)

    a = json.decode(b)

    print(a[10])

    > nil

     

    ...because the index is now a string "10"...

    ...which is a terrible behaviour?

    Edited by jgab
  • Topic Author
  • Posted
    3 hours ago, cag014 said:

    @jgab

    I'm trying to use HC3 emulator and have find something interesting:

     

    Btw, there is a new version v.155 that supports reflecting log output to the HC3. 

    Setting hc3_emulator.HC3_debugmessages=true will result in

    self:debug("Opps")

    is also pushed to the HC3 log with the tag __TAG and type "debug" (same for trace,warning,error)

    The normal behaviour is that logs are only done in the IDE (ex. ZBS)

     

    This can be useful as IDEs normally don't support HTML in their log windows but the HC3 does...

    Posted
    15 minutes ago, jgab said:

     

    Btw, there is a new version v.155 that supports reflecting log output to the HC3. 

    Setting hc3_emulator.HC3_debugmessages=true will result in

    self:debug("Opps")

    is also pushed to the HC3 log with the tag __TAG and type "debug" (same for trace,warning,error)

    The normal behaviour is that logs are only done in the IDE (ex. ZBS)

     

    This can be useful as IDEs normally don't support HTML in their log windows but the HC3 does...

    Thanks for a prompt reply and an update 

    Posted
    6 hours ago, cag014 said:
    6 hours ago, jgab said:

    This can be useful as IDEs normally don't support HTML in their log windows but the HC3 does...

     

    Regarding support HTML color codes, could you please consider to change 

            str = str:gsub("<font color=(.-)>(.*)</font>",

    to 

            str = str:gsub("<font color=(.-)>(.-)</font>",
     

    In this case color changes in the string will be supported (for example "<font color=red> RED</font><font color=green>GREEN</font>")

  • Topic Author
  • Posted (edited)
    25 minutes ago, cag014 said:

    Regarding support HTML color codes, could you please consider to change 

            str = str:gsub("<font color=(.-)>(.*)</font>",

    to 

            str = str:gsub("<font color=(.-)>(.-)</font>",
     

    In this case color changes in the string will be supported (for example "<font color=red> RED</font><font color=green>GREEN</font>")

    Thanks that was a bug - it will still not allow for nested color tags but if they appear sequentially it's ok.

    I pushed v0.156

    What IDE are you using? VS or ZBS? Ah, Guess ZBS as the hack with color seems to work for you.

    Edited by jgab
  • Topic Author
  • Posted
    8 minutes ago, jgab said:

    Thanks that was a bug - it will still not allow for nested color tags but if they appear sequentially it's ok.

    I pushed v0.156

    What IDE are you using? VS or ZBS?

     

    So this code is to "emulate" html tags used in HC3 log messages in the IDE.

    The current "hack" only works for ZBS's log console that supports ansi codes for color changes. 

    In VS I have no idea - maybe it supports HTML tags and we can just pass them on?

    Posted

    thanks,

    I'm using ZBS

    Trying to implement All-in-one QA/Scene for debug purposes (looks like it could be used for HCL also)

    Till now it looks excellent... 99% works.

  • Topic Author
  • Posted
    32 minutes ago, cag014 said:

    thanks,

    I'm using ZBS

    Trying to implement All-in-one QA/Scene for debug purposes (looks like it could be used for HCL also)

    Till now it looks excellent... 99% works.

    If you discover things that doesn't work let me know and maybe it can be implemented.

    Posted
    5 minutes ago, jgab said:

    If you discover things that doesn't work let me know and maybe it can be implemented.

    Will do so

    Posted

    @jgab

    First of all my account has been reset...

    Regarding HC3 emulator, I'm using refreshstate but looks like  you code somehow uses also and I receive same data twice!!!

    Probably one time from my code and the second comes from you. Any idea how to stop it?

  • Topic Author
  • Posted (edited)
    26 minutes ago, cag014 said:

    @jgab

    First of all my account has been reset...

    Regarding HC3 emulator, I'm using refreshstate but looks like  you code somehow uses also and I receive same data twice!!!

    Probably one time from my code and the second comes from you. Any idea how to stop it?

    How are you doing the request?

    The emulator tries to intercept

    api.get("/refreshStates?last=...")

    and

    net.HTTPCLient():request("http://<ip>/api/refreshStates?last=..."

     

    So, how do your request look like?  full url and if you use api.get or net.HTTPClient

    Edited by jgab
  • Topic Author
  • Posted
    17 minutes ago, jgab said:

    How are you doing the request?

    The emulator tries to intercept

    api.get("/refreshStates?last=...")

    and

    net.HTTPCLient():request("http://<ip>/api/refreshStates?last=..."

     

    So, how do your request look like?  full url and if you use api.get or net.HTTPClient

     

    If you do net.HTTPCLient():request("http://<ip>/api/refreshStates?last=..."

    the ip should be 127.0.0.1

    Posted
    1 hour ago, jgab said:

     

    If you do net.HTTPCLient():request("http://<ip>/api/refreshStates?last=..."

    the ip should be 127.0.0.1

    Yes, I do net.HTTPClient, but I use IP address like 192.168.1.10. The reason doing so because ALL-in-One can control many controllers (more like master/slave concept)

    May be I have been misunderstood... I want to use HC3 emulator  as a standalone program running on PC and does not creating any QA. 

    In general it does work and I'm able to use it for HC3, HC2 and HCL. Everything works as expected (just some HTML issues).

    The problem that I have receive same refresh state from HC3 emulator and every command executed twice. 

    Again is there is any option to run it as stand alone emulator and not related to QA or device ID?

     

     

    Posted

    @jgab

    There is one more color available 

    darkgrey="\027[30;1m",

     

    Could you please add it to the next release... thanks

  • Topic Author
  • Posted
    3 hours ago, cag014 said:

    Yes, I do net.HTTPClient, but I use IP address like 192.168.1.10. The reason doing so because ALL-in-One can control many controllers (more like master/slave concept)

    May be I have been misunderstood... I want to use HC3 emulator  as a standalone program running on PC and does not creating any QA. 

    In general it does work and I'm able to use it for HC3, HC2 and HCL. Everything works as expected (just some HTML issues).

    The problem that I have receive same refresh state from HC3 emulator and every command executed twice. 

    Again is there is any option to run it as stand alone emulator and not related to QA or device ID?

     

    The emulator emulates a Scene or QA running on a HC3. I guess your master QA runs on a HC3? Then you run that QA in the emulator.

    I assume the master QA will call refreshStates on ip 127.0.0.1 to get its own events, and call refreshStates on other IPs for slaves to get their events?

    The emulator runs its own refreshStates loop and cache the result so that fibaro.getValue, fibaro.getGlobalVariable, api.get etc will get values from the cache. It also intercept http requests to 127.0.0.1/api/refreshStates to retrieve values from the cache. Http requests to other IP addresses are passed to that machine, so it should work with slaves.

    The point is to make it transparent for the QA. You can develop the master QA in ZBS and move it to the HC3 and the QA will not see the difference. You can have a "standalone" program and a QA with the same code.

    3 hours ago, cag014 said:

    @jgab

    There is one more color available 

    darkgrey="\027[30;1m",

     

    Could you please add it to the next release... thanks

    Will be in the next release. Thanks.

    Posted
    2 minutes ago, jgab said:

    I guess your master QA runs on a HC3?

    No... I don't want to run anything on HC3 or any other controller, just to run the code on PC.

    6 minutes ago, jgab said:

    The emulator runs its own refreshStates loop and cache the result so that fibaro.getValue, fibaro.getGlobalVariable, api.get etc will get values from the cache

    Right now I run a code that controls HC3 and HC2 (as a slave) and everything looks fine (I mean the values from HC2 are correct).

    Could you suggest how to stop internal refershStates  just for testing.

    Another issue, it looks like the Http timeout doesn't accept milliseconds? When I set timeout to 1000 it works, but by setting to 999, I never receive response from Http(refreshstate) 

    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...