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

Thanks. Now it works :)

 

5 hours ago, jgab said:

I have still not had time to look at the child buttons (...Clicked) problem. Will try to find time tonight,

OK, thanks

Posted

Still have few issues...

In VS I need to include LUA libraries using require command and to load (dofile) some AOS configurations files.

I'm trying to do that before your header

Please login or register to see this code.

But looks like you're validating everything from line 1 to end--HC3

In addition you have obsolete net.HTTPAsyncClient also!?

  • Topic Author
  • Posted (edited)
    5 hours ago, cag014 said:

    In addition you have obsolete net.HTTPAsyncClient also!?

    net.HTTPAsyncClient doesn't exists anymore 

    net.HTTPClient() is async per default (really async).

    If you want to run net.HTTPClient() synchronous do

    net.HTTPClient({sync=true})

    It's still the HTPClient model with callbacks but you can do tricks like

    Please login or register to see this code.

    ...the thing that always fails for beginners using HTTPClient() :-) 

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

    Still have few issues...

    In VS I need to include LUA libraries using require command and to load (dofile) some AOS configurations files.

    I'm trying to do that before your header

    Please login or register to see this code.

    But looks like you're validating everything from line 1 to end--HC3

     

    Let's try to solve this the right way.

    If it's an extra config file why don't you include it in the body of your code? Why do you need it before the header?

    You can run require() inside the header to load a file and that file can set whatever parameters in hc3_emulator() it needs.

    When the emulator starts up your code (the second time) it ignores the header (hc3_emulator is ~= false), loads your file and runs it. If you need your own libraries you should include them with the --FILE: include directive

    Ex.

    --FILE:mydir/myLibrary.lua,MyLib;

    It will load dir/myLibrary.lua and make sure that it's loaded in the same context as your main QA/Scene. The emulator can run many QAs in "parallell" so it's important that stuff end up in the right context. It's only the emulator that runs in the Lua global/start context. All user code runs in their own environments.

    The environments are restricted to the Scene and QA functions by default but you can enable "full Lua" with hc3_emulator.fullLua=true. However, doing that and then doing a dofile must make sure that the code ends up in the right context. dofile will do the right thing in "user code". I haven't patched 'require' yet I I don't think I can as it does a lot of stuff behind the scene to not double include files...

     

    Anyway, tell me a bit more about your use case and let's see if we can work out a solution.

    If you just need to read in config data do it with a dofile in the body of your code (and set hc3_emulator.fullLua=true)

     

    Btw. hc3_emulator.colorDebug is moved to

    hc3_emulator.debug.color

     

     

    Posted

    Using multiple HC3 But I can't upload it to the home center

     

     

    Please login or register to see this attachment.

    Please login or register to see this image.

    /monthly_2021_04/491446324_Inked2_LI.jpg.761aabd19ee80dadacee1e981447561b.jpg" />

  • Topic Author
  • Posted
    8 minutes ago, minsad79 said:

    Using multiple HC3 But I can't upload it to the home center

     

     

    Please login or register to see this attachment.

    Please login or register to see this link.

    Yes, the deploy command from ZBS menu only worked if you have credentials stored in file 'credentials.lua'

    The hc3_emulator.deploy=true still works.

    Anyway, I fixed it now so it works from ZBS menu v 0.299.7

     

    Posted
    On 4/13/2021 at 7:34 AM, jgab said:

     

    Let's try to solve this the right way.

    If it's an extra config file why don't you include it in the body of your code? Why do you need it before the header?

    You can run require() inside the header to load a file and that file can set whatever parameters in hc3_emulator() it needs.

    When the emulator starts up your code (the second time) it ignores the header (hc3_emulator is ~= false), loads your file and runs it. If you need your own libraries you should include them with the --FILE: include directive

    Ex.

    --FILE:mydir/myLibrary.lua,MyLib;

    It will load dir/myLibrary.lua and make sure that it's loaded in the same context as your main QA/Scene. The emulator can run many QAs in "parallell" so it's important that stuff end up in the right context. It's only the emulator that runs in the Lua global/start context. All user code runs in their own environments.

    The environments are restricted to the Scene and QA functions by default but you can enable "full Lua" with hc3_emulator.fullLua=true. However, doing that and then doing a dofile must make sure that the code ends up in the right context. dofile will do the right thing in "user code". I haven't patched 'require' yet I I don't think I can as it does a lot of stuff behind the scene to not double include files...

     

    Anyway, tell me a bit more about your use case and let's see if we can work out a solution.

    If you just need to read in config data do it with a dofile in the body of your code (and set hc3_emulator.fullLua=true)

     

    Btw. hc3_emulator.colorDebug is moved to

    hc3_emulator.debug.color

     

     

    Almost there (v0.299.8)

    1. I need to execute require()  for your code as well (to load LUA libs), meanwhile have added reuire to your code

    2. hc3_emulator.debug.color not found ! May be you refer to

    hc3_emulator.consoleColors=<table>     -- Maps fibaro.debug/self:debug etc to color (debug.color enables color debugging)

    3. Since my QA is virtual and not actually exists in HC3, but somehow it is part of the devices list  and fails because such a device no found in the system.

    Do you've anyway to ignore it ?

  • Topic Author
  • Posted (edited)
    9 hours ago, cag014 said:

    Almost there (v0.299.8)

    1. I need to execute require()  for your code as well (to load LUA libs), meanwhile have added reuire to your code

    Ok, you have added 'require' so you can execute require in the header.

    What you mean with "execute require()  for your code as well (to load LUA libs)..."?

    Show me an example.

     

    Quote

    2. hc3_emulator.debug.color not found ! May be you refer to

    hc3_emulator.consoleColors=<table>     -- Maps fibaro.debug/self:debug etc to color (debug.color enables color debugging)

    It is

    Please login or register to see this code.

    hc3_emulator.debug is copied over to _debugFlags.

     

    Quote

    3. Since my QA is virtual and not actually exists in HC3, but somehow it is part of the devices list  and fails because such a device no found in the system.

    Do you've anyway to ignore it ?

    So the idea is that your code should think it's executing on the HC3, that's why api.get("/devices") return you devices. When does it fail?

    Edited by jgab
    Posted (edited)
    18 hours ago, jgab said:

    Ok, you have added 'require' so you can execute require in the header.

    What you mean with "execute require()  for your code as well (to load LUA libs)..."?

    Show me an example.

    First of all, I'm following 10Der configuration as received from him.

    To run LUA in VS code you need to load and run libraries using require function. As you know require searches for the file in a path and controls whether a file has already been run to avoid duplicating the work.

    In our case I use require("fibaro") - following 10Der config.

    if dofile and not hc3_emulator then

        require("fibaro")

    fibaro.lua file has following paths:

    package.path = package.path .. ";./fibaro/libs/?.lua";
    package.cpath = package.cpath .. ";./fibaro/libs/?.dll";

    All that works fine in v0.158. In new version require is not allowed in your header. When require("fibaro") is not executes following require in your code is fail

    local socket  = require("socket")   

    Currently to make the code run, I've added require("fibaro") before and it works.

      require("fibaro")
      local socket  = require("socket")         -- LuaSocket, these are the dependencies we have
      local url     = require("socket.url")     -- LuaSocket
      local headers = require("socket.headers") -- LuaSocket
    Edited by cag014
    Posted
    18 hours ago, jgab said:

    So the idea is that your code should think it's executing on the HC3, that's why api.get("/devices") return you devices. When does it fail?

    Yes, but not limited to HC3 only. Currently I'm running AOR (using v0.158) where the code "thinks" it's executing on HC2.

    In general AOR could control any fibaro system (HCL / HC2 / HC3 / HC3L).

    The code fails because api.get("/devices") returns not exist device ID (in this case 3101). Where this ID assigned?

     

     

     

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

    First of all, I'm following 10Der configuration as received from him.

    To run LUA in VS code you need to load and run libraries using require function. As you know require searches for the file in a path and controls whether a file has already been run to avoid duplicating the work.

    In our case I use require("fibaro") - following 10Der config.

    if dofile and not hc3_emulator then

        require("fibaro")

    fibaro.lua file has following paths:

    package.path = package.path .. ";./fibaro/libs/?.lua";
    package.cpath = package.cpath .. ";./fibaro/libs/?.dll";

    All that works fine in v0.158. In new version require is not allowed in your header. When require("fibaro") is not executes following require in your code is fail

    local socket  = require("socket")   

    Currently to make the code run, I've added require("fibaro") before and it works.

      require("fibaro")
      local socket  = require("socket")         -- LuaSocket, these are the dependencies we have
      local url     = require("socket.url")     -- LuaSocket
      local headers = require("socket.headers") -- LuaSocket

    Ok, but I'm willing to include the package.path setting in the emulator in a compatible way.

     

    Posted
    10 minutes ago, jgab said:

    Ok, but I'm willing to include the package.path setting in the emulator in a compatible way.

     

    Agree....

  • Topic Author
  • Posted
    10 minutes ago, jgab said:

    Ok, but I'm willing to include the package.path setting in the emulator in a compatible way.

     

    For ZBS the package is set outside the user code (special ZBS config file). If the table 'package' exists I can set it according to your example. Would that work?

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

    Yes, but not limited to HC3 only. Currently I'm running AOR (using v0.158) where the code "thinks" it's executing on HC2.

    In general AOR could control any fibaro system (HCL / HC2 / HC3 / HC3L).

    The code fails because api.get("/devices") returns not exist device ID (in this case 3101). Where this ID assigned?

     

    Because your code defines a QuickApp, it will be a "virtual QA" that exists in the emulator with a invented deviceID (starting at 3101). 3101 is "your own id" and you should ignore it - like QAs typically do.

    You could run pure Lua code without being a QuickApp, but then you can't use the QuickApp class and it's functions - only fibaro.* and api.* functions.

    • Thanks 1
    Posted
    50 minutes ago, jgab said:

     

    Because your code defines a QuickApp, it will be a "virtual QA" that exists in the emulator with a invented deviceID (starting at 3101). 3101 is "your own id" and you should ignore it - like QAs typically do.

    You could run pure Lua code without being a QuickApp, but then you can't use the QuickApp class and it's functions - only fibaro.* and api.* functions.

    I'm curious... why in v0.158 it doesn't happened?

  • Topic Author
  • Posted
    1 hour ago, cag014 said:

    I'm curious... why in v0.158 it doesn't happened?

    Well, it was actually a bit buggy. Normally when developing a QA, I use the "automatic proxy" model. This means that the QA in the emulator has presence in the HC3 with a proxy QA and when doing api.get("/devices") we get the deviceId of the proxy.

    However, with the new emulator we can run multiple QAs in "parallel" in the emulator and when doing api.get("/devices") they expect to be able to find each other.

    It was "buggy" because when running in complete "offline mode" you couldn't find yourself with api.get("/devices") which a QA should be able to do.

     

    So, in your case,  isn't it easy to  filter out your own QA if it is returned by api.get("/devices").   When you run your AIO on the HC3 I guess that's the same?

     

     

     

     

  • Topic Author
  • Posted

    In v.0.299.12. 

    package is set by default to

    Please login or register to see this code.

    if the table. package exists (it doesn't in user code in ZBS), but do in. VS.

    It can also be added to in the header

    Please login or register to see this code.

     

    • Thanks 1
  • Topic Author
  • Posted (edited)

    v.299.13

    Ok, I managed to get Windows 10 and VS code to run in VirtualBox on my Mac so I could test the emulator.

    I added package defaults for libraries in the same folder (@10der style) but can also be modified with hc3_emulator.package - see previous post.

    I also ironed out some imperfections I could spot (default QA names became the whole path etc)

    I would recommend that you set

    hc3_emulator.assetDirectory=".\\"

    also, and then run (once)

    hc3_emulator.downloadAssets()

    "deviceTemplates.json" can also be downloaded manually from my GitHub and be placed in "assetDirectory".

    It will download devices templates that are used when creating QAs in the emulator (so we get the right properties etc.) - otherwise the emulator will complain each time and. create a default device that is "less accurate".

     

    I still think that VS is awkward to work with for pure Lua development. The debugger crashes in the Lua socket library when stopping the debugger now (the emulator spends most of its time these days listening to sockets :-) ) - kind of ugly. Just get the feeling that its not really well integrated and Lua is still a second class citizen in VS...

     

    Then I have my issues with Microsoft's aesthetics -- those icons are really ugly.

    And the use of colors - why do VS Code need to look like a child's toy when coding?neon.jpg.5ec42b044b0562aa076cdb5d8145b4bd.jpg

    Please login or register to see this attachment.

     

    Edited by jgab
    Posted

    [23.04.2021] [17:26:36] |[31;1mERROR[0m|: Running E:\DS_Drive\EventRunner\HC3\EventRunner4.lua - fibaroapiHC3.lua:4405: Can't openfile Backup(HC3-00001295)/
    fibaroapiHC3.lua:4405: Can't openfile Backup(HC3-00001295)/
    stack traceback:
        [C]: in function 'error'
        fibaroapiHC3.lua:5547: in function 'assert'
        fibaroapiHC3.lua:7442: in field 'write'
        fibaroapiHC3.lua:4405: in method 'save'
        [string "E:\DS_Drive\EventRunner\HC3\EventRunner4.lua"]:43: in main chunk
        [C]: in function 'xpcall'
        fibaroapiHC3.lua:4644: in local 'runQA'
        fibaroapiHC3.lua:4676: in method 'callback'
        fibaroapiHC3.lua:2603: in function <fibaroapiHC3.lua:2599>
        (...tail calls...)
    nil (coroutine: thread: 013cd3bc, socket: tcp{client}: 0134EB20)
    stack traceback:
        [C]: in function 'error'
        fibaroapiHC3.lua:4648: in local 'runQA'
        fibaroapiHC3.lua:4676: in method 'callback'
        fibaroapiHC3.lua:2603: in function <fibaroapiHC3.lua:2599>
        (...tail calls...)

     

     

     

    backup error

     
  • Topic Author
  • Posted
    9 minutes ago, minsad79 said:

    [23.04.2021] [17:26:36] |[31;1mERROR[0m|: Running E:\DS_Drive\EventRunner\HC3\EventRunner4.lua - fibaroapiHC3.lua:4405: Can't openfile Backup(HC3-00001295)/
    fibaroapiHC3.lua:4405: Can't openfile Backup(HC3-00001295)/
    stack traceback:
        [C]: in function 'error'
        fibaroapiHC3.lua:5547: in function 'assert'
        fibaroapiHC3.lua:7442: in field 'write'
        fibaroapiHC3.lua:4405: in method 'save'
        [string "E:\DS_Drive\EventRunner\HC3\EventRunner4.lua"]:43: in main chunk
        [C]: in function 'xpcall'
        fibaroapiHC3.lua:4644: in local 'runQA'
        fibaroapiHC3.lua:4676: in method 'callback'
        fibaroapiHC3.lua:2603: in function <fibaroapiHC3.lua:2599>
        (...tail calls...)
    nil (coroutine: thread: 013cd3bc, socket: tcp{client}: 0134EB20)
    stack traceback:
        [C]: in function 'error'
        fibaroapiHC3.lua:4648: in local 'runQA'
        fibaroapiHC3.lua:4676: in method 'callback'
        fibaroapiHC3.lua:2603: in function <fibaroapiHC3.lua:2599>
        (...tail calls...)

     

     

     

    backup error

     

    Can you share the commands you made?

    I guess you are trying save or read in a .fqa?

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