Belchertown hook1 not refreshing

100 views
Skip to first unread message

Tim Tuck

unread,
Sep 24, 2020, 3:39:28 AM9/24/20
to weewx-user
Hi all,

I have this in my index_hook_after_station_info.inc

<div style="text-align: center; background-color:
#$aqi($current($data_binding='aqi_binding').aqi_pm2_5_category).color;" >
    <H2>  The 24hr AQI for South Penrith is
$current($data_binding='aqi_binding').aqi_pm2_5 which is
$aqi($current($data_binding='aqi_binding').aqi_pm2_5_category).category.</H2>
</div>


and in /etc/weewx/weewx.conf I have ..

            reload_hook_images = 1
            reload_images_hook_asi = 300

But hook1 never refreshes.

Have I missed something ?

thanks

Tim


Manfred Maier

unread,
Sep 24, 2020, 7:46:16 AM9/24/20
to weewx-user
Hi Tim,
the only thing you've missed is that the refresh of the image hooks only works for images.

There is a workaround available (using some custom script). I hopefully find some time later in the evening to post the solution here.

I'm using this workaround on my page: wetter-zorneding.de
The text below the station observations updates automatically (showing the sunshine hours and amount of rain).

Best,
Manfred

Manfred Maier

unread,
Sep 24, 2020, 3:50:13 PM9/24/20
to weewx-user
So, this is my approach.

In the index.html.tmpl I've included the following script:

    <script>
        setInterval("reload_hook();", 10000);
        function reload_hook () {
                $.get('./hooks/hook_after_station_info.html', function(data) {
                        \$('#target_after_station_info').html(data);
                })
        }
    </script>      

This script replaces later in the index.html a certain content by the content of the file hook_after_station_info.html in the subfolder 'hooks'. The replacement is done every 10000 milliseconds.

In the same index.html.tmpl file I've replaced the code, that manages the content of the "index_hook_after-station_info" by the following:

                #if os.path.exists("index_hook_after_station_info.inc")
                <!-- Start of index_hook_after_station_info row -->
                <div class="row index-hook-after-station-info border-bottom">
                    <div id="target_after_station_info">
                    #include "index_hook_after_station_info.inc"
                    </div>
                </div>
                <!-- End of index_hook_after_station_info row -->
                #end if

 In the index_hook_after_station_info.inc I've put the HTML code that should be displayed on the page. In my case the file contains a couple of custom calculations of variables and then the following html code:

<br>
<p align="center" style="font-size:24px">
$suntext $raintext
<br>
<a href="https://www.brezentrager.de/wetter-zorneding/" target="_blank">Hier geht's zur aktuellen Vorhersage für Zorneding</a>
</p>
<br>

The last missing part is the file that is used to update the index hook.
As mentioned above, this file is stored in the subfolder 'hooks'. So create this subfolder in your Belchertown folder and create a file called 'hook_after_station_info.html.tmpl'. The content of this file is identical to the content of the index_hook_after_station_info.inc

Finally you have to tell Belchertown, that this file has to be produced every time the skin is produced. This can be done in the skin.conf file.
Under [CheetahGenerator] add:

        [[[hooks]]]
            template = hooks/hook_after_station_info.html.tmpl

This approach leads to the desired behavior (i.e. the index hook updates automatically). But I'm definitely not an experienced web-programmer. I'm pretty sure there is a more elegant way of doing it. There's for example no reason for having two separate file with the code for the index_hook. This easily could be done with just one file.

Hope this works for you. In case you have any questions, please let me know.

Best,
Manfred

Tim Tuck

unread,
Sep 27, 2020, 8:39:24 PM9/27/20
to weewx...@googlegroups.com

Hi Manfred,

Thanks for that, I'll have to give that a try,

cheers

Tim

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/ec9f86d9-7a8f-4df7-aa39-9dab82d9df52n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages