Top > 日記 > 2021-03-16

supermonの地域温度表示

AllstarLinkのコントロール画面(supermon)の初期地域温度表示は主に米国の
地域しか対応してないので、日本国内対応版にlink.phpを改変した。
参考:PHPで天気を取得、表示させたい!OpenWeatherMap APIの使い方 (hsmt-web.com)

  1. 【概要】
     
     Webサーバ上に、wth.phpを作成する。 --- /var/www/html/wth.php
     1.自Webserver 上にwth.phpを作成する
     2.link.phpを改修して、wth.phpをアクセスさせる
     3.得られた文字列を加工・抽出して表示させる
     具体的に要求するURLは
      [[http://api.openweathermap.org/data/2.5/weather?q=mobara,jp&appid=xxxxxxxyyyyyzzz: ]]
     ※appidは個人で得たAPIのid。http://192.168.xx.yy/wth.php をブラウザで開くと
    w_iconMobaraw_nameTemp_16_degfew clouds_Description_Press_1009_hpascalWind_13.89_m/sSunrise:05:03:39Sunset:17:03:29
    が得られ、このTemp_16_deg を抽出する。
  2. 【詳細】 
    /var/www/html/wth.php ----
    <!DOCTYPE html>
    <html>
    <head>
    <title>OpenWeather</title>
    </head>
    <body>
    <?php
    $url = "http://api.openweathermap.org/data/2.5/weather?q=";
    $city = 'mobara,jp&';
    $appid = 'appid=b31f206a2ad51c9a3928e4ed36e0c0ac';
    #$url = $city.$appid;
    $url = "http://api.openweathermap.org/data/2.5/weather?q=mobara,jp&appid=xxxxxxxyyyyyzzz";
    $icon = '<img align="middle" style="width:45px;" src="http://openweathermap.org/img/w/';
    $k_temp = 273.15;
    $json = file_get_contents($url);
    $json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
    $arr = json_decode($json,true);
    if ($arr === NULL) {
        return;
    }else{
        $weather_temp = $arr["main"]["temp"] - $k_temp;
        $weather_temp_min = $arr["main"]["temp_min"] - $k_temp;
        $weather_temp_max = $arr["main"]["temp_max"] - $k_temp;
        $weather_id = $arr["weather"][0]["id"];
        $weather_description = $arr["weather"][0]["description"];
        $weather_icon = $icon.$arr["weather"][0]["icon"].'.png">';
        $weather_main = $arr["main"]["temp_min"];
        $weather_lat = $arr["coord"]["lat"];
        $weather_lon = $arr["coord"]["lon"];
        $weather_pressure = $arr["main"]["pressure"];
        $weather_humidity = $arr["main"]["humidity"];
        $weather_speed = $arr["wind"]["speed"];
        $weather_name = $arr["name"];
        $weather_country = $arr["sys"]["country"];
        $weather_sunrise = $arr["sys"]["sunrise"];
        $weather_sunset = $arr["sys"]["sunset"];
        echo '<p style="position: static;margin:0;">';
        echo($weather_icon.'w_icon');
        echo($weather_name.'w_name');
        echo('Temp_'.intval($weather_temp).'_deg');
        echo($weather_description.'_Description_');
        echo('Press_'.$weather_pressure.'_hpascal');
        echo('Wind_'.$weather_speed.'_m/s');
        echo 'Sunrise:'.date( "H:m:s" , $weather_sunrise ).'';
        echo 'Sunset:'.date( "H:m:s" , $weather_sunset ).'<br>';
        echo '</p>';
    }
        echo('Wind_'.$weather_speed.'_m/s');
        echo 'Sunrise:'.date( "H:m:s" , $weather_sunrise ).'';
        echo 'Sunset:'.date( "H:m:s" , $weather_sunset ).'<br>';
        echo '</p>';
    }
    ?>
    </body>
    </html>?>
    </body>
    </html>
     
    以下工事中
     

    URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White


リロード   新規 下位ページ作成 凍結解除 差分 コピー 名前変更   ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: Wed, 11 Mar 2026 17:11:07 JST (10d)