I have this idea to modify the mobile app to add support for QR codes, so that you can open the profile page from emonCMS (on your Pi) and read your API key via the barcode scanner.
I had a brief attempt and modifying the Android App myself - and really quickly ran out of skills.
While there are some good guides that make this integration look really simple, I just couldn’t make it work.
Anyone either able to help guide me to do this, or maybe have a stab yourself?
It’s a great idea Andy, and your emoncms github update works very well.
We’ve been further discussing this development in Github and hope that this integration is possible.
I’ve been stripping out the Google barcode reader example app. It’s now ready to be combined into the emoncms app but if anyone could test it before I do I’d appreciate it. It will only accept the QR codes as has been defined in emoncms and will put out the necessary fields and show the output as a popup notification.
I’m quite proud of the regex statement!
Rebuilt my Pi with the current RC, merged in emoncms “master” and I am currently pushing your APK to my phone…
Well that was so fast I won’t bother to post / edit;
SSL (or rather the lack of) correctly detected.
It would be nice to have the red line on the screen (per the usual barcode apps) just because it sets some expectation for device orientation (not that it matters with QR codes).
I guess the next part is to integrate this into the settings area in your app?
Here’s the current progress…couple of bugs left but it’s working well.
I thought about adding the red line as per usual but the Google api is very different and is much more efficient. It can scan multiple barcodes at the same time and they don’t have to be in the center of the screen. It’s not very intuitive but usually the barcodes scan so quickly it doesn’t matter.
Only one small issue to note, and you could put this down to user error;
I side loaded the new app over the top of the old one, and while it would scan the QR code correctly, and it would populate the fields correctly - I had connection issues.
I suspect that these issues were of my own making because I had also re-named my feeds since the last time I used the app, un-install / reinstall of the app (thus clearing out the cache and saved data) made it work perfectly again.
I’ll re-install the old one again, set that up and load the new one over the top and see if I get the same issue.
EDIT: After playing about with this, the connection issues are also apparent using the old app, the issue may be due to me running the latest version of the emoncms from git (master branch).
The “connection errors” have been mentioned before, so I do not think it’s anything to do with your particular setup, I have almost always seen very occasional “connection errors” but more recently it’s become significantly more frequent.
Is there any possibility the android app could also look for feeds of particular names if not manually overridden by picking from the list of feeds?
This would almost make installing and using the app a simple 2 step process of downloading the app and scanning the QR code.
PS any further thoughts on expanding to multiple instances yet ?
Looking for default feeds should be easy. I’d assume watts and kwh would be the standard names?
The connector error message is shown when an http request times out. I only see this when I have a weak mobile signal such as when on the train. I also run the bleeding edge version of emoncms from master and see no issues.
Maybe it should only show the connection error after 3 timeouts in a row?
the default feed names for the MyElectric app are “use” and “use_kwh”
The “3 strikes” rule may well be the way to go, it does always connect and the issue probably is more the red “connection error” message rather than the actual time taken to connect, without the message it would probably go unnoticed.
I have just received the emoncms app upgrade and it opened/connected without a warning, The “scan QR” option opens the camera fine but I don’t currently have the QR codes set up to test any further at this time. excellent work, thank you for doing this.
The reconnection issue has got much worse of late.
I’m using emoncms low-write 9.5.1 2016.4.28 and the latest app installed a few minutes ago (with QR reader which worked great!).
The reconnection issue is not due to the QR update changes, it was the same in the last version too.
@JumpMaster - how often does the app poll the emonpi?
@Paul - what Pi version are you using?
Paul - sorry I meant what hardware version, raspberry pi2, 2+ 3 etc.
Not that it matters, problem found - working on a fix - its not the android app (I don’t think).
The Android app has a 10 second delay between updates. 2 requests are made (use_kwh and a full feed list) and every 60 seconds it also requests the power usage for the last X days for the lower graph.
If any of these requests error it retries in 5 seconds.
I’m using a custom server (I work for a cloud hosting provider) and don’t see any issues.
The problem is in emoncms, the log output from apache says;
PHP Warning: Division by zero in /var/www/emoncms/Modules/feed/feed_model.php on line 461
And its not kidding there really is a div0 error there, what I have not figured out yet is where the variable $outinterval comes from - my quick and dirty PoC code is to add a check that sets $outinterval to 1 if its anything less than this already - I need to stress that this is NOT a proper fix, but it does totally solve the problem, proving the issue is NOT within the android app - its in the emoncms application.
I can post this as a PR for review if that helps but honestly the div0 error should be investigated by someone who knows emoncms better than I do rather than being patched up using the method I chose.
Hope that helps.
@JumpMaster Take a look at the error log for the web server and see if you have any divide by zero errors logged when using the app - logs on the emonpi are full of them.
In the mean time I am going to investigate the API some more and get some traffic captures going to see if I can figure out where the problem is - my initial reaction that there is a problem in the emoncms code may or may not be correct - plus the reason I see the issue with my Pi, and you don’t on your hosted platform may be entirely due to the performance of those boxes - the real question is if you have the same error in the logs or not.
I’ll do some more digging and feed back soon.
Why get the full feed list every time? I’d have thought that this was only needed when selecting the feed as the input.
Connection error issue moved to it’s own thread - Android App "CONNECTION ERROR"