Dan-in-CA / SIP

A highly customizable DIY irrigation/sprinkler controller based on Raspberry Pi
359 stars 156 forks source link

Mobile Interface #9

Closed salbahra closed 10 years ago

salbahra commented 10 years ago

I just finished building a mobile interface that runs 100% in the user's browser (no more PHP). I would like to integrate this into your project now since it should be quite easy. The only thing needed to make the UI work is the JSON output of current variables (ideally, the same output format as the OpenSprinkler). The OpenSprinkler uses the following commands: /jc (settings), /js (station status), /jo (options), /jn (station names), and /jp (programs). More information can be found here: http://rayshobby.net/phpBB3/viewtopic.php?f=2&t=403

If you could replicate these then all that's needed is a check for a mobile browser and redirecting to the mobile html file. The code for my app is posted here: https://github.com/salbahra/OpenSprinkler-Hosted-Controller. Currently, the code is multi-site aware however that can easily be removed and integrated with your python code to provide a seamless mobile UI.

If you are interested, please let me know and I can help with this integration. Thanks!

jonathan-marsh commented 10 years ago

Sounds very interesting, I will look this weekend. I have a few json interfaces in muly current version to support dynamic UI elements like current station state and log history.

Jonathan http://jonathanmarsh.net/ (sent from my iPhone)

On Feb 21, 2014, at 2:42 PM, Samer Albahra notifications@github.com wrote:

I just finished building a mobile interface that runs 100% in the user's browser (no more PHP). I would like to integrate this into your project now since it should be quite easy. The only thing needed to make the UI work is the JSON output of current variables (ideally, the same output format as the OpenSprinkler). The OpenSprinkler uses the following commands: /jc (settings), /js (station status), /jo (options), /jn (station names), and /jp (programs). More information can be found here: http://rayshobby.net/phpBB3/viewtopic.php?f=2&t=403

If you could replicate these then all that's needed is a check for a mobile browser and redirecting to the mobile html file. The code for my app is posted here: https://github.com/salbahra/OpenSprinkler-Hosted-Controller. Currently, the code is multi-site aware however that can easily be removed and integrated with your python code to provide a seamless mobile UI.

If you are interested, please let me know and I can help with this integration. Thanks!

— Reply to this email directly or view it on GitHub.

Dan-in-CA commented 10 years ago

Hi Samer,

Nice to hear from you.

Let me take a look at your code and think about how this might work.

One of the goals for my project has always been to make it as easy as possible for DIYers to add new features to the program. In this regard I have been working on a simple plugin architecture and have a couple of example plugins partially completed. One is a month-by-month automatic adjustment to the watering schedule and another is for putting the built-in relay on the latest OSPi and OSBo to use.

How easy do you think it will be for someone with perhaps limited programming skills to add a new feature to your interface?

I'll let you know what I think after I've had a chance to look things over.

Dan

On 2/21/2014 2:42 PM, Samer Albahra wrote:

I just finished building a mobile interface that runs 100% in the user's browser (no more PHP). I would like to integrate this into your project now since it should be quite easy. The only thing needed to make the UI work is the JSON output of current variables (ideally, the same output format as the OpenSprinkler). The OpenSprinkler uses the following commands: /jc (settings), /js (station status), /jo (options), /jn (station names), and /jp (programs). More information can be found here: http://rayshobby.net/phpBB3/viewtopic.php?f=2&t=403

If you could replicate these then all that's needed is a check for a mobile browser and redirecting to the mobile html file. The code for my app is posted here: https://github.com/salbahra/OpenSprinkler-Hosted-Controller. Currently, the code is multi-site aware however that can easily be removed and integrated with your python code to provide a seamless mobile UI.

If you are interested, please let me know and I can help with this integration. Thanks!

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9.

salbahra commented 10 years ago

Thank you both for your replies.

Dan, in regard to your question, I would say quite easy if you are familiar with Javascript. The program is based on jQuery Mobile which is well documented and the javascript version I have now is fairly easy to follow since there isn't server side logic anymore. I made the version on Github only support OpenSprinkler microcontroller and I think since the content is static, the code can be forked into your project and mature with it. This way, neither project is held back by a universal UI.

Just to add, I think jQuery and jQuery Mobile are one of the most documented libraries on the internet. Furthermore, jQuery has an understandable logic to it. For developers, debugging and testing will be easy since PHP isn't in the way.

As I mentioned earlier, the code isn't ready to be merged with your project however it can be massaged to do so at this point. It relies on a device object which holds all of the device information and updated within a update_device() function. This can be modified to get the data however OSPi wishes to return it. Also, for submitting settings, programs, etc the URL's can be modified from the $.get command quite easily (however I believe they are still 100% the same between OSPi and OS).

