Development: Devices, Inputs and Feeds in emoncms

First of all: yes, the last pull request contained only some few bugfixes :slight_smile:
One of the bugfixes results in a quite noticable change though, as a device will be initialized immediately at device creation now. I did not see any reason to wait with the initialization to be honest… but I get the feeling that the device module may be used differently than I anticipated^^ Which is the reason why the current version rewrites all processlists to the template default.
In the use-case I had mainly in mind, a device will be created and initialized just once - and a re-initialization would then only be necessary if I experimented too much with my processes or feeds and something went terribly wrong^^

With the latest pull-request I added at least a small warning-line regarding the processList reset at the init-dialog.

Regarding the dry-run: nothing is impossible :wink: and most of the necessary code can be copied but currently there is only one single api route ./device/template/init.json?id=1 with the device id as sole parameter to initialize the device… as the device type etc. can be fetched backend-wise.
A collapseable text-box would be much easier at first, maybe even parsed or “nicely” displayed JSON like chrome or firefox does it.

To get a little more creative with the input and feed names in terms of e.g. variables in the template, I’d be strongly in favor^^
What I currently do is quite patchy/not very creative as (in my device-control branch) I just added a “prefix”: <name|node> option in the templates, which will be taken into account for all inputs and feeds if the keyvalue is present. For example the feeds with the names “use” and “use_kwh” in the template would be created as “foo_use” and “foo_use_kwh” if the device name was chosen “foo” with “prefix”:“name”.
If we can agree on something nice and sustainable for future developments, I’d gladly implement it :wink:

Hi Adrian

It sounds like we have been using the device module in similar ways. Prior to now, I thought of it as a very powerful tool but not overly user friendly, the sort of thing I would recommend a dev/admin using for rapid replication of complex processing, but not really ready for the casual user, mainly because the learning curve to only use it once or twice was a bit steep.

I have a load of templates and quite often they get edited for specific jobs as it’s easier to edit the template before each run than manually add all the inputs, processing and feeds the original way or even to edit after device creation.

I also have a bash script with some default.json files that I can just edit a couple of variables and it uses sed routines to change various keywords I have placed throughout my base templates, it then spits out a new single use json file for use in the device module. It sounds odd I know to produce single use templates but it really cuts my workload down no end, alas I know much of what I use is bespoke so I do not expect the device module to accommodate all my needs.

Personally, I would prefer the devices were not initialized as they were created. But it’s a minor point and may need rethinking anyway if there is to be a dry-run type confirmation.

Regards the API, there are many options, First is that users/scripts using the API directly will probably have greater confidence than the casual GUI user so there could be a simple assumed “force yes” arg to skip the dry-run. Or a second API can be used so the emoncms webpage can call “dryrun” first and “init” if confirmed, I imagined these to be the same process, where the expected result is output to screen rather than actually completing as I assumed the device module should check it can do the full initialization before starting it and fail part way through, although I’m guessing the new method should reduce the chance of it failing, previously it could create half the feeds before finding a duplicate and aborting, often ( I speak from experience) this could be caused by something as simple as a typo, the feed “power1” was created then the device initialization failed when it couldn’t find feed “pwer1” when incorrectly defined in the input processing, IMO any attempt to create this device (via API or GUI) should complain/fail before creating any feeds so IMO it should not create the first feed until it has done a “dry-run” regardless of whether user confirmation is requested, so pausing at the end of the first pass for the user to confirm would be a small addition in this instance.

The thing that causes me the biggest headache is cross device totaling, I’m guessing that with this new version, because of the “just add what doesn’t already exist” approach. I’m hoping that I can add to that a facility to define feeds by tag and feedname in the input processing so I can create “summary” nodes, in which I can define 3x “Power1” feeds (tagged as L1, L2 & L3) and define a process list of +feed “L1: Power1”, +feed “L2: Power1”. +feed “L3: Power1”, logtofeed “Summary:PowerTotal” (not sure that would be acceptable syntax, but you get the gist), Then (hopefully) when the L1, L2 and L3 nodes are created they should use those 3 existing Power1 feeds. Currently I expect the tag for any feeds named in a processlist to be assumed to be equal to the nodename of that device, so defining +feed Power1 three times isn’t going to have the desired effect, but that is pretty much what I do now, I add 3x +feed “dummy_feed” and then go in afterwards and edit the target feed by selecting from the dropdown on the inputprocessing editing page.

