Running application offline

Hi, I’ve got a Javascript/HTML application currently running on the balenaBrowser.
This application communicates between the JS file and HTML file using Socket IO, collecting data and then publishing it to an AWS database using Amazon’s IOT Hub.
I’m trying to figure out a way to make this application load up when offline, cache the transaction data it collects, then when reconnected publish the data to the database.

Right now, if the device has no connection to the internet, the browser says that Localhost is not responding. My first thought was to create a service worker to cache the js/html files and then display the cached versions when offline, but when trying to run the service worker script from the HTML file, it cannot find the service worker script file location (I believe the HTML file moves when running on the browser), and if trying to run it from the js file, I get a Reference Error that “navigator is not defined”.

Can anyone help with some ideas on how to get this running while my device has no connection?

Thanks,
Matt

Hello @Mattssmith94 could you please share more information of what device are you using, balenaOS version and what browser container are you using?

Thanks

Sure, we’re using a RaspberryPi4, Balena OS version 2.95.8, and the browser is balenablocks browser aarch64

@Mattssmith94 when the device is online, can you ping from the balenaCloud Terminal 1 container from the other?

Hello @Mattssmith94 let me get back here to learn if you could you solve this issue?

Hey Mpous, sorry for the delay. No I have not solved this issue yet.

Can you give me steps to try pinging from one container to another? I’m not sure how to try that.

Hi @mattssmith94,

Methods for pinging one container from another would vary depending on how your containers are configured. If they are both configured with network: host, you can ping one from another by their port number. Say container A exposes port 3000 and container B exposes port 3001. From within the shell for container A, try running curl localhost:3001 and see if you get a response.

If each container is on their own bridge network, communicating between them will be impossible. If both containers are on the same bridge network, you can ping one from the other by their service names. Say container A is named client and container B is named server. From client, try running curl server:3001 (or whatever port your server exposes) to see if there’s a response.

In both of the above cases, the curl commands should be run from within the shell of a container. You can get there through the dashboard, or from a host OS terminal instance after running balena exec -it $(balena ps -q -f name=MY-CONTAINER-NAME). Rather than curling root (/) to check for inter-container communications, it may be better to use whatever healthcheck mechanism Socket.io provides and you have set up, if any. You can read more about inter-container communication here: Container networking | Docker Documentation

Let us know if this helps!

Regards,
Christina

1 Like

More about Docker bridge networks here: Use bridge networks | Docker Documentation

Hi Christina, thanks for the explanation!

I tried to run these curl commands from my Frontend Terminal to two of my others and both refused connection.

Here’s what the logs said:

curl localhost:8282
Failed to connect to localhost port 8282: Connection Refused
curl server:8282
Could not resolve host: server

Here’s my Docker-Compose if that helps:

version: ‘2’
services:
redis:
image: “redis:alpine”
network_mode: host
privileged: true
ports:
- “6379:6379”
frontend:
build: frontend
network_mode: host
privileged: true
# labels:
# io.balena.features.supervisor-api: 1
ports:
- “80:80”
packet_radio:
build: packet_radio
network_mode: host
privileged: true
labels:
io.balena.features.kernel-modules: 1
io.balena.features.firmware: 1
ports:
- “8181:8181”
usb_scale:
build: usb_scale
network_mode: host
privileged: true
labels:
io.balena.features.dbus: 1
io.balena.features.kernel-modules: 1
io.balena.features.firmware: 1
ports:
- “8282:8282”
browser:
image: bhcr.io/balenablocks/browser-aarch64
privileged: true
restart: always
network_mode: host
ports:
- ‘5011’ # management API (optional)
- ‘35173’ # Chromium debugging port (optional)
wifi-connect:
build: ./wifi-connect
network_mode: “host”
labels:
io.balena.features.dbus: ‘1’
cap_add:
- NET_ADMIN
environment:
DBUS_SYSTEM_BUS_ADDRESS: “unix:path=/host/run/dbus/system_bus_socket”

@Mattssmith94 what do you mean? from HostOS or from the frontend service? did you try to curl usb_scale?

