Open Source app for Open Weather Map

Hi,

I want to share my Open Source app - Open Weather Widget:

https://apps.garmin.com/en-US/apps/1f3f2d10-ac05-4a9b-a8fa-bdeac8775793

Here is the complete code for it:

https://github.com/desyat/OpenWeatherMapWidget

Specific things that are used in the code:

- Background web requests (OWM API)

- Online web requests

- Open Weather Map API usage example

- Glance view for widgets

It is challenging to reuse the code for 3 different processes in the app (main app, background, and glance view). I attempted to minimize code repetition, but as a result the code got a bit more complicated. Feel free to ask questions or recommend improvements.

Thanks!

  • You considered doing a barrel for this?  That's how I've done OWM and other things.  It helps to keep the code in one place. no matter how many things use it.  A .barrel is actually just a .zip of the barrel project, so the source is easy to get to if needed.

    What issues did you have with running in a background, glance, or main app?  I don't recall it being much more than proper annotations.  I use all there modes (background, glance, foreground) in the same widget/super app for example.

  • Here are 2 things I'd like to figure out:

    - How to annotate code to be used in both, Glance AND Background (main process seems to be able to use any of that code already)?

    - Is it possible to change APP icon used in Glance View? I know "Garmin Weather" widget does it (different icon for different weather conditions), but is it possible for 3rd party apps?

    There was also an issue of simulator working differently from a real device - specifically in how Global variables were visible from different processes. 

  • -Like this for the annotation:

    (:background :glance)

    But you really only need (:background) to use it in a glace or the main app.  The way this all basically works, is the annotation defines where in the prg something is placed.  Anything with (:background) is first. (:glance) is next, and everything else 3rd..  So when the background runs, the first part of the .prg gets loaded and used.  In a glance view. the first two parts, and the main app, all the code.

    -no way to change the launcher_icon in CIQ.  The Garmin weather widget isn't done in CIQ

    - as far as globals, using a simple case of "var a=0;" as a global, the parts can all reference "a", but it's not the same "a".  The background and main app have their own copies of "a", so if the background has a=123; when the main app references a, it's still 0.

    If you are in the glace view and do "a=123;" the main view will see "abc==123"

  • Good Info, thanks! I guessed as much about the icons in Glances - Garmin should implement it for IQ apps though.

    Here is what happened with Global Variables in my app. There is a global function and some variables annotated as (:glance). The function updates those global variables. In simulator, when I run the function from main process, I see updated global variables. On a real device, the global variables didn't change for the main process.

  • The background and glance part of an app has a limited amount of memory compared to the main app.

    If the background is limited to 32k (really 28k), the background and glance also has that limit so you want to make sure you do not run into memory issues.

    Here's one of mine with a background and a glance Notice the memory data on the bottom line.:

  • Here is what happened with Global Variables in my app. There is a global function and some variables annotated as (:glance). The function updates those global variables. In simulator, when I run the function from main process, I see updated global variables. On a real device, the global variables didn't change for the main process.

    For this problem I decided to change the function to return values to the process that called it (see function getSettings() in GlobalCode.mc). Not ideal, but it works Slight smile

  • Now that I think about this, it makes sense and the real device is correct.  When you go from a glance to full screen, the entire .prg gets loaded, so a global isn't retained in that case.

    In general, I avoid globals, so hadn't seen this.

  • Thing is, the function was called from the main view, not from Glance, so it should have updated global variables visible to the main view. 

  • A different memory space.

  • Exactly my point on difficulties of re-using code between all 3 internal processes. Something developers should be aware of.