Jump to content

Recommended Posts

10 minutes ago, petrkl12 said:

OK, now I understand

I need "only" test of pressing buttons and start correct function in ZBS for debuging 

btw. in HC2 you created http page with some buttons in ZBS and it could be also possibility how to emulate press buttons 

Ok, it's been on my todo list to make a fake web UI for QAs - I will have a look at it.

  • Thanks 1
Link to post
Share on other sites
  • Replies 113
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This is a thread for the fibaroapiHC3.lua sdk that is under development (keeping it separate from the HC3 QuickApps coding - tips and tricks thread) I've started to run and test HC3 QuickApps off

The SDK can be useful for coding and debugging large projects with a lot of moving parts. Zerobrane studio allows for setting conditional breakpoints and live variables watches which is real time save

New version v0.120. Hopefully this version is usable in Visual Studio (Windows) thanks to debugging effort from @10der.    Besides being an emulator for the HC3, fibaroapiHC3.lua is als

Posted Images

Posted (edited)

New version v 0.100

- New format for credentials file.

 A file "credentials.lua" will be loaded at startup and the table return assigned to hc3_emulator.credentials

Ex. a file that looks like

return {
  ip = "192.168.1.66",
  user = "admin",
  pwd = "admin"
}

will set hc3_emulator.credentials = { ip = "192.168.1.66", user = "admin",  pwd = "admin" }

...which are the necessary credentials to connect to the HC3.

You can also add other credentials to the table that you need to access other services. To set quickVars to the values do

if dofile and not hc3_emulator then
 hc3_emulator = {}
 hc3_emulator.quickVars{ ["HueIP"] = "$CREDS.HueIP" }
 dofile("fibaroapiHC3.lua")
end
...

this will initialise  the quickVar "HueIP" to hc3_emulator.credentials.HueIP when running QA.

 

- Web UI support. When running a QA, open http://127.0.0.1:6872/web/main (If you have the fibaroapiHC3plugin you have the short cut option-cmd-e to open browser)

  UI needs to be defined in header.  Ex.

if dofile and not hc3_emulator then
  hc3_emulator = {
    name="TestUI",
    --proxy=true,
    poll=1000,
    UI = {
      {label='status',text="Hello"},
      {button='button1', text='B1'},
      {{button='button2', text='B2'},{button='button3', text='B3'}},
      {{button='button4', text='B4'},{button='button5', text='B5'},{button='button6', text='B6'}},
      {
        {button='button7', text='B7'},{button='button8', text='B8'},
        {button='button9', text='B9'},{button='button10', text='B10'}
      },
      {
        {button='button111', text='B11'},{button='button12', text='B12'},
        {button='button13', text='B13'},{button='button14', text='B14'},{button='button15', text='B15'}
      },
      {slider='sl1', text="MySlider"},
    }
  }
  dofile("fibaroapiHC3.lua")
end

function QuickApp:button1Clicked()
  self:debug("B1")
end

function QuickApp:button2Clicked()
  self:debug("B2")
  self:updateView("sl1","value","66")
end

function QuickApp:sl1Change(ev)
  self:debug("S:",ev.values[1])
end

function QuickApp:onInit()
  setTimeout(function() self:updateView("status","text","Goodbye") end,3000)
  setTimeout(function() self:updateView("button1","text","B100") end,7000)
end

If you also have a proxy on the HC3 the sliders will be synched...

 

Here is a little demo

 

...and no, I don't think I can emulate UIs for childDevices as they use custom js controllers.

Edited by jgab
  • Thanks 1
Link to post
Share on other sites

Hello.

I am very grateful for your great work (sdk)

 

 

I have problem with new version 0.100.

 

K-20200716-862078.thumb.png.75eca02f87a90d2516f76fb24547db35.png

 

K-20200716-862142.thumb.png.748bd506d93cfdb1c7ac1d9808cb324a.png

 

K-20200717-001071.png.81563af9d68d343e93a429f599304031.png

 

 

 

and...with version 0.99

It starts when typing   hc3_emulator.start{}    eof.

if not type "hc3_emulator.start{}", it does not start.

 

I call fibaroapiHC3 with this code.

 