I attempted to run the command from the frontend service to the usb_scale to see if they could communicate with one another.

Could you please share the error that you get @Mattssmith94 ?

Sure, here’s a screenshot of what I get with the attempted Curl command:
image

Hi

looking at your docker-compose files, the services are in network host made so the port should be accessible

  • can you confirm that the services are running and that there is a server listening on the ports?
  • did you try running curl localhost:8282 from the usb-scale service? does it work?
  • perhaps you can provide support access to your device and let us know the uuid of the device so we can take a look. please see our docs

Right now, if the device has no connection to the internet, the browser says that Localhost is not responding.

can you please elaborate? how is the page loaded? is it stored somewhere on the device or loaded from a server?

Can you share the source of your project in a public git repo?

thanks

Hi Rahul,
I can confirm that the services are running, but I’m not sure how to confirm that there’s a server listening (again, somewhat new to this).

I tried running “curl localhost:8282” on “usb_scale” and it does not work, however, “curl localhost:80” does work, and returns the HTML file that my frontend (on port 80) is running. This appears to work from any other service.

As for support, I have been trying to register my balena account as a paid prototype account, but the links to do so lead me to a blank page, and I contacted sales yesterday but have not heard a reply yet.

I was mistaken in my wording of the localhost error. When there’s no internet connection, the browser displays a page that says “Localhost refused to connect”.
The source of the project is proprietary and I’m not allowed to share it without permission from my client.

Hi, i’m having a bit trouble what you are trying to achieve

but I’m not sure how to confirm that there’s a server listening (again, somewhat new to this)
I tried running “curl localhost:8282” on “usb_scale” and it does not work

what are you testing by running curl localhost:8282? i would expect you have a server listening on that port for the usb_scale service. but it seems there is not?

however, “curl localhost:80” does work, and returns the HTML file that my frontend (on port 80) is running. This appears to work from any other service.

this does indicate that a web server is running as intended and returning the webpage

I was mistaken in my wording of the localhost error. When there’s no internet connection, the browser displays a page that says “Localhost refused to connect”.

what is the page trying to access?

i think it would still be easier to debug this if you provided a sample application

The source of the project is proprietary and I’m not allowed to share it without permission from my client.

perhaps you can remove proprietary services and provide a minimal example?

As for support, I have been trying to register my balena account as a paid prototype account, but the links to do so lead me to a blank page, and I contacted sales yesterday but have not heard a reply yet.

We are a distributed team. i believe the team will get back to you as soon as possible. but in the meantime, can you please provide more details about the process you followed to sign up for the plan. and ran into the issue? that sounds like a bug we should fix.

Also, you should be able to grant support access even if you are on the free plan. how are you provisioning your device?
are you using balenaCloud?

thanks for providing these clarifications so we can better assist you

Hi mattssmith.
I’ve been looking for your email so I could help you with the upgrade, and I haven’t found anything. Please write to sales@balena.io so we can pick it up from there (and sorry if any other colleague contacted you and I didn’t notice).
That problem with the blank page you are finding is new, so I would like to take a look at it.
Thank you!

Hi rmorrillo24,
I just sent an email over to the email address you provided. Two days ago I had used the Contact Sales form on balena - Scale pricing from prototype to enterprise usage and haven’t heard a response.

Thanks

Hi Rahul,

I’m trying to get my application to run offline. I think you’re correct about the servers listening in on the ports, as I’ve found the server listen for Frontend’s port, but not for the other containers. I’m working on adding those now.

As for the links I found that lead to a blank page, the “Sign Up” links on the balena - Scale pricing from prototype to enterprise usage page under each plan take me to my fleets currently, and the “Login to Dashboard” link here: balena - Get in touch for support takes me to a blank page on my dashboard.

I found that I can grant support access as you said, we are using BalenaCloud, but because time is limited on that, how will I know if support got to the devices within the timeframe and what changes they’ve made?

Thank you for all of the replies, this is a difficult problem for my client and I, and I appreciate the help offered here