Hi,
To give me a bit of reassurance developing and packaging emoncms, I've started a simple end-to-end test script with the idea that I will run this before each version of the repo is uploaded to APT.
Using the API, it pops an input into emoncms, creates three feeds and adds them to the input process:
- log to feed
- accumulator
- kwh to kwh/day
It then submits some input and checks the feed values match what is expected, before deleting the feeds at the finish.
Although I mainly wanted this for new dev, it's highlighting a few issues with emoncms just now, including non-JSON responses on the JSON API and the odd lack of an updated value in the kwd - kwhd feed (which just seems to sit at zero).
Output:
Testing http://192.168.1.66/emoncms using API key 'e84e8d580cf593bee654ef7e23db615c' Submit input value 1 for node 1... WARNING: JSON API has not returned JSON! Got 'ok' Create feed 'Test_input_feed'... WARNING: JSON API has not returned JSON! Got '<br /> <b>Notice</b>: Trying to get property of non-object in <b>/usr/share/emoncms/www/Modules/feed/feed_model.php</b> on line <b>104</b><br /> {"success":true,"feedid":40,"result":true}' Success Add process 1 (40) to input 1 Success Create feed 'Test_accumulator_feed'... WARNING: JSON API has not returned JSON! Got '<br /> <b>Notice</b>: Trying to get property of non-object in <b>/usr/share/emoncms/www/Modules/feed/feed_model.php</b> on line <b>104</b><br /> {"success":true,"feedid":41,"result":true}' Success Add process 14 (41) to input 1 Success Create feed 'Test_daily_feed'... WARNING: JSON API has not returned JSON! Got '<br /> <b>Notice</b>: Trying to get property of non-object in <b>/usr/share/emoncms/www/Modules/feed/feed_model.php</b> on line <b>104</b><br /> {"success":true,"feedid":42,"result":true}' Success Add process 23 (42) to input 1 Success Submit input value 1 for node 1... WARNING: JSON API has not returned JSON! Got 'ok' Submit input value 2 for node 1... WARNING: JSON API has not returned JSON! Got 'ok' Submit input value 3 for node 1... WARNING: JSON API has not returned JSON! Got 'ok' Check that feed 40 has expected value 3 WARNING: JSON API has not returned JSON! Got '"3"' Success Check that feed 41 has expected value 6 WARNING: JSON API has not returned JSON! Got '"6"' Success Check that feed 42 has expected value 6 WARNING: JSON API has not returned JSON! Got 'null' Use of uninitialized value $value in numeric eq (==) at ./testsequence line 122. Use of uninitialized value $value in concatenation (.) or string at ./testsequence line 126. Failed: actual value is Now deleting test feeds... Deleting feed 40 WARNING: JSON API has not returned JSON! Got 'null' Deleting feed 41 WARNING: JSON API has not returned JSON! Got 'null' Deleting feed 42 WARNING: JSON API has not returned JSON! Got 'null'
As always, any thoughts welcome!
Re: Emoncms test script
Good idea Dave.
It's great that you are committing so much time & effort into making things easier for everyone.
Paul
Re: Emoncms test script
Thanks Paul,
As well as having a sanity check for pre-release, I'm hoping this might be something a new user can run to help diagnose issues when making a support request.
I've also made a pull request with the addition of log4php. Upgrading my install from v7 to v8 has led to many issues and it's quite hard to know why nothing is appearing on disk with no logs.
Re: Emoncms test script
This looks like a nice approach! good idea, lets extend on this.
WARNING: JSON API has not returned JSON! Got 'ok'
Yes because of needing to maintain backwards compatibility, I had to add exceptions for the time, input/post and input/bulk api:
if ($route->format == 'json')
{
if ($route->controller=='time') {
print $output['content'];
} elseif ($route->controller=='input' && $route->action=='post') {
print $output['content'];
} elseif ($route->controller=='input' && $route->action=='bulk') {
print $output['content'];
} else {
print json_encode($output['content']);
}
I was thinking the other day it might be good to move to using the header status code 200 returned by a http post rather than an ok for the input/post and input/bulk response, this will need coordinated work across all the basestations as well as emoncms to make the transition though.
At the same time it would be good to put the write apikey in the body of the post and look at encoding.
Re: Emoncms test script
I hadn't really considered legacy device support.
It might be an idea to adopt a version-based API, where the client can submit essentially a flag telling emoncms what type of response they support.
input/post.json?version=2&node=X&csv=Y&apikey=Z
Re: Emoncms test script
Any change from posting "ok" as return from http post would need to be flagged well before the change being made.
I'm sure I'm not alone in having scripts that look for the "ok". e.g. my "post to emoncms" from node-red looks for the "ok" and if 5 posts in a row fails it sends me a tweet.
I recognise that changing this is trivial, but it would need to be coordinated.
Re: Emoncms test script
It's a fundamental change that would break backwards compatibility on every installed system. It needs rather more than 'coordination'. I think emoncms.org would still need to send back 'ok' for the foreseeable future, even though Nanodes/OKGs/RPi's would be free to use the status code and ignore the 'ok'.
Re: Emoncms test script
Yeah, it needs to be opt in - hence my suggestion of something in the request (like a version marker) that self-selects the call to receive a json response.