Balenadash: how to change URL dynamically

I’ve got a balenadash up and running. I can point it to a URL with the WPE_URL environment variable.

How might I go about changing the web page on screen, without logging into balena-cloud, changing a device variable, waiting for the containers to restart…

I would like to be able to ping a webhook on the device and have the displayed webpage change. Happy to open source my work but not sure how I would go about getting started… or is this something that’s easy to do without further development?

Hey @mozz100

I think a good approach to this is, instead of changing the WPE_URL variable, you can point your device to a website hosted on the same device, and have that page redirect to other pages.

Here is an example project https://github.com/balena-io-playground/balena-dash-google-photos, if you see the file https://github.com/balena-io-playground/balena-dash-google-photos/blob/master/wpe/public_html/index.html it waits for one page to come alive and then redirect. It’s not the exact same as you asked, but its the general idea.

On a second idea, you can update the environment variable using the API here https://www.balena.io/docs/reference/api/resources/device_environment_variable/#update-device-env-var

Let me know if this helps,
Cheers

Thanks @dansku - response much appreciated. I’m still seeking more help, please: I’m not sure either approach solves the problem for me. Maybe I’m not understanding correctly. Here goes…

Your first suggestion - I could just implement a server that issues a 301 redirect, right? But once I have redirected the on-screen browser to e.g. www.bbc.co.uk/news, I lose control and can’t switch away from it, until everything is restarted by a reboot or something. If I’m understanding things correctly, the process inside the wpe container doesn’t restart itself on a schedule, or check the WPE_URL periodically. Or does it?

Your second suggestion about changing the variable using the API. I can do that - nice API and docs! - but this exhibits the exact problem I’m trying to solve. After I hit the API I get “OK”, but there’s no on-screen indication until tens of seconds later, when the containers begin to cycle, and after that it’s about 2 minutes wait while the containers restart. The new page displays as expected.

So what I have discovered is if I manually go to the balena UI and use the web-based terminal to execute e.g. WPELauncher https://www.bbc.co.uk/ inside the wpe container, a new browser fills the screen and renders quickly. After I hit Ctrl+C, I’m back to where I was - the original page shows back.

Can I get my device or containers to listen for some network-originated instruction and do the same thing? I’d like colleagues to be able to send a URL to the screen and see it load in front of their eyes. That would be so awesome - and I would certainly share the code.

Can I e.g. run a python of javascript process alongside the two containers already running, and send some sort of signal to the wpe process, or run commands inside it? Or can I write a script that runs inside the wpe container and listens on a port (js or python preferable, but open to suggestions)?

Or is there another way I could listen on a port and control the screen on the wall without the two-minute delay?

All help much appreciated.

(EDIT - clarification)

Maybe an http server compiled for ARM and running inside the wpe container? Might be my first golang project

@mozz100 check out my alternative balenaDash project here, which includes support for multiple URLs. Let me know if you need help! https://github.com/willswire/balena-dashboards

So, I wrote my first ever lines of golang. It works nicely. Plenty of features that could be added but new URLs flash up on screen pretty much instantly with this, and it reverts to existing behaviour when it’s not doing anything

@mozz100 this is very cool. We would love to roll your work into the balenaDash project and add this as a feature; have you considered submitting a PR to add that functionality?

Thanks @chrisys - I’ll submit a PR soon. Gimme a couple of days to write a blog post (spare time limited at the mo!) about my (excellent) experiences with balena first? :slight_smile:

1 Like

Sounds awesome and maybe a perfect candidate for our blog4swag program - just let me know when you’ve posted it :wink:

Alrighty - I created “tohora” and have blogged about my experiences making it on balena here: https://www.rmorrison.net/mnemozzyne/2019/03/07/tohora-instant-control-balenadash/

and submitted a pull request here - https://github.com/balena-io-projects/balena-dash/pull/10

Hope it’s useful to others!

1 Like