Broken "Inputs" page in emoncms 10.1.1

Hi all,

After upgrading my emonbase to emoncms 10.1.1 the Inputs page won’t load anymore:

Here are the details of my setup:


Version: low-write 10.1.1
Modules: Administration | App v2.0.1 | Backup v2.1.0 | EmonHub Config v2.0.2 | Dashboard v2.0.3 | Device v2.0.0 | EventProcesses | Feed | Graph v2.0.1 | Input | Postprocess v2.1.0 | CoreProcess | Schedule | Network Setup v1.0.0 | sync | Time | User | Visualisation | WiFi v2.0.0

Git URL:
Branch: * stable
Describe: v9.5.1-2081-g76ced7cb

Any suggestion?

Javascript debugging seems to indicate that the page chokes on a missing device description…

Have you cleared the browser cache?

Yes I had.

I went to mysql to fix it, somehow I had an input whose nodeid did not exist in the device table.
This is an input I created manually, in the previous version of the emoncms UI… I don’t have precise reproducible steps unfortunately.
I see JS code to try and ask the server to create missing devices, but somehow that didn’t kick in here…


1 Like

I am seeing this error too.

@glyn.hudson @TrystanLea @emrys there seems to be a problem with the latest patch.

Thanks @franck102 @borpin, Im cant replicate it here, however it sounds like it might be resulting from this line: emoncms/input_view.php at master · emoncms/emoncms · GitHub
could you try commenting that line out @borpin to see if the error goes away?

@TrystanLea - yes it goes away.
is there a requirement to check and see if there is a device name specified?
Should the devices array be passed here.

The devices array is in the scope of the whole script, so does not need passing.

It sounds like the device does actually exist in the array but its missing the description property, hence its not creating a device at this point emoncms/input_view.php at master · emoncms/emoncms · GitHub but somehow the description is not present before that…

Would you be able to put a console.log(devices) at this point and copy here what it prints to the javascript console? emoncms/input_view.php at master · emoncms/emoncms · GitHub

Alternatively I can add a check for the description, but it may be not addressing the root cause.

It was just that the other function (next line) did do so - not consistent.

The purist in me says you should always check and never assume :grin:.

If it is empty would it be undefined?

Don’t know how to export the object. I think your assumption is false…



BTW, if I click on ‘new device’ there is no description field.

I thought that was called “defensive programming”. :grinning:

1 Like

I can’t reproduce anymore, but when debugging I did find a funky device (different properties, missing description, and with the message that appears in Brian’s log), which seems to come from device_model.php.
The line Trystan points to assumes that the device is either null or correct, the above breaks that assumption…


That’s definitely the line that triggers the exception, but just commenting it out will still leave you with malformed device objects in the array… so probably a defect waiting to happen :slight_smile:

The problem could well be here:

When getting the device list from Redis the code post-processes the array, calling this->get(), and it doesn’t check that that get() call was successful; instead it just inserts an error response in the device array…


I’ve added a check for the description higher up in the input_view code, where the device list is loaded: fix for missing device description · emoncms/[email protected] · GitHub

What error response are you seeing? Sounds similar to what @freeyland is seeing here?: Uncaught reference error list format updated object

So this fix solves the issue but it seems none of the devices (on a standard EmonSD image) get populated.

Where should this information be entered?

I have to say I do not understand the ‘devices’ at all.

I created a bogus input to reproduce the problem. The issue is here:

The call to device->create returns this error object:

1. deviceid:
  * message: "Device already exists"
  *  success: false
  *  __proto__: Object

… and the code assumes it simply received a deviceId.

The problem is all over the place in device module: several of its functions return either an object (deviceid, device), or an error array (success: false, message: xxx).
And none of the usages of the module are testing for that.

I don’t have time to look into this further, maybe next week…

To reproduce, simply use this:

MariaDB [emoncms]> update input set nodeid='bogus' where id=292;

sudo systemctl restart redis-server


Thanks @franck102, I’ve improved the implementation to check for the error message object in the result.

$.ajax({ url: path+"device/create.json?nodeid="+nodeid, dataType: 'json', async: false, success: function(result) {
    if (result.success!=undefined) {
        alert("There was an error creating device: nodeid="+nodeid+" message="+result.message); 
    } else {
        devices[nodeid].id = result;
        devices[nodeid].devicekey = "";

See: emoncms/input_view.js at master · emoncms/emoncms · GitHub
and commit

This is merged in after another merge fixing an issue where the input view did not work if the device module was not installed - hence other changes that might not look familiar.