[quote=“sle118, post:20, topic:190668”]I’ve been trying to setup a local instance of emoncms and I’m scratching my head on setting it up as a valid data provider.
First, I have created a copy of function sendValueToStorage_emoncms to sendValueToStorage_Local_emoncms, changed the url to point to the local instance, and defined it in the startup lua script.
Next, from the examples in this thread, I ran the following code in the “test lua”
[code]local json_loc = require “openLuup.json”
local newJsonParameters = {
callback = “sendValueToStorage_Local_emoncms”,
parameters = {{
default = 1,
key = “nodeid”,
label = “Node ID”,
type = “number”
},{
key = “feedid”,
label = “Feed ID”,
type = “number”
},{
key = “999999999222222222233333334444474”,
label = “Input Key name”,
type = “text”
},{
key = “999999999222222222233333334444476”,
label = “Read/Write API Key”,
type = “text”
},{
default = “http://127.0.0.1/emoncms/vis/editrealtime?feedid={1}&embed=1&apikey={3}”,
ifheight = 460,
key = “graphicurl”,
label = “Graphic Url”,
type = “url”
}},
url = “”
}
local arguments = {
newName = “emoncms_local”,
newUrl = “”,
newJsonParameters = json_loc.encode (newJsonParameters),
}
luup.call_action (“urn:upnp-org:serviceId:altui1”, “RegisterDataProvider”, arguments, AltUI)
[/code]
I was hoping to have a new data provider template added with all the defaults (and the keys). Although I now see the new data provider, I am simply unable to have the api keys “stick” in place…
I have since updated the code above. The keys had to be placed in the “key” elements of the structure; doing this resolved my initial issue. The next thing I found is that ALTUI does not save the callback parameters in the json. I was hoping a “set and forget” where I would run the code and let ALTUI restore the values when the luup engine is restarted, but that didn’t work as expected. The reason seems to be that the callback and callback names are decoupled in a separate lookup which gets constructed only when they are fully registered.
So I forked the code and added some logic to get an actual function added to the callback table if the function is found in the global table. Then I created a new pull request after testing it successfully in my own system.
https://github.com/amg0/ALTUI/pull/2[/quote]
in fact I did not support calling directly another LUA function which comes from a code I do not know ( cannot trust ). so only ALTUI internally calls a function to push to thingspeak or emoncms, but externally registered data providers using the UPNP action works exclusively with the url mecanism. The data provider must provide a url ( like a handler url if your data provider is a lua device ) that ALTUI will call with a wget() passing in argument all the data providers provided parameters in the json structure as well as lul_device lul_service lul_variable old new lastupdate values
your code is working fine but a) it poses a little supportability threat to me as ALTUI would call unknown code in its own lua space and b) I am not sure I understand fully the part of recursively searching inside the _G table, can you please explain that part a little bit ?