jonathan-marsh commented 10 years ago

Samer,

I’m having trouble finding an adequate specification for /jo, /jc, /jp, /jn – can you help me find samples or the source code for those? I’d like to try to replicate this API as a plug-in module.

-Jonathan

From: Samer Albahra [mailto:notifications@github.com] Sent: Friday, February 21, 2014 5:59 PM To: Dan-in-CA/OSPi Cc: Jonathan Marsh Subject: Re: [OSPi] Mobile Interface (#9)

Thank you both for your replies.

Dan, in regard to your question, I would say quite easy if you are familiar with Javascript. The program is based on jQuery Mobile which is well documented and the javascript version I have now is fairly easy to follow since there isn't server side logic anymore. I made the version on Github only support OpenSprinkler microcontroller and I think since the content is static, the code can be forked into your project and mature with it. This way, neither project is held back by a universal UI.

Just to add, I think jQuery and jQuery Mobile are one of the most documented libraries on the internet. Furthermore, jQuery has an understandable logic to it. For developers, debugging and testing is a lot easier without PHP in the way.

As I mentioned earlier, the code isn't ready to be merged with your project however it can be massaged to do so at this point. It relies on a device object which holds all of the device information and updated within a update_device() function. This can be modified to get the data however OSPi wishes to return it. Also, for submitting settings, programs, etc the URL's can be modified from the $.get command quite easily (however I believe they are still 100% the same between OSPi and OS).

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-35791512 . https://github.com/notifications/beacon/2431714__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcwODU2NzE2MSwiZGF0YSI6eyJpZCI6MjYyMTM0MjN9fQ==--ecb081034dd4fa9cfb1c8681e66af58975b2d516.gif

salbahra commented 10 years ago

That would be fantastic! By the way, the JSON will need the following header: Access-Control-Allow-Origin: *. Here is the expected output:

“jo”: device options

{"fwv":203,"tz":24,"ntp":1,"dhcp":1,"ip1":192,"ip2":168,"ip3":1,"ip4":22,"gw1":192,"gw2":168,"gw3":1,"gw4":1,"hp0":80,"hp1":0,"ar":1,"ext":1,"seq":1,"sdt":20,"mas":0,"mton":0,"mtof":0,"urs":0,"rso":0,"wl":100,"stt":10,"ipas":0,"devid":0,"con":110,"lit":100,"ntp1":204,"ntp2":9,"ntp3":54,"ntp4":119,"reset":0}

“jc”: current device settings

{"devt":1393439012,"nbrd":2,"en":1,"rd":0,"rs":1,"mm":0,"rdst":0,"loc":"75601","sbits":[0,0,0],"ps":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"lrun":[0,0,0,0]}

“js”: station status and total stations

{"sn":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"nstations":16}

“jp”: program information

{"nprogs":1,"nboards":2,"mnp":54,"pd":[[1,37,0,120,600,144,1620,255,255]]}

“jn”: station names, master station bits, and maximum station length allowed

{"snames":["1 LT Driveway T","2 RT Driveway C","3 LF Driveway C","4 RT Circle C","5 LT Driveway E","6 Front Island C","7 RT Drive Lawn","8 RT Lawn Bed C","9 LT Lawn Bed C","10 LF Lawn Bed C","11 LF Back Bed","12 RT Back Bed","13 RT Back C","14 Back Fence","15 LT Corner Bed","16 Around Pool"],"masop":[255,255],"maxlen":16}

I have all of these hosted on http://vps.albahra.com for testing. Example: http://vps.albahra.com/jc

Update: By the way, I made a version of the app that works straight off the SD card and put it in device-sdcard branch. That version has the multi-site code stripped out. For performance reasons related to the Arduino, I stuffed it all into one file (as much as possible). I am trying to make my code more modular to accommodate these things however learning grunt or similar seems like a steep curve at the moment. Soon hopefully!

salbahra commented 10 years ago

Any progress on getting the JSON replies incorporated to the main code? If you want, I can try to make a pull request with the feature. This will allow my native mobile apps to support OSPi as well.

Thank you!

jonathan-marsh commented 10 years ago

Hi Samer,

Not much progress yet I'm afraid; life interferes. I have the basic GET API in place except for a lot of the network config details in /jo, such as ip address, router address, etc. Got stuck looking for ways to provide that additional information. Not sure these fields are even required by the app ...

I just published what I've done so far to https://github.com/jonathan-marsh/OSPi/tree/Mobile-API, even though it's not yet working. Suggestions would be helpful!

-Jonathan

From: Samer Albahra [mailto:notifications@github.com] Sent: Saturday, March 22, 2014 3:07 PM To: Dan-in-CA/OSPi Cc: Jonathan Marsh Subject: Re: [OSPi] Mobile Interface (#9)

Any progress on getting the JSON replies incorporated to the main code? If you want, I can try to make a pull request with the feature. This will allow my native mobile apps to support OSPi as well.

Thank you!

Reply to this email directly or view it on GitHubhttps://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-38365718 .

salbahra commented 10 years ago

Oh please don't bother with those (just NTP if you use it). The IP fields aren't even updated on the OS anyways so not used for sure. I can go through specific fields used if you want.

Thanks a lot!

On Sunday, March 23, 2014, Jonathan Marsh notifications@github.com wrote:

Hi Samer,

Not much progress yet I'm afraid; life interferes. I have the basic GET API in place except for a lot of the network config details in /jo, such as ip address, router address, etc. Got stuck looking for ways to provide that additional information. Not sure these fields are even required by the app ...

I just published what I've done so far to https://github.com/jonathan-marsh/OSPi/tree/Mobile-API, even though it's not yet working. Suggestions would be helpful!

-Jonathan

From: Samer Albahra [mailto:notifications@github.comjavascript:_e(%7B%7D,'cvml','notifications@github.com'); ] Sent: Saturday, March 22, 2014 3:07 PM To: Dan-in-CA/OSPi Cc: Jonathan Marsh Subject: Re: [OSPi] Mobile Interface (#9)

Any progress on getting the JSON replies incorporated to the main code? If you want, I can try to make a pull request with the feature. This will allow my native mobile apps to support OSPi as well.

Thank you!

Reply to this email directly or view it on GitHubhttps://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-38365718 .

Reply to this email directly or view it on GitHubhttps://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-38384529 .

Dan-in-CA commented 10 years ago

I have been developing the new plugin system. I think it would be good to use that for the JSON replies. It will eliminate having to add to the main code.

I should have something together in a couple of days. Right now I have some other time critical matters to attend to.

On 3/22/2014 3:06 PM, Samer Albahra wrote:

Any progress on getting the JSON replies incorporated to the main code? If you want, I can try to make a pull request with the feature. This will allow my native mobile apps to support OSPi as well.

Thank you!

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-38365718.

salbahra commented 10 years ago

Thank you! I agree 100% the plugin system would be a great way to implement this.

Dan-in-CA commented 10 years ago

Samer, I have a plugin for this working. However there are a few fields that the OSPi does not provide or at least I'm not sure what value they need to be. Let me know if you actually use the following:

  1. from /jo: "fwv" (The following seem to be network related and the pi's operating system handles this not the python program) "ntp" "dhcp" "ip1" - "ip4" "gw1"- "gw4" "hp0" I used gv.sd['htp'] for this which is the port the program is using. "hp1" "ntp1" - "ntp4" (The following I don't recognize) "ar" "ext" "stt" "devid" "con" "lit"
  2. from /jn "masop"

Dan

On 3/2/2014 6:14 PM, Samer Albahra wrote:

That would be fantastic! By the way, the JSON will need the following header: Access-Control-Allow-Origin: *. Here is the expected output:

“jo”: device options

{"fwv":203,"tz":24,"ntp":1,"dhcp":1,"ip1":192,"ip2":168,"ip3":1,"ip4":22,"gw1":192,"gw2":168,"gw3":1,"gw4":1,"hp0":80,"hp1":0,"ar":1,"ext":1,"seq":1,"sdt":20,"mas":0,"mton":0,"mtof":0,"urs":0,"rso":0,"wl":100,"stt":10,"ipas":0,"devid":0,"con":110,"lit":100,"ntp1":204,"ntp2":9,"ntp3":54,"ntp4":119,"reset":0}

“jc”: current device settings

{"devt":1393439012,"nbrd":2,"en":1,"rd":0,"rs":1,"mm":0,"rdst":0,"loc":"75601","sbits":[0,0,0],"ps":[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],"lrun":[0,0,0,0]}

“js”: station status and total stations

{"sn":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"nstations":16}

“jp”: program information

{"nprogs":1,"nboards":2,"mnp":54,"pd":[[1,37,0,120,600,144,1620,255,255]]}

“jn”: station names, master station bits, and maximum station length allowed

{"snames":["1 LT Driveway T","2 RT Driveway C","3 LF Driveway C","4 RT Circle C","5 LT Driveway E","6 Front Island C","7 RT Drive Lawn","8 RT Lawn Bed C","9 LT Lawn Bed C","10 LF Lawn Bed C","11 LF Back Bed","12 RT Back Bed","13 RT Back C","14 Back Fence","15 LT Corner Bed","16 Around Pool"],"masop":[255,255],"maxlen":16}

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-36476634.

salbahra commented 10 years ago

Hey Dan thank you very much. I will give this a try soon however I will address the fields you mentioned and if they will be needed.

The "fmv" is firmware version and if possible please provide something unique to the Pi. I think I will be using this to differentiate between the two, for example 1.8.3-ospi? The "ext" is how many extension boards are connected to the device and is required.

"masop" is also required this is the master operation bits. Does the interval program still use these?

These are not used by my app and can be ignored: "devid", "lit", "con", "stt", "ar", "hp0", "hp1", "ntp", "dhcp", "ip1" - "ip4", "gw1"- "gw4", "ntp1" - "ntp4"

Dan-in-CA commented 10 years ago

OK, I think I can add the required fields. I have not pushed this to GitHub yet but as soon as I add the fields and clean thing up a bit I push a new branch and let you know.

On 3/26/2014 3:49 PM, Samer Albahra wrote:

Hey Dan thank you very much. I will give this a try soon however I will address the fields you mentioned and if they will be needed.

The "fmv" is firmware version and if possible please provide something unique to the Pi. I think I will be using this to differentiate between the two, for example 1.8.3-ospi? The "ext" is how many extension boards are connected to the device and is required.

"masop" is also required this is the master operation bits. Does the interval program still use these?

These are not used by my app and can be ignored: "devid", "lit", "con", "stt", "ar", "hp0", "hp1", "ntp", "dhcp", "ip1" - "ip4", "gw1"- "gw4", "ntp1" - "ntp4"

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-38750419.

Dan-in-CA commented 10 years ago

there is a new branch called plugins_enabled containing the plugin to work with the mobile app.

Among the changes to this branch are a new plugins python package that contains the actual plugin modules. The URLs and GPIO definitions have been extracted from the main ospi.py file into separate modules. This allows plugins access to these parts of the program without setting up circular dependencies. If a plugin needs to, for example, add new URLs it simply imports the urls module.

There is also a plugin for automatically changing the % water level on a monthly basis and a plugin for working with the built in relay on the newer boards.

On 3/26/2014 3:49 PM, Samer Albahra wrote:

Hey Dan thank you very much. I will give this a try soon however I will address the fields you mentioned and if they will be needed.

The "fmv" is firmware version and if possible please provide something unique to the Pi. I think I will be using this to differentiate between the two, for example 1.8.3-ospi? The "ext" is how many extension boards are connected to the device and is required.

"masop" is also required this is the master operation bits. Does the interval program still use these?

These are not used by my app and can be ignored: "devid", "lit", "con", "stt", "ar", "hp0", "hp1", "ntp", "dhcp", "ip1" - "ip4", "gw1"- "gw4", "ntp1" - "ntp4"

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-38750419.

salbahra commented 10 years ago

Wow, that sounds absolutely amazing! Thanks for the hard work!

salbahra commented 10 years ago

Right now snames is being returned like this:

snames: "['S01','S02','S03','S04','S05','S06','S07','S08',]"

Which is a string, can we make it an array instead? Also, can we drop the last (empty) element as well?

Thank you!

salbahra commented 10 years ago

Good news! My app fully works against this plugin. The app however will not function within a Chrome browser only as a native app due to cross-origin policy issues. These are hit against /co, /cp, and other setting changing methods (since they don't return the accept cross origin header). The good news is this isn't an issue right now because PhoneGap can ignore them and continue working.

Thanks again Dan and Jonathan!

salbahra commented 10 years ago

Any ETA on when this will be merged with master? Thanks!

Dan-in-CA commented 10 years ago

Merged locally. Just need to finish testing on the Pi. Probably by tomorrow.

On 4/3/2014 4:10 PM, Samer Albahra wrote:

Any ETA on when this will be merged with master? Thanks!

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-39516151.

Dan-in-CA commented 10 years ago

Done. Also added a post on the forum.

On 4/3/2014 4:10 PM, Samer Albahra wrote:

Any ETA on when this will be merged with master? Thanks!

— Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-39516151.

salbahra commented 10 years ago

Thank you!

On Friday, April 4, 2014, Dan notifications@github.com wrote:

Done. Also added a post on the forum.

On 4/3/2014 4:10 PM, Samer Albahra wrote:

Any ETA on when this will be merged with master? Thanks!

Reply to this email directly or view it on GitHub https://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-39516151.

Reply to this email directly or view it on GitHubhttps://github.com/Dan-in-CA/OSPi/issues/9#issuecomment-39625227 .