Android app for the Classic

Started by Graham, January 06, 2014, 07:54:42 PM

Previous topic - Next topic

Graham

I'm working on an android app that displays the charge status of a classic over modbus. It's very basic at this point, it will display a gauge view in landscape and a simple list in portrait. It requires a minimum of android API level 15 (version 4.0.3+).

If anyone would like to try it, let me know if it displays correctly on your device, It renders correctly on a nexus 10, I've also tried a galaxy 4 using the emulator.

I haven't completed the settings page, so the gauge scales are currently fixed. 

By default it will scan your local network for port 502, you can set a static IP address or change the port number in the settings.

Since it is not on google play, you will have to allow installation of apps from 'unknown sources', otherwise known as sideloading explained at http://phandroid.com/2013/07/20/android-101-sideloading-apps/.

The APK file is in a public folder on DropBox https://dl.dropboxusercontent.com/u/217460186/Classic/Classic.apk . (click on this link within your device to install)

The source is on SourceForge at https://sourceforge.net/projects/classicmonitor/.


Main Status Page


Graham.
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

Halfcrazy

Graham
Very Very nice. It did not seem to auto detect my classic but when I plugged it in manually it worked. It found something on port 502 at IP 192.168.2.16 and all my Classics are from 190 to 200. When the sun comes up I will play with it more but this is Way Way cool. Any plans to add support for the WBjr?

Ryan
Changing the way wind turbines operate one smoke filled box at a time

Graham

Thanks Ryan, I'm planning on getting a WBjr, I could display the battery current gauge as an automotive gauge with +/- amps.
I'll probably add a log screen to help me debug issues like the scan problem, the code used the gateway address and subnet mask to come up with a scan range, it then uses a thread pool to attempt to connect to each address with the given port, I could add a scan range in the settings as an option to limit the range of addresses.

Graham.
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

Halfcrazy

So I was playing with it here and it keeps disconnecting and reconnecting like every 2 seconds. I am running a Galaxy S3 with Android 4.3.0010
Changing the way wind turbines operate one smoke filled box at a time

Graham

Looks like your getting a modbus exception from the J2Mod library. I`m currently limited to testing against a modbus slave simulator with a galaxy S3 emulator (which don't report any connection errors), I`ll have to try this against my classic this weekend when I get back to my cabin. The last time I was there, my Nexus 10 was able  to remain connected to the (real) classic.
I'm considering replacing the J2Mod with my own implementation, this would allow me to implement the custom file transfer in order to get the logs off the classic so I can chart the data, it would also allow more control over the tcp settings/timeouts etc.
Are you using a tool like wireshark to see the error? If you are can you send me a screen capture?
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

Halfcrazy

Let me see if I can run Wire shark and get the info. It may be tomorrow before I can but I will try my best
Changing the way wind turbines operate one smoke filled box at a time

RossW

Quote from: Graham on January 08, 2014, 09:19:55 AM
I'm considering replacing the J2Mod with my own implementation, this would allow me to implement the custom file transfer in order to get the logs off the classic so I can chart the data, it would also allow more control over the tcp settings/timeouts etc.
Are you using a tool like wireshark to see the error? If you are can you send me a screen capture?

newmodbus - the utility I wrote about a year back - went the same way. The available modbus libraries were clunky, slow and unnecessarily convoluted to use. So I coded all the classic stuff straight in. It's actually pretty straightforward, don't let the documentation scare you. modbus-over-tcp is basically just building the same modbus frame you would if it were over serial, then adding a small header to it to transport over tcp.

If your code is written in C, I'm happy to share the relevant bits of my code to get you on the way?

R.
3600W on 6 tracking arrays.
7200W on 2 fixed array.
Midnite Classic 150
Outback Flexmax FM80
16 x LiFePO4 600AH cells
16 x LiFePO4 300AH cells
Selectronics SP-PRO 481 5kW inverter
Fronius 6kW AC coupled inverter
Home-brew 4-cyl propane powered 14kVa genset
2kW wind turbine

zoneblue

Hey Ross, ive almost finished with the daemon version of newmodbus. Its running fine sampling once per second, on the second +/-1ms. 

The newmodbusd 1 second rate will allow us to use ajax to get real time primary stats. And, do way more accurate Wh, Ah and similar integrations.  It also matches the classic internal 1sec averaging scheme.

What i'm doing is storing the regsiter data in a temp file, then renaming it when done. This seems to be giving me the high availability to other applications that i needed.

Just got a few decisions to make about summarising the rather prolific raw data.

6x300W CSUN, ground mount, CL150Lite, 2V/400AhToyo AGM,  Outback VFX3024E, Steca Solarix PL1100
http://www.zoneblue.org/cms/page.php?view=off-grid-solar

RossW

Quote from: zoneblue on January 08, 2014, 05:42:26 PM
Hey Ross, ive almost finished with the daemon version of newmodbus. Its running fine sampling once per second, on the second +/-1ms. 

Great news. Is this based on a pulled-apart-and-re-assembled version of the newmodbus code I sent you?
Did you ever see a repeat of the network bug we thought related to the processor type (or did that go away when you recompiled native for your processor)?
3600W on 6 tracking arrays.
7200W on 2 fixed array.
Midnite Classic 150
Outback Flexmax FM80
16 x LiFePO4 600AH cells
16 x LiFePO4 300AH cells
Selectronics SP-PRO 481 5kW inverter
Fronius 6kW AC coupled inverter
Home-brew 4-cyl propane powered 14kVa genset
2kW wind turbine

