Author Topic: Configure Pi Gateway to Run Locally (LAN only, No Internet Connection)  (Read 1315 times)

Jason

  • Jr. Member
  • **
  • Posts: 57
This is how to configure the Pi IoT Gateway to run locally.

One must have internet access to download the files.
After that the Pi IoT Gateway can run locally with some limitations (no emails sent, etc...)

One will need to modify /home/pi/gateway/www/index.html

1. (Optional) As a backup, create two copies of this file as a backup and name them as: index_original.html and index_offline.html
2. Create a folder to hold the files for offline use:  /home/pi/gateway/www/offlinefiles
3. Open the index.html with a text editor.
    In head (beginning) of the file notice the lines that say either href="https://....." or src="https://......." .
    These files will need to be stored locally.
    Currently Nov. 2018 there are 10 files that need to be stored locally.
4. Download and store these files locally.
    4.1 One way to do this is to use the curl command in the command line
          Ex: curl https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css -o /offlinefiles/jquery.mobile-1.4.5.min.css
          This downloads jquery.mobile-1.4.5.min.css from the jquery website and saves it to the folder"/offlinefiles" with the file name "jquery.mobile-1.4.5.min.css"
    4.2 Do this for all 10 remote (online) file links in the index.html file
5. Update index.html so all the "https://..." references are directed locally to the files in the offline files folder.
    5.1 Ex:  Before <link type="text/css" rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
                 After   <link type="text/css" rel="stylesheet" href="/offlinefiles/jquery.mobile-1.4.5.min.css" />
    5.2 Repeat for all the 10 remote (online) file links in the index.html file
6. Save this file as index.html.
7. Save this file as index_offline.html
8. Now the gateway is ready for use offline.
9. (Optional) To convert it back to "normal" mode, just copy the index_original.html file and rename it as index.html.

Troubleshooting Note:
1. First try with the original index.html file.
    Access the IoT Gateway to verify it works.
    Download one file to the /offlinefiles folder.
    Change one of the filelinks in the index.html file.
    Save the index.html file
    Access the IoT Gateway to verify it still works.
            If it doesn't check and make sure the file is indeed in the folder
            Also check for typos.
    Then repeat for each link till you are done.

Best Wishes!

Jason

  • Jr. Member
  • **
  • Posts: 57
Re: Configure Pi Gateway to Run Locally (LAN only, No Internet Connection)
« Reply #1 on: December 06, 2018, 11:08:28 PM »
Issue Found:

When attempting to download all the data from one node into a csv file, the calendar that should show up and let you pick a data doesn't show up.  A user is allowed to fill in the field manually, however I was unable to find any thing that worked.  Debugging I found that I was getting an error with this section of index.html file.

Code: [Select]
    $('#exportCSVDateRange_export').click("tap", function(event) {
      var start = $("#exportCSVDateRange_start").datepicker("getDate").getTime();
      var end   = $("#exportCSVDateRange_end").datepicker("getDate").getTime();
      var points   = $('#exportCSVDateRange_points').val();
      socket.emit('EXPORTNODELOGSCSV', selectedNodeId, start, end, points); //[unix epoch, end of time], how many points to return
    });

The variable start wasn't able to get defined because of some error I didn't understand.  However I found that I could hard code in the desired value for start in ms since the epoch as follows:

Code: [Select]
    $('#exportCSVDateRange_export').click("tap", function(event) {
      var start = 1543132800000;
      var end   = 1543564800000;
      var points   = $('#exportCSVDateRange_points').val();
      socket.emit('EXPORTNODELOGSCSV', selectedNodeId, start, end, points); //[unix epoch, end of time], how many points to return
    });

This code would run fine, but only select data from the hard coded times.  Also the original index.html file worked fine.  This leads me to believe that I must have missed a file that needs to be downloaded for offline use.  More investigation is needed.

I haven't noticed any other bugs related to putting the files local, and the gateway has been working well for a few weeks now.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Configure Pi Gateway to Run Locally (LAN only, No Internet Connection)
« Reply #2 on: December 07, 2018, 09:55:59 AM »
Can you give me more details about the calendar error?
I cannot replicate this, I am running the v9 beta (to be released soon), but the export dialog calendar stuff was not changed.
Anything special about that node?
Open dev tools (F12 in chrome) and open CONSOLE where you should see any errors.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Configure Pi Gateway to Run Locally (LAN only, No Internet Connection)
« Reply #3 on: December 07, 2018, 10:58:09 AM »
And regarding your first post - release 9.0 will include all resources locally so you dont have to have internet.

Jason

  • Jr. Member
  • **
  • Posts: 57
Re: Configure Pi Gateway to Run Locally (LAN only, No Internet Connection)
« Reply #4 on: December 07, 2018, 05:37:37 PM »
Hi Felix,

Found the "bug" RawGitHub.com changed its' name to RawGit.com.  Therefore jquery.ui.datepicker.js, jquery.mobile.datepicker.css and jquery.mobile.datepicker.js files that were downloaded were all just HTML flies with "301 Moved Permanently" errors.  Properly downloaded the "real" files from the correct addresses.  Now the downloading all metrics of a node works properly.

Felix: What do you think about updating the Index.html file to update the URLs from RawGitHub to RawGit.com?

Also just FYI:
"RawGit is now in a sunset phase and will soon shut down. It's been a fun five years, but all things must end. GitHub repositories that served content through RawGit within the last month will continue to be served until at least October of 2019. URLs for other repositories are no longer being served. If you're currently using RawGit, please stop using it as soon as you can."
https://rawgit.com/

Thanks!

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Configure Pi Gateway to Run Locally (LAN only, No Internet Connection)
« Reply #5 on: December 07, 2018, 05:42:04 PM »
I just mentioned that all scripts will be stored on the Pi in v9.0, no longer loaded from gihub or anywhere else.

Jason

  • Jr. Member
  • **
  • Posts: 57
Re: Configure Pi Gateway to Run Locally (LAN only, No Internet Connection)
« Reply #6 on: December 07, 2018, 06:10:12 PM »
Gottcha! I though that was going to be like an option, like flip a switch and go to offline mode.

I am pretty excited about the next release!  Mainly for the multiple metrics on one graph feature!

Thanks!