if dofile then 
    hc3_emulator = {id=nil, poll=nil, net={maxdelay=0, mindelay=0}, colorDebug=true, quickVars={}}
    dofile("api/fibaroapiHC3.lua")
end

blabla
blabla

hc3_emulator.start{}

 

 

Can you help me?

 

Link to post
Share on other sites
12 minutes ago, rangee said:

Hello.

I am very grateful for your great work (sdk)

I have problem with new version 0.100.

and...with version 0.99

It starts when typing   hc3_emulator.start{}    eof.

if not type "hc3_emulator.start{}", it does not start.

 

I call fibaroapiHC3 with this code.

 

Can you help me?

Yes, since .99 the way to include the emulator changed.

You should do

if dofile and no hc3_emulator then 
    hc3_emulator = {id=nil, poll=nil, net={maxdelay=0, mindelay=0}, colorDebug=true, quickVars={}}
    dofile("api/fibaroapiHC3.lua")
end

blabla
blabla

...no .start() at the end (everything moved to to header) and add "not hc3_emulator" to the initial condition.

and more that the credentials.lua format changed. See

 

Link to post
Share on other sites

@jgab Okay. THX   :)

It works but .. something wrong.

 

-- my init file
if dofile and not hc3_emulator then 
    hc3_emulator = {id=nil, poll=nil, net={maxdelay=0, mindelay=0}, colorDebug=true, quickVars={}}
    hc3_emulator.credentials = {something}
    if _QVAR then  for k, v in pairs(_QVAR) do  hc3_emulator.quickVars[k] = v end end
    dofile("api/fibaroapiHC3.lua")
end
--[[ _QVAR
_QVAR = {
    ["xx"] = "xx",
    ["yy"] = 0,
}
]]


Then error occurs. lien fibaroapiHC3.lua's  line 112x and error below.

    if hc3_emulator.quickVars then 
      local vs = self.properties.quickAppVariables or {}
      for k,v in pairs(hc3_emulator.quickVars) do self:setVariable(k,v) end
    end