zoneblue

Quote
Great news. Is this based on a pulled-apart-and-re-assembled version of the newmodbus code I sent you?

Yes. Dragged kicking and screeming into c.

Quote
Did you ever see a repeat of the network bug we thought related to the processor type (or did that go away when you recompiled native for your processor)?

Even when complied on cubie the classic timeout issue remained. Working down from 5 minute samples, 5 was fine, 4 was fine, 3 was fine. 2 minutes starts to drop occasional samples, and locks up after about a week. 1 minute drops lots of samples and classic locks up after about 14 hours.

So, on a open-read-close basis, its stable at 3 minute sample intervals or higher.

I did manage to locate the via eden 400Mhz x86 box, but havent got around to trying it. But im not really sure theres much point. The ARM boards are here to stay, at least for now. Lets say, hypthetically that timeouts dont occur on a slow x86 box what does that gain us? The only upside that i can see is the possibility of, maybe, providing some key clue that will help midnite actually solve the problem.

But given midnite's other priorities, this daemon route is at least a way forward, allowing further development on blackbox UI.

The point being is that if you maintain an open modbus connection, its stable and theres no timeouts, or refused connects. Even if most peoples application is just 60s cron job to read the text file produced by the daemon.

Ross, will you be ok if i include the both your and my source in the blackbox svn? Attributions obviously.


6x300W CSUN, ground mount, CL150Lite, 2V/400AhToyo AGM,  Outback VFX3024E, Steca Solarix PL1100
http://www.zoneblue.org/cms/page.php?view=off-grid-solar

RossW

Quote from: zoneblue on January 08, 2014, 06:39:13 PM
Yes. Dragged kicking and screeming into c.

lol.

Quote
The point being is that if you maintain an open modbus connection, its stable and theres no timeouts, or refused connects. Even if most peoples application is just 60s cron job to read the text file produced by the daemon.

*nod*, and you know the history of the reason I added the "keep connection open" logic in the code :)

Quote
Ross, will you be ok if i include the both your and my source in the blackbox svn? Attributions obviously.

Yup.
3600W on 6 tracking arrays.
7200W on 2 fixed array.
Midnite Classic 150
Outback Flexmax FM80
16 x LiFePO4 600AH cells
16 x LiFePO4 300AH cells
Selectronics SP-PRO 481 5kW inverter
Fronius 6kW AC coupled inverter
Home-brew 4-cyl propane powered 14kVa genset
2kW wind turbine

mjp24coho

Android app is great, but I would think there'd be an even bigger market for an apple app.  Anyone have one in the works?
Offgrid Cabin: 8x215 watt Kyocera panels (roof mount), Midnite E-Panel with Magnum MS4024 inverter, Midnite Classic 200, 800AH 24V forklift battery, Magnum battery monitor, online Magnum inverter & Midnite charge monitoring, Honda EM5000SX generator.

Graham

Quote from: RossW on January 08, 2014, 04:44:16 PM
Quote from: Graham on January 08, 2014, 09:19:55 AM
I'm considering replacing the J2Mod with my own implementation, this would allow me to implement the custom file transfer in order to get the logs off the classic so I can chart the data, it would also allow more control over the tcp settings/timeouts etc.
Are you using a tool like wireshark to see the error? If you are can you send me a screen capture?

newmodbus - the utility I wrote about a year back - went the same way. The available modbus libraries were clunky, slow and unnecessarily convoluted to use. So I coded all the classic stuff straight in. It's actually pretty straightforward, don't let the documentation scare you. modbus-over-tcp is basically just building the same modbus frame you would if it were over serial, then adding a small header to it to transport over tcp.

If your code is written in C, I'm happy to share the relevant bits of my code to get you on the way?

R.

I`d be very interested in some of your modbus code, I found J2Mod easy to use but it doesn't appear to have many options for tcp settings/config. This is my  first Android app, I'm using the new Android Studio with Java. It's been a few years since I used good old 'C' but I'm sure it will all come back to me.

Graham.
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

Graham

Quote from: mjp24coho on January 08, 2014, 09:20:32 PM
Android app is great, but I would think there'd be an even bigger market for an apple app.  Anyone have one in the works?

I decided to write this app as an exercise to learn mobile development with the new Android Studio recently release by Google, but if I was going to target all platforms I would consider using Phonegap and Phonegap.build. This is one of the tools used in 'hybrid' mobile development, http://en.wikipedia.org/wiki/PhoneGap. You write your app in javascript using the phonegap library + jquery/dojo etc, then submit the code to phonegap.build and it returns executables for each of the major mobile platforms (Android, IOS, Blackberry, Windows phone).
Off-Grid Island cottage, Lac Simon QC Canada
370 Ahrs @ 24V (4 8L16 batteries)
4 x 250watt panels on dual axis trackers http://tinyurl.com/hfpkgr5
Classic 150, Whizbang Jr.
Android Monitor: http://tinyurl.com/lomzq3s

vtmaps

Quote from: Graham on January 09, 2014, 08:07:49 AM
but if I was going to target all platforms I would consider using Phonegap and Phonegap.build.

Another multiplatform development environment is Livecode (formerly Runtime Revolution).   --vtMaps