I’m happy to help with any of this if I can as I do use it quite a lot, my php isn’t great but I can muddle though.

PS this isn’t a list of demands, just throwing idea’s out there for consideration, if my php was better and my diary slimmer, I would happily give it a go on my own.

So this morning I need to set up another user account, 4 devices on my live server which was fully updated last night so it is emoncms master 9.8.11 but there is no versioning in the device module yet, but it is fully updated from master branch as of now (10:25 16/11/2017) .

When I used a template I used before the screens etc were all familiar (as not running device-integration branch on live server) and all appeared to go well, except… No processlists were created! Feeds and inputs all seem to be present, but no processlists at all.

Since I have a test server i’ve just set up, I thought I could try that too. That is also fully updated but is running the device-integration branch of the device module and emoncms itself is the master branch. I was able to create a device, all looked ok until I tried to initialise it, I got this error message


as you can see, not much to go on and a quick check found no inputs or feeds created, looking at the device page again I could see there was no “type”
returning into the modal device setup page again, I can select the template and edit the fields, but when saved it does not retain the type. I have confirmed this in phpmyadmiin.

Since this was using the “device-integration” branch of the device module, I thought I would try switching the branch and try the master branch with a default template (in case there was something wrong with my template) on a totally stock, fully updated, master branch only install.

This time, familiar actions and responses all as expected and the emonTH was created, but without any processlists.

Now I’m a bit stuck, I have a deadline to meet and cannot currently use the device module, any clues how to fix? device module isn’t tagged so I cannot easily roll back. Right now I do not now which is the faster option, manually creating all the processing by hand, trying to locate/fix the issue or to try and roll back the repos to a known good point by trying to extract files from an image backup.

Current situation for the account/user I’m working on is there are no processlists and even if I find a fix, I cannot re-use the “master” device module without deleting all the created inputs and feeds. I also currently cannot use the “device-integration” branch as that has no “type” for initiation or re-initiation.

I’m gonna move on to another part of that same project for now, in hope I get a reply with some assistance here, otherwise I think I will have to start manually adding the horrendously long processlists.

Any suggestions please @TrystanLea or @Adminde

Just tried another quick test, I have rolled back my test server to emoncms 9.8.8 and switched back to the device-integration branch of the device module. Re-running the initialisation again for the emonTH did not add the processlists.

The roll back to 9.8.8 suggests this isn’t anything to do with the security fixes by @TrystanLea yesterday.

Since the device now has a type from the first run being completed by the master branch device module, re-running the initialization with the "device-integration branch device module should have added the missing processlists but it hasn’t, this suggests the failure to save the “type” is unrelated to this issue.

Clicking the new edit button from the device page brings up the modal page with the emonTH already highlighted to the new branch is definitely able to see the type saved by the old branch.

Hi @pb66

sorry for that

I tested all my stuff with the emoncms/device-support branch and yesterday @TrystanLea merged quite some changes, including the group-support or at least something related to that.

This changed the $input/$feed->set_processlist function, which broke the whole device module. I created a pullrequest - maybe this fixes your problem?

Thanks @Adminde, I updated the set_processlist function yesterday to sort the issue here: Important Emoncms security update for multi-user emoncms installations V9.8.11 as the processlists where not being validated for input and feed ownership permissions.

@pb66 I will make a patch for the master branch of the device module for you, @Adminde has fixed it in the device-integration branch

Thanks guys but I have already tried backdateing to 9.8.8 emoncms and the problem still exists, so are you saying there were changes made after 9.8.8 that effectively got undone yesterday?