--[[
number    table    4    table: 015d4530
[2020-07-17] [01:01:37] |�[31;1mERROR�[0m|: QuickApp crashed: api/fibaroapiHC3.lua:1131: Wrong parameter type, string required. Provided param '4' is type of number
api/fibaroapiHC3.lua:1131: Wrong parameter type, string required. Provided param '4' is type of number
stack traceback:
    api/fibaroapiHC3.lua:4627: in function <api/fibaroapiHC3.lua:4625>
    [C]: in function 'error'
    api/fibaroapiHC3.lua:217: in function '__assert_type'
    api/fibaroapiHC3.lua:1076: in method 'setVariable'
    api/fibaroapiHC3.lua:1131: in field '__init'
    api/fibaroapiHC3.lua:2199: in global 'QuickApp'
    api/fibaroapiHC3.lua:1589: in field 'start'
    api/fibaroapiHC3.lua:4621: in field 'fun'
    api/fibaroapiHC3.lua:832: in function <api/fibaroapiHC3.lua:820>
    [C]: in function 'xpcall'
    api/fibaroapiHC3.lua:4624: in local 'startUp'
    api/fibaroapiHC3.lua:4637: in main chunk
    [C]: in function 'dofile'
]]

 

So I changed...

 

    if hc3_emulator.quickVars then 
      local vs = self.properties.quickAppVariables or {}
      for k,v in pairs(hc3_emulator.quickVars) do 
        if type(v) == "table" then  for name, value in pairs(v or {}) do  self:setVariable(name, value) end
        else  self:setVariable(k, v)
        end
      end
    end

 

with code,  my code init successfully.

 

 

++

Did you unabled api.call(/refreshStates) ?? then why?

Can you roll-back it or give options to use or not
 

Edited by rangee
Link to post
Share on other sites
Posted (edited)
2 hours ago, rangee said:

@jgab Okay. THX   :)

It works but .. something wrong.

 

-- my init file
if dofile and not hc3_emulator then 
    hc3_emulator = {id=nil, poll=nil, net={maxdelay=0, mindelay=0}, colorDebug=true, quickVars={}}
    hc3_emulator.credentials = {something}
    if _QVAR then  for k, v in pairs(_QVAR) do  hc3_emulator.quickVars[k] = v end end
    dofile("api/fibaroapiHC3.lua")
end
--[[ _QVAR
_QVAR = {
    ["xx"] = "xx",
    ["yy"] = 0,
}
]]

Then error occurs. lien fibaroapiHC3.lua's  line 112x and error below.

 

Where does _QVAR come from? You include it yourselves? But if _QVAR is like in your example nothing wrong so far....

 

Quote
    if hc3_emulator.quickVars then 
      local vs = self.properties.quickAppVariables or {}
      for k,v in pairs(hc3_emulator.quickVars) do self:setVariable(k,v) end
    end
--[[
number    table    4    table: 015d4530
[2020-07-17] [01:01:37] |�[31;1mERROR�[0m|: QuickApp crashed: api/fibaroapiHC3.lua:1131: Wrong parameter type, string required. Provided param '4' is type of number
api/fibaroapiHC3.lua:1131: Wrong parameter type, string required. Provided param '4' is type of number
stack traceback:
    api/fibaroapiHC3.lua:4627: in function <api/fibaroapiHC3.lua:4625>
    [C]: in function 'error'
    api/fibaroapiHC3.lua:217: in function '__assert_type'
    api/fibaroapiHC3.lua:1076: in method 'setVariable'
    api/fibaroapiHC3.lua:1131: in field '__init'
    api/fibaroapiHC3.lua:2199: in global 'QuickApp'
    api/fibaroapiHC3.lua:1589: in field 'start'
    api/fibaroapiHC3.lua:4621: in field 'fun'
    api/fibaroapiHC3.lua:832: in function <api/fibaroapiHC3.lua:820>
    [C]: in function 'xpcall'
    api/fibaroapiHC3.lua:4624: in local 'startUp'
    api/fibaroapiHC3.lua:4637: in main chunk
    [C]: in function 'dofile'
]]

 

So this doesn't make sense. It seems like you call self:setVariable with number 4 as the first argument. Where did that come from?

The only way I can repeat that is if I add a '4' key to the _QVAR struct, like

  local _QVAR = {
    ["xx"] = "xx",
    ["yy"] = 0,
    [4] = 99,
}

 

Quote

So I changed...

 

    if hc3_emulator.quickVars then 
      local vs = self.properties.quickAppVariables or {}
      for k,v in pairs(hc3_emulator.quickVars) do 
        if type(v) == "table" then  for name, value in pairs(v or {}) do  self:setVariable(name, value) end
        else  self:setVariable(k, v)
        end
      end
    end

 

with code,  my code init successfully.

 

No, no, no, this will break the code if you do self:setVariable("myVar",{a=9}) which is allowed. The value to setVariable can be anything.

The bug you need to hunt down is why a number has sneaked into being a key in your quickVars.

 

Quote

++

Did you unabled api.call(/refreshStates) ?? then why?

Can you roll-back it or give options to use or not

 

api.get("/refreshStates?....") is supported when you set hc3_emulator.poll=<ms to poll>.

What kind of problems do you have? How do you use it?

 

P.S. I see that the line numbering doesn't match in fibaroapiHC3.lua. Have you added/removed code in the file? If so what code and why? There should be no reason to modify the file and if so let's make it a configurable option...

Edited by jgab
Link to post
Share on other sites
17 minutes ago, petrkl12 said:

@jgab

In new version - is there possible to create web UI directly from existing QA?

No, it must be declared in the code headers as hc3_emulator.UI = ....

...and on the HC3 it must be a proxy QA - that's the only way I can get the UI interaction on the HC3 back to ZBS (and the web GUI)

However, I will provide a function to read the UI of an existing QA and print it out as an "UI" table, so it can be pasted into the code, it that is of any help.

 

Link to post
Share on other sites

@jgab 

13 hours ago, jgab said:

. Have you added/removed code in the file? If so what code and why?

Oh. I change <function rawCall(method,call,data,cType,hs,to)> to connect hc3 at outside from my home.

(Because.. I use https to connect at outside)

I set a boolean value   "hc3_emulator.credentials.https" and add lines...

  function rawCall(method,call,data,cType,hs,to)
    if hc3_emulator.offline then return Offline.api(method,call,data,cType,hs) end
    if call:match("/refreshStates") then return Offline.api(method,call,data,cType,hs) end
    local resp,temp_url = {}, nil
    if hc3_emulator.credentials.https then  temp_url = "https://"..hc3_emulator.credentials.ip.."/api"..call
    else  temp_url = "http://"..hc3_emulator.credentials.ip.."/api"..call
    end
    local req={ method=method, timeout=to or 5000,
      url = temp_url,
      sink = ltn12.sink.table(resp),
      user=hc3_emulator.credentials.user,
      password=hc3_emulator.credentials.pwd,
      headers={}
    }

 

Anyway.. I'll explain with you orginal fibaroapiHC3.lua  sdk file.

This is  my init setting and _QVAR and  line 1126's code(self:setVariable  with function Quickapp:__init(Device))

_QVAR = {
    ["awair_ip"] = "192.168.1.21",
    ["awair_interval"] = 60,
    ["ENT_ID"] = "a2ltY2cwxxxx",
    ["ENT_SECRET"] = "091af5sxxxx",
    ["ENT_CODE"] = "bab34da56d7xxxx",
    ["ENT_interval"] = 10,
    ["OAW_station"] = "location",
    ["OAW_X"] = 99,
    ["OAW_Y"] = 99,
    ["OAW_KEY"] = "T7bTrXATUAmqxxxx",
    ["OAW_interval"] = 10,
    -- more key,value pairs and  there are no  key type number.
}

if dofile and not hc3_emulator then 
    hc3_emulator = {net={maxdelay=0, mindelay=0}, colorDebug=true, quickVars={}}
    if _USERINFO then  for k, v in pairs(_USERINFO) do  hc3_emulator.credentials = v end end -- v = {ip = "my.domain.com", user = "usr", pwd = "pwd", https=true}
    hc3_emulator.quickVars = _QVAR or {}
    dofile("api/fibaroapiHC3.lua")
end
-------------------------------
--	api/fibaroapiHC3.lua:1073: in method 'setVariable'
--	api/fibaroapiHC3.lua:1126: in field '__init'
  function QuickApp:__init(device) 
    QuickAppBase.__init(self,device)
    if hc3_emulator.quickVars then 
      local vs = self.properties.quickAppVariables or {}
      for k,v in pairs(hc3_emulator.quickVars) do self:setVariable(k,v) end
    end
    self.childDevices = {}
    self.hasProxy = plugin.isProxy
    _quickApp = self
    if self.onInit then self:onInit() end
    if not self._childsInited then self:initChildDevices() end
  end

 This is original code from yours.. and this occurs error.

 

[2020-07-17] [16:41:04] |[31;1mERROR[0m|: QuickApp crashed: api/fibaroapiHC3.lua:1126: Wrong parameter type, string required. Provided param '4' is type of number
api/fibaroapiHC3.lua:1126: Wrong parameter type, string required. Provided param '4' is type of number
stack traceback:
	api/fibaroapiHC3.lua:4618: in function <api/fibaroapiHC3.lua:4616>
	[C]: in function 'error'
	api/fibaroapiHC3.lua:217: in function '__assert_type'
	api/fibaroapiHC3.lua:1073: in method 'setVariable'
	api/fibaroapiHC3.lua:1126: in field '__init'
	api/fibaroapiHC3.lua:2190: in global 'QuickApp'
	api/fibaroapiHC3.lua:1580: in field 'start'
	api/fibaroapiHC3.lua:4612: in field 'fun'
	api/fibaroapiHC3.lua:829: in function <api/fibaroapiHC3.lua:817>
	[C]: in function 'xpcall'
	api/fibaroapiHC3.lua:4615: in local 'startUp'
	api/fibaroapiHC3.lua:4628: in main chunk
	[C]: in function 'dofile'

 

So I tried to find out what's wrong.

 

K-20200717-620396.thumb.png.cacfd3205c1a4b2aebc8088d2a3bc21e.png

 

There's something strance key  3B, 60, 2C, 48, 0E, 36, 44

I didn't add that. Where they came from?

Need more information..


      for k,v in pairs(hc3_emulator.quickVars) do print(k, type(k), type(v))
        if type(k) == "number" and type(v) == "table" then 
            for a,b in pairs(v) do  print(a,b) end
        end
        self:setVariable(k,v)
      end

 and finaly...

 

K-20200717-630631.png.47e6704b299c304c4878ffb7ea110ae7.png

 

what?   What's going on?

I just  set   hc3_emulator.quickVars = _QVAR or {}   and _QVAR has no problem.

 

Link to post
Share on other sites
40 minutes ago, rangee said:

@jgab 

Oh. I change <function rawCall(method,call,data,cType,hs,to)> to connect hc3 at outside from my home.

(Because.. I use https to connect at outside)

I set a boolean value   "hc3_emulator.credentials.https" and add lines...

  function rawCall(method,call,data,cType,hs,to)
    if hc3_emulator.offline then return Offline.api(method,call,data,cType,hs) end
    if call:match("/refreshStates") then return Offline.api(method,call,data,cType,hs) end
    local resp,temp_url = {}, nil
    if hc3_emulator.credentials.https then  temp_url = "https://"..hc3_emulator.credentials.ip.."/api"..call
    else  temp_url = "http://"..hc3_emulator.credentials.ip.."/api"..call
    end
    local req={ method=method, timeout=to or 5000,
      url = temp_url,
      sink = ltn12.sink.table(resp),
      user=hc3_emulator.credentials.user,
      password=hc3_emulator.credentials.pwd,
      headers={}
    }

 

Ok, I'll add a flag for https in the next version. I think it's better to call https.request than hope that http.request will deal with it. (It may change in the future)

 

40 minutes ago, rangee said:

Anyway.. I'll explain with you orginal fibaroapiHC3.lua  sdk file.

This is  my init setting and _QVAR and  line 1126's code(self:setVariable  with function Quickapp:__init(Device))

_QVAR = {
    ["awair_ip"] = "192.168.1.21",
    ["awair_interval"] = 60,
    ["ENT_ID"] = "a2ltY2cwxxxx",
    ["ENT_SECRET"] = "091af5sxxxx",
    ["ENT_CODE"] = "bab34da56d7xxxx",
    ["ENT_interval"] = 10,
    ["OAW_station"] = "location",
    ["OAW_X"] = 99,
    ["OAW_Y"] = 99,
    ["OAW_KEY"] = "T7bTrXATUAmqxxxx",
    ["OAW_interval"] = 10,
    -- more key,value pairs and  there are no  key type number.
}

if dofile and not hc3_emulator then 
    hc3_emulator = {net={maxdelay=0, mindelay=0}, colorDebug=true, quickVars={}}
    if _USERINFO then  for k, v in pairs(_USERINFO) do  hc3_emulator.credentials = v end end -- v = {ip = "my.domain.com", user = "usr", pwd = "pwd", https=true}
    hc3_emulator.quickVars = _QVAR or {}
    dofile("api/fibaroapiHC3.lua")
end

 

 

You declare _QVAR before "if dofile" ? ok.

I assume the loop should be 

if _QVAR then  for k, v in pairs(_QVAR) do  hc3_emulator.credentials[k] = v end end

... but it doesn't change anything. 

 

Well, setVariable will always asserts that the first arg should be a string otherwise it will throw an error.

Somehow, someone corrupts your quickVars table. ...and I don't think it's me. But let's continue to look.

When you have a number key - can you print out the json representation av the value? It seems to be a table,  maybe we can recognise the values in the table?

 

Can you also give me the whole initial ZBS log when you run the code until it crash?

Link to post
Share on other sites
Posted (edited)

@rangee I have uploaded v 0.101 on my gitHub with some extra checks. Try it and let me know.

Oh, and hc3_emulator.apiHTTPS=true will use https for api calls.    Ok, now it's fixed. just pushed a new version (still v 0.101 though)

https://github.com/jangabrielsson/EventRunner

 

Edited by jgab
  • Thanks 1
Link to post
Share on other sites
22 minutes ago, jgab said:

@rangee I have uploaded v 0.101 on my gitHub with some extra checks. Try it and let me know.

Oh, and hc3_emulator.apiHTTPS=true will use https for api calls.    Ok, now it's fixed. just pushed a new version (still v 0.101 though)

https://github.com/jangabrielsson/EventRunner

 

 

v 0.101  works with no error.

 

 

And here's error when run with v 0.100

      for k,v in pairs(hc3_emulator.quickVars) do
        if type(v) == "table" then print(k,v) for a,b in pairs(v) do  print(a,b) end end
        self:setVariable(k,v)
      end


Program 'lua53.exe' started in 'C:\Users\CG\Downloads\Fibaro' (pid: 13028).
[17.07.2020] [19:18:27] |�[35mSYS  �[0m|: HC3 SDK v0.100
[17.07.2020] [19:18:27] |�[35mSYS  �[0m|: Created Event server at 192.168.1.2:6872
�[34;1m------------------- QuickApp 'My App', deviceID:999 started at 07/17/20 19:18:27 -------------------�[0m
1	table: 01545648
name	MQTT_PW
value	pwd
[17.07.2020] [19:18:27] |�[31;1mERROR�[0m|: QuickApp crashed: api/fibaroapiHC3.lua:1128: Wrong parameter type, string required. Provided param '1' is type of number
api/fibaroapiHC3.lua:1128: Wrong parameter type, string required. Provided param '1' is type of number
stack traceback:
    api/fibaroapiHC3.lua:4621: in function <api/fibaroapiHC3.lua:4619>
    [C]: in function 'error'
    api/fibaroapiHC3.lua:217: in function '__assert_type'
    api/fibaroapiHC3.lua:1073: in method 'setVariable'
    api/fibaroapiHC3.lua:1128: in field '__init'
    api/fibaroapiHC3.lua:2193: in global 'QuickApp'
    api/fibaroapiHC3.lua:1583: in field 'start'
    api/fibaroapiHC3.lua:4615: in field 'fun'
    api/fibaroapiHC3.lua:829: in function <api/fibaroapiHC3.lua:817>
    [C]: in function 'xpcall'
    api/fibaroapiHC3.lua:4618: in local 'startUp'
    api/fibaroapiHC3.lua:4631: in main chunk
    [C]: in function 'dofile'

 

 

 

16 hours ago, jgab said:

api.get("/refreshStates?....") is supported when you set hc3_emulator.poll=<ms to poll>.

What kind of problems do you have? How do you use it?


I use api.get("/refreshStates" ..)  in some of my QA to trigger the device like your ER4.

some QA(A) not uses api.get("/ref...")  some QA(B) uses.

Before v 0.98.. it was not problem.

But after v 0.100,  I need to change   hc3_emulator.poll=ms  when I test QA(B) and hc3_emulator.poll=nil when I test QA(A).

I do not need polling when I work with QA(A)

 

But.. if you need to do it this way..  remain it.  I will adapt it.

 

I found _debugFlags and  set _debugFlags.trigger = false...  no more trigger message.

 

Link to post
Share on other sites
8 minutes ago, rangee said:

 

v 0.101  works with no error.

 

 

And here's error when run with v 0.100

      for k,v in pairs(hc3_emulator.quickVars) do
        if type(v) == "table" then print(k,v) for a,b in pairs(v) do  print(a,b) end end
        self:setVariable(k,v)
      end


Program 'lua53.exe' started in 'C:\Users\CG\Downloads\Fibaro' (pid: 13028).
[17.07.2020] [19:18:27] |�[35mSYS  �[0m|: HC3 SDK v0.100
[17.07.2020] [19:18:27] |�[35mSYS  �[0m|: Created Event server at 192.168.1.2:6872
�[34;1m------------------- QuickApp 'My App', deviceID:999 started at 07/17/20 19:18:27 -------------------�[0m
1	table: 01545648
name	MQTT_PW
value	pwd
[17.07.2020] [19:18:27] |�[31;1mERROR�[0m|: QuickApp crashed: api/fibaroapiHC3.lua:1128: Wrong parameter type, string required. Provided param '1' is type of number
api/fibaroapiHC3.lua:1128: Wrong parameter type, string required. Provided param '1' is type of number
stack traceback:
    api/fibaroapiHC3.lua:4621: in function <api/fibaroapiHC3.lua:4619>
    [C]: in function 'error'
    api/fibaroapiHC3.lua:217: in function '__assert_type'
    api/fibaroapiHC3.lua:1073: in method 'setVariable'
    api/fibaroapiHC3.lua:1128: in field '__init'
    api/fibaroapiHC3.lua:2193: in global 'QuickApp'
    api/fibaroapiHC3.lua:1583: in field 'start'
    api/fibaroapiHC3.lua:4615: in field 'fun'
    api/fibaroapiHC3.lua:829: in function <api/fibaroapiHC3.lua:817>
    [C]: in function 'xpcall'
    api/fibaroapiHC3.lua:4618: in local 'startUp'
    api/fibaroapiHC3.lua:4631: in main chunk
    [C]: in function 'dofile'

 

Good that it solved itself.

 

8 minutes ago, rangee said:

I use api.get("/refreshStates" ..)  in some of my QA to trigger the device like your ER4.

some QA(A) not uses api.get("/ref...")  some QA(B) uses.

Before v 0.98.. it was not problem.

But after v 0.100,  I need to change   hc3_emulator.poll=ms  when I test QA(B) and hc3_emulator.poll=nil when I test QA(A).

I do not need polling when I work with QA(A)

 

But.. if you need to do it this way..  remain it.  I will adapt it.

 

I found _debugFlags and  set _debugFlags.trigger = false...  no more trigger message.

 

 

Yes, fibaroapiHC3 will poll and store events/triggers in an internal queue (polling every ms given in  hc3_emulator.poll).

All user calls to api.get("/refreshStates...) will get events/triggers from that queue.

If hc3_emulator.poll=nil it will not add triggers to the internal queue and you will not receive any triggers with api.get("/refreshStates...).  However, if you run in offline mode (hc3_emulator.offline=true) calling simulated devices will push triggers to that queue....

So there is no way to get /refreshStates without going through the fibaroapiHC3 internal queue now.

The reason is that the emulator wants to call the HC3's /refreshStates to get current states and if user code also do it it will put too much load on the HC3. Instead user code will get /refreshStates values from the values the the emulator has fetched. It also makes it easier handle "offline" mode to have an internal queue...

If you don't need polling set hc3_emulator.poll=false

 

Yes, hc3_emulator._debugFlags have some flags that turn on/off various debugging messages.

  • Thanks 1
Link to post
Share on other sites

Workflow with fibaroapiHC3

I thought I'm going to share my workflow when I develop QuickApps these days.

  1. Make sure that you have downloaded the latest fibaroapiHC3plugin.lua from my GitHub and installed it. It gives, besides tooltips and completion for fibaro api commands, also keyboard shortcuts for some practical things.
  2. Make sure that you have a credentials.lua file with the HC3 credentials
  3. Open new empty window in ZBS and choose Edit-HC3 SDK templates...->QuickApp
    This will insert skeleton code in the buffer for a QuickApp with the right headers to include the emulator etc.
  4. Edit hc3_emulator properties, names etc.
  5. Add hc3_emulator.UI table for buttons sliders etc.
  6. No hc3_emulator.proxy yet...
  7. Add code. In your code you can do a  'require("<Lua file>")' to include a file with common functions that you often use in your QuickApps. It should be the filename without .lua. It's best if the file resides in the working directory.
  8. Run
  9. Open the web QA interface with View->HC3 Emulator (shortcut option-cmd-E)
    Check that buttons sliders labels works
  10. If everything looks ok. add  hc3_emulator.proxy=true
  11. Run again
  12. Check that the proxy app on the HC3 works with UI interaction etc. Look at the HC3 log for the QA to see if there is something the emulator missed.
  13. Everything works?
  14. add hc3_emulator.deploy=true
  15. Run
  16. The emulator will create a QuickApp with the real code on the HC3. It will substitute any 'require' in the code with the required file's code, because the HC3 doesn't support 'require'
  17. Voila, you have developed and debugged your QuickApp offline and then deployed the working version to the HC3.

(video may come...)

Link to post
Share on other sites
On 4/18/2020 at 10:51 AM, jgab said:

You need to have installed https://github.com/xHasKx/luamqtt so that require("mqtt") works from fibaroapiHC3.lua

 

Would it be possible for you to add a quick post showing how to install luamqtt ? I am running ZeroBrane on Windows 10.    Sorry - I tried but got in a mess...

 

http://www.thijsschreijer.nl/blog/?p=772

 

Update 

I've played some more and it's a lot of work it seems just to add the mqtt library - I have memory errors being thrown from luarock during the install of luasocket and apparently that's a 64 bit vs 32 bit issue so I'm going to give up on the mqtt library install and just use your great sdk for other things.  The installed luasocket version was too old to satisfy the dependency.

 

If anyone has a step by step or easy install I'll give it a go but for now I'll debug mqtt directly on HC3.

 

Edited by xAPPO
more info
Link to post
Share on other sites
Posted (edited)
3 hours ago, xAPPO said:

 

Would it be possible for you to add a quick post showing how to install luamqtt ? I am running ZeroBrane on Windows 10.    Sorry - I tried but got in a mess...

 

http://www.thijsschreijer.nl/blog/?p=772

 

Update 

I've played some more and it's a lot of work it seems just to add the mqtt library - I have memory errors being thrown from luarock during the install of luasocket and apparently that's a 64 bit vs 32 bit issue so I'm going to give up on the mqtt library install and just use your great sdk for other things.  The installed luasocket version was too old to satisfy the dependency.

 

If anyone has a step by step or easy install I'll give it a go but for now I'll debug mqtt directly on HC3.

 

Unfortunately, Windows and I parted ways many years ago...

Do you run the latest version of ZBS? I think that there were some updates of the Luasocket version, but maybe that's what causes the issue. ZBS has it's own version of luasocket that's come with the installation (and own versions of Lua) so you shouldn't need to install it

The http://www.thijsschreijer.nl/blog/?p=772 is an ancient article (2013) and everything (Lua, luasocket) comes with the ZBS installation these days (parts are written in Lua).

https://studio.zerobrane.com/doc-installation

 

.luamqtt  is a pure lua library so I pulled it down as a directory named 'mqtt' in my ZBS working directory. require("mqtt") will look in wd.

MacBook-Pro-3:EventRunner jgab$ pwd
   /Users/jgab/EventRunner                       <-- My working directory where I place fibaroapiHC3.lua
MacBook-Pro-3:EventRunner jgab$ ls mqtt          <-- Subdirectory where mqtt files are placed
bit53.lua       init.lua        luasocket_ssl.lua   protocol4.lua
bitwrap.lua     ioloop.lua      ngxsocket.lua       protocol5.lua
client.lua      luasocket.lua   protocol.lua        tools.lua

But I'm all MacOS.

@10der, have you tried fibaroapiHC3 with MQTT with VS? Need to install https://github.com/xHasKx/luamqtt so that require("mqtt") works.

 

Anyway, I have only played a little with the MQTT functionality so I'm not sure I have got all the messages right (the way they do it on the HC3). So, if someone does something serious with fibaroapiHC3 and MQTT it would be great as we could iron out the differences...

Edited by jgab
Link to post
Share on other sites
2 hours ago, jgab said:

have you tried fibaroapiHC3 with MQTT with VS

Done. Installed. 
trying to understand what is next ;) 

Jan can you give a example what I should test.

thank you

Link to post
Share on other sites
1 hour ago, 10der said:

Done. Installed. 
trying to understand what is next ;) 

Jan can you give a example what I should test.

thank you

Well, I manage to run code like this

if dofile and not hc3_emulator then
  hc3_emulator = {
    name="MQTT test",
    proxy=false,
    poll=2000,
  }
  dofile("fibaroapiHC3.lua")
end

function QuickApp:onInit()
  self:debug("onInit")
  local function handleConnect(event)
    self:debug("connected: "..json.encode(event))
    self.client:subscribe("test/#")
    self.client:publish("test/blah", "test".. os.time())
  end
  self.client = mqtt.Client.connect('192.168.1.50', {clientId="HC3"})
  self.client._debug = true
  self.client:addEventListener('published', function(event) self:debug("published: "..json.encode(event)) end)  
  self.client:addEventListener('message', function(event) self:debug("message: "..json.encode(event)) end)
  self.client:addEventListener('connected', handleConnect)
end

 

Link to post
Share on other sites

@jgab updated module now req lfs what not installed in my env

well.  i have fixed. copy from ZBS.

continue testing

Link to post
Share on other sites

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