Topic Closed
tom
7 Posts

Hi all,

I have designed a plugin that I use on my site. It takes the data from my weewix weather station and displays the current temperature. This is from a MySQL database. The problem is that I think the cache on browsers won't allow me to get the current weather details.

Can I force the plugin to do an update.

The site is https://ctd.noip.me

 

Tom

1 year ago#11054

juergen
1.4K Posts
51.3K Downloads
16 Plugins
design, web development & visual effects

Most likely not a browser cache issue but I probably don't understand the issue.
I assume your Typesetter plugin opens a connection to a local database which is fed by your weather station software (weewx) and renders the data (in a Gadget?)

If i visit your site, seems that I get new data every 5 minutes, but I need to manually refesh the page to update the values.
Do you want your plugin to update them automatically every 5 mins w/o a page refresh? Or are you seeing old values?

1 year ago#11055

tom
7 Posts

Yes I use a local database and it is a gadget. I use the same idea in another site to display two weather stations. It is a free site for a friend to show local sites in our area. The person in Geeveston noticed his weather data not updating when he came back to his page. They use the same gadget idea. I would have liked it to automatically updated the weather but just to be current would be fine. The other site is.

https://huonviews.servepics.com 

Very happy with the sites and will be so much better when we have 10 or more cameras setup around the district.

So the issue seems to me that even though I have new data it is not updating the page even after a refresh.

Tom

 

here is the code i use

<?php
defined('is_running') or die('Not an entry point...');

class weewix{
    function weewix(){

        $folder =  
        $latest_ctime = 0;
        $latest_filename = '';
        $latest_update = '';    
        $d = dir($path);

        
        $db_hostname='localhost';
        $db_username='xxx';
        $db_password='xxx';
        $db_database='weewx';
        $conn = mysqli_connect($db_hostname, $db_username, $db_password, $db_database);

        if (!$conn) {
            echo "Error: Unable to connect to MySQL." . PHP_EOL;
            echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
            echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
            exit;
        }
        // get rain for today
        $rainSum = 0;
        $query = 'SELECT sum FROM archive_day_rain ORDER by datetime DESC LIMIT 1';
        $val_result = $conn->query($query);
        if (mysqli_num_rows($val_result) > 0) {
            // output data of each row
            while($val = mysqli_fetch_assoc($val_result)) 
            {
            $rainSum = $val['sum'];
            }
        }

        // get temp min/max for today
        $tempMin = 0;
        $tempMax = 0;
        $query = 'SELECT min, minTime, max, maxTime FROM archive_day_outTemp ORDER by datetime DESC LIMIT 1';
        $val_result = $conn->query($query);
        if (mysqli_num_rows($val_result) > 0) {
            // output data of each row
            while($val = mysqli_fetch_assoc($val_result)) 
            {
            $tempMin = $val['min'];
            $tempMax = $val['max'];
            }
        }
        
        $query = 'SELECT datetime, outTemp, inTemp, rainRate, rain, barometer, windSpeed, windDir , windGust FROM archive ORDER by datetime DESC LIMIT 1';
        $val_result = $conn->query($query);
        if (mysqli_num_rows($val_result) > 0) {
            // output data of each row
            while($val = mysqli_fetch_assoc($val_result)) 
            {
                if ($latest_update <> $val["datetime"]) { 
                    $latest_update = $val["datetime"];
                    $date_array = getdate();

                    $body = date("D j M, \a\\t g.i:s a", time()) . '
                    <br><i>At Police Point, Tasmania.</i>
                    <table style="width:100%">
                        <tr>
                            <td style="width:40%"><b>Temp:</b></td>
                            <td>' . number_format($val["outTemp"],1) . '&degC</td> 
                        </tr>
                        <tr>
                            <td style="width:40%"><b>Min Temp:</b></td>
                            <td>' . number_format($tempMin,1) . '&degC</td> 
                        </tr>
                        <tr>
                            <td style="width:40%"><b>Max Temp:</b></td>
                            <td>' . number_format($tempMax,1) . '&degC</td> 
                        </tr>
                        <tr>
                            <td style="width:40%"><b>Rain:</b></td>
                            <td>' . number_format($val["rainRate"],1) . ' mm/hr</td>
                        </tr>
                        <tr>
                            <td style="width:40%"><b>Today:</b></td>
                            <td>' . number_format($rainSum,1) . ' mm</td>
                        </tr>
                        <tr>
                            <td style="width:40%"><b>Wind:</b></td>
                            <td>'. number_format($val["windSpeed"] * 3.6,0) . ' km/h at ' . number_format($val["windDir"],0) .'&deg</td>
                        </tr>
                        <tr>
                            <td style="width:40%"><b>Peak:</b></td>
                            <td>'. number_format($val["windGust"] * 3.6,0) .' km/h</td>
                        </tr>
                    </table>    
                    ';

                }
            }
        }
        echo $body . '<hr>';
    }
}

Edited: 1 year ago#11056

juergen
1.4K Posts
51.3K Downloads
16 Plugins
design, web development & visual effects

I can't see a reason why it should not work (except maybe some possible timezone/DST related mismatch)

You can easily check if it's the browser cache. Simply add a line like

echo '<p>Now = ' . date('Y-m-d H:i:s') . '</p>';

If the output changes when you refresh the page, it's not a browser cache issue.

Edited: 1 year ago#11057

tom
7 Posts

Thanks for that.

Have added the time check and see what happens.

1 year ago#11058

juergen
1.4K Posts
51.3K Downloads
16 Plugins
design, web development & visual effects

When I visit your site https://ctd.noip.me I always get the current local date/time and seemingly also new weather data every 5 mins.
So there is no caching, at least with my connection (from roughly the opposite of the world).

If  the values don't update properly on your or your visitors’ side, I believe it must be a proxy server caching in between.

1 year ago#11060

juergen
1.4K Posts
51.3K Downloads
16 Plugins
design, web development & visual effects
To me it looks much as if the weather station in Geeveston only updates the DB once per hour.
1 year ago#11061

Topic Closed

 

News

Typesetter 5.1
8/12/2017

Typesetter 5.0.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

Over 8 Times Faster Than Wordpress
5/3/2016

We've known for a long time that Typesetter is fast. It's something we take pride ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Luzern (Schweiz): * Konzeption, Planung und Erstellung Ihres Internet-Auftritts * Betreuung und Aktualisierung/Pflege Ihrer Website * ...

Find out more about our Provider Spotlight

Log In

  Register