I’m guessing I will have to use the “device-integration” branch if I’m to recover this situation as the original “master” device module does not do re runs unless I delete all the feeds already created (and there are a lot).

As it stands if there’s only a fix for creating the processlists I will still need to create devices with the master branch and only update devices with the “device-integration” branch.

@pb66 can you not update to latest emoncms master and then I will patch the device master branch to fix the set_processlist function?

I just tried backdateing emoncms master to commit 778bd22cd949bd80f6238bdde1a5c466149f3f51 - your patch from a couple of days ago @pb66 with the device module master branch and device initialisation worked fine?

That’s not the point, if the problem exists in 9.8.8 with the updated device module (either branch) it isn’t something you did last night that’s causing the issue.

My live server IS on the latest emoncms but I’m not doing any more experimenting on there, if anything I will be rolling everything back. I only updated because of your security fix, prior to that everything was fine with v9.8.8 and an out of date device module, everything worked.

I will first try it on the test server, That was originally on 9.8.10 until I rolled it back to 9.8.8, again both of these were pre-security fix updates to 9.8.11.

Can we please be sure the device module “device-integration” branch works with both the master and stable branches of emoncms before meging to the master device module branch? And can we start using a version number?

I did add this change in April to ensure that inputs where not created if there was an existing input with the same nodeid and name: https://github.com/emoncms/device/commit/69ea64343d7e94e53dd9f7e1100f402a587c7d4c - I dont know if your version of the device module was prior to that?

Totally agree. I tested the integration-branch now in both stable and master.
I guess versioning makes only sense in a potentially new stable branch?

The changes with the set_processlist() were merged yesterday with #0b3d009 in stable and in #af3e77 in master… so prior to yesterday, everything should’ve worked for my understanding?

Although I cannot be sure, I expect it was before then.

I have just pulled in both the main master emoncms branch and the “device-integration” branch of the device module, still no processlists created.

Switched to the “master” branch of the device module, as I cannot re-run initialise, I created a second emonTH and that too has been created with no processlists.

I suspect the device module has not been compatible with the master branch of emoncms for sometime and it just hasn’t been noticed because I haven’t updated the device module and you guys are not running master or stable emoncms.

Do you know off hand how to roll back to a specific commit? I will try rolling the device module back to before those changes

Ok I think I have an interim solution, I’ve created a patch for the master banch available in a branch called set_processlist_patch:

https://github.com/emoncms/device/tree/set_processlist_patch

if you just do ‘git checkout set_processlist_patch’ that should get device initialisation back up and running on the master branch. Im not going to merge it as it will cause merge conflicts later on, if I try to merge the device-integration branch into it.

This patch works with the latest emoncms master branch 9.8.11.

Depending on whats your definition of “quite a while” :wink:
The device-support branch actually gets almost weekly merges to be up-to-date with master.
All problems regarding set_processlist() and hence the template processList creation was due to the merge from yesterday.
Maybe this is a cache-problem with your browser, as the module stores some template meta-data in the browser cache? Did you try ctrl-F5 reloading the page?
I tried reproducing your problems with the latest fix and everything works fine for me :confused:

Sorry Trystan, but that doesn’t help me much, a patched “master” still cannot add the processlists to existing inputs and and the previously created feeds blocks it from re-initialising.

We need to fix the “device-integration” module to be compatible with emoncms pre-9.8.11 and so that the types are saved. For now patching the “device-integration” branch would make more sense, that would get me out of this hole and allow the “device-integration” branch to be merged into master without breaking systems that already use the device module.

I’ve merged @Adminde’s pull request, so that should be the device-integration branch sorted

Well possibly 7.5 months in this case.

At every step and I just retested now, just in case.

@pb66 the device types are definitly getting saved correctly for all emoncms branches for me.
When you create new devices, they still get saved with a type NULL?

We are discussing the lack of processlists, not the device type, I now have many devices all with a type (i’m having to switch back and forth between branches)but none with a processlist.