Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

survey is not working offline on the tablet #1

Closed
ryantanaka opened this issue Aug 31, 2017 · 11 comments
Closed

survey is not working offline on the tablet #1

ryantanaka opened this issue Aug 31, 2017 · 11 comments

Comments

@ryantanaka
Copy link

This app continues to function normally if/when the hosting device loses internet connectivity; all data is held in-app until connectivity with the server is re-established.

To test this feature mentioned in the README, I ran the following scenario on the tablet:

  1. Successfully connect to test server, bringing up the survey page.
  2. Disconnect tablet from Wifi with survey page still open.
  3. Submit a few more surveys. (Pressing some of the response buttons, then seeing the "Thank You!" text popup several times) Page visibly functions properly.
  4. wait...

The survey page will timeout.

I will check the server to see if reconnecting after timeout actually sends those few responses that are logged while Wifi was unavailable. If that does work, then I will only need to fix the timeout issue. Currently not 100% sure how data is being held "in-app" client side when connection is lost.

@ryantanaka
Copy link
Author

Update: Tested this scenario, except on my computer using Google Chrome browser. The application will in fact function offline and resume sending data to the server when connection resumes as long as the user submits one more survey! This is great.

The code that makes this possible is located in Utilities.elm (note: Elm source code files are not included in this repo, but in survey_display_local, only the compiled javascript file (main.js) is included in this repo.)

-- Executes appropriate model updates based on an http response.
handle_response : Model -> Comms -> ( Model, Cmd Msg )
handle_response model comms =
case comms of
-- Deletes values which have been uploaded.
Ok ( dict ) ->
( { model | uploads = [] }
, Cmd.none )
-- Re-adds failed uplaods to main archive.
Err ( error ) ->
let
_ = Debug.log "Error: " error
new_arch = model.archive ++ model.uploads
in
( { model |
archive = new_arch ,
uploads = [] }
, Cmd.none )

The model.archive object is type aliased as an elm List that takes entries as its argument.

As for the tablet, I am unsure as of yet why I got a net::ERR_INTERNET_DISCONNECTED maybe about 1min into using the app offline.

@ryantanaka
Copy link
Author

@carlosviansi okay I figured this out. There were two settings in the kiosk app that needed to be changed for the app to work as intended:

General -> Idle Page Timeout: this needed to be deselected
Connectivity -> Reload Home Page: this needed to be deselected

"Idle Page Timeout" allowed the page to timeout when selected. This is not what we want.
"Reload Home Page" would reload the page whenever connection is restored via 2G/3G/4G/WiFi. If this setting is enabled, we end up losing surveys that are stored because the page gets reloaded.

@carlosparadis
Copy link
Member

Thanks for the updates, so the TL;DR of this story is:

Problem 1: How responses are stored offline

  • The original understanding that survey_display_local was code installed as some sort of App in the Tablet is incorrect. Instead, the off-line storage is really a javascript code and variable that comes together with the HTML page requested upon accessing the survey, "invisible to the user". As such, no local installation is required (i.e. no survey_display_local code is on the tablet) and this behavior will happen anywhere. The code snippet you showed above gives 2 behaviors to the submit button via javascript once elm is compiled:
    1. It first tries to submit the code to the server (which runs survey_display_server
    2. If it fails, the javascript which was downloaded along with the survey page stores it into the "invisible variable", and "fakes" a submission, by updating the current page. If another offline submission occurs, it repeats behavior 2, else it unloads all the "invisible javascript variable" answers to the server.

This finally maps to the memory I had from Forrest where he said he could only find how to provide

"offline persistence in Elm"

Nonetheless, the major drawback to the current indigenous workaround is that data persists in memory, not on disk. As such, if the tablet powers off, or if the last answer was the last one not to be submitted in the day, it will lose the data (as it requires a final submission) if a power off is scheduled. Assuming loss of connection is brief, our only concern should be on the setup sleep time to have a few hours ahead of the last class in the worst case scenario internet goes off towards the end of the last class of the day.

Problem 2: The time-outs in the nexus 7.

This you found to be a problem with the kiosk app itself, as you noted in the last comment. Due to the behavior of Elm in storing on memory, the timeout would lose the "invisible variable data". With you changing the settings, this is resolved, and we should expect only the limitations of Problem 1.

Next Steps

Could you create a diagram illustrating the way the offline functionality works? Given how subtle it is, I think an image would call enough attention to it. Specifically here is a proposal to the diagram:

  • A server icon labeled survey_display_server

  • A file icon labeled <survey_link>.html

    • File icon should have a smaller icon that resembles a list and labeled "Javascript Responses Bin"
  • A browser icon labeled client browser

  • Have the browser on the left, the file in the middle, and the server in the right.

  • Have an arrow numbered 1 pointing from server to browser, with the file icon over the arrow.

  • Have a second arrow numbered 2 showing the smaller list icon sent back to the server, note somewhere the person clicked submit button with internet (maybe a globe with the word www).

  • Have a dashed arrow looping over the html page on the browser now showing the smaller list icon somehow more filled up to suggest it is storing offline. Label it somewhere "On Memory" and that it is offline (maybe put a globe with www crossed with a red X here).

@ryantanaka
Copy link
Author

ryantanaka commented Sep 18, 2017

  • updated data structure icon to be [ ]

offline_functionality

xml file

offline_functionality.xml.zip

@carlosparadis
Copy link
Member

Ah! gotcha :-) In a way this issue is also part of #3.

@ryantanaka
Copy link
Author

good point, yeah just a little more fine grain detail

@carlosparadis
Copy link
Member

carlosparadis commented Sep 21, 2017

Ok this issue is also completed, it is just pending using the diagram for the readme, so I will be taking over from you. Do you have the .xml file too to attach here?

@ryantanaka
Copy link
Author

@carlosviansi ok sounds good. sorry, the link to the xml was kind of hard to see so i added a small headline (see the bottom of the comment with the diagram)

@carlosparadis
Copy link
Member

Oh I see now: offline_functionality.xml.zip

Thanks!

@carlosparadis
Copy link
Member

Pending moving the necessary information of this issue to the wiki! Re-assigned again to Ryan! Feel free to close after you move to the wiki :-)

@ryantanaka
Copy link
Author

The data saving feature is no longer relevant, the kiosk browser is set to refresh every 5 minutes. CLosing this issue.

@ghost ghost removed the stat:next label May 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants