{"id":1482,"date":"2019-03-16T15:15:38","date_gmt":"2019-03-16T06:15:38","guid":{"rendered":"https:\/\/blog.fourthgate.jp\/?p=1482"},"modified":"2019-03-16T15:16:44","modified_gmt":"2019-03-16T06:16:44","slug":"raspberry-pi%e3%81%a7%e6%b8%a9%e5%ba%a6%e8%a8%88%e6%b8%ac%ef%bc%88%e3%81%9d%e3%81%ae2%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.fourthgate.jp\/?p=1482","title":{"rendered":"Raspberry Pi\u3067\u6e29\u5ea6\u8a08\u6e2c\uff08\u305d\u306e2\uff09"},"content":{"rendered":"<p>\u5148\u65e5\u306e\u30e9\u30ba\u30d1\u30a4\u6e29\u5ea6\u8a08\u3001\u5ef6\u3005\u3068\u6e29\u5ea6\u8a08\u6e2c\u3092\u7d9a\u3051\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4e00\u65e5\u306e\u6e29\u5ea6\u5909\u5316\u306f\u3001\u6e2c\u5b9a\u30c7\u30fc\u30bf\u3092\u5168\u3066\u53d6\u5f97\u3059\u308c\u3070\u3088\u3044\u3067\u3059\u3067\u304c\u3001\u9031\u9593\u3068\u304b\u6708\u9593\u3068\u3044\u3063\u305f\u9577\u3044\u30b9\u30d1\u30f3\u306b\u306a\u308b\u3068\u3001\u30c7\u30fc\u30bf\u3092\u306f\u3057\u3087\u3063\u305f\u307b\u3046\u304c\u3088\u3044\u3067\u3059\u3002<br \/>\n\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u6e2c\u5b9a\u30c7\u30fc\u30bf\u306e\u79fb\u52d5\u5e73\u5747\u3092\u53d6\u3063\u3066\u307f\u3088\u3046\u3068\u601d\u3044\u7acb\u3061\u307e\u3057\u305f\u3002<\/p>\n<p>\u8272\u3093\u306a\u30b5\u30a4\u30c8\u3092\u53c2\u8003\u306b\u3055\u305b\u3066\u9802\u3044\u3066\u3001\u306a\u3093\u3068\u304b\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<br \/>\nCakePHP3\u3067\u306e\u30b3\u30fc\u30c9\u306f\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002<\/p>\n<p><code>$hm_data = $this->ondo_data->find( )<br \/>\n    ->join( [\u3000\u3000\u3000\u3000\u3000\u3000.....(3)<br \/>\n        'table' => 'temperature_histories',<br \/>\n        'alias' => 'subtbl',<br \/>\n        'type' => 'LEFT',<br \/>\n        'conditions' => [<br \/>\n            'TIMESTAMPDIFF(MINUTE, TemperatureHistories.measuring_datetime, subtbl.measuring_datetime) BETWEEN -35 AND 35',<br \/>\n            'TemperatureHistories.sensor_id = subtbl.sensor_id',<br \/>\n        ],<br \/>\n    ] )<br \/>\n    ->select([<br \/>\n        'dayhhmm' => \"DATE_FORMAT(TemperatureHistories.measuring_datetime, '%d %H:%i')\",<br \/>\n        'hourAvg' => 'AVG(CAST(subtbl.temperature AS SIGNED))',\u3000\u3000\u3000\u3000\u3000\u3000.....(5)<br \/>\n        'measuring_datetime' => 'TemperatureHistories.measuring_datetime',<br \/>\n    ])<br \/>\n    ->where(function ($exp, $q) use ( $sdate, $edate ) {\u3000\u3000\u3000\u3000\u3000\u3000.....(1)<br \/>\n        return $exp->between( 'TemperatureHistories.measuring_datetime', $sdate, $edate );<br \/>\n    })<br \/>\n    ->where( ['MINUTE(TemperatureHistories.measuring_datetime)' => '00', 'TemperatureHistories.sensor_id' => $sensor_id ] )\u3000\u3000\u3000\u3000\u3000\u3000.....(2)<br \/>\n    ->group([ 'TemperatureHistories.measuring_datetime' ])\u3000\u3000\u3000\u3000\u3000\u3000.....(4)<br \/>\n    ->order([ 'TemperatureHistories.measuring_datetime' => 'ASC' ])\u3000\u3000\u3000\u3000\u3000\u3000.....(6)<br \/>\n    ->all();<\/code><\/p>\n<p>temperature_histories \u306f\u30c6\u30fc\u30d6\u30eb\u540d\u3002<br \/>\ntemperature \u3078\u8a08\u6e2c\u7d50\u679c\u304c\u5165\u308a\u307e\u3059\u3002<br \/>\nmeasuring_datetime \u306f\u8a08\u6e2c\u65e5\u6642\u3002<br \/>\nsensor_id \u306f\u3001\u6e29\u5ea6\u30bb\u30f3\u30b5\u30fc\u306eID\u3067\u3059\u3002<\/p>\n<p>\u5927\u3056\u3063\u3071\u306a\u89e3\u8aac\u306f\u2026<br \/>\n(1)\u96c6\u8a08\u671f\u9593\u306f\u3001$sdate \u3068 $edate \u306e\u9593\u3067\u3059\u3002<br \/>\n(2)\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u306e\u306f\u3001$sensor_id \u6307\u5b9a\u3055\u308c\u308b\u30bb\u30f3\u30b5\u30fc\u3001\u6642\u9593\u306f\u6b63\u6642\uff0800\u5206\uff09\u6bce\u3068\u3057\u307e\u3059\u3002<br \/>\n(3)subtbl\u3068\u3044\u3046\u5225\u540d\u3067\u81ea\u5206\u81ea\u8eab\u3092join\u3057\u307e\u3059\u304c\u3001\u305d\u306e\u969b\u306b\u3001\u6e2c\u5b9a\u6642\u9593\u306e\u524d\u5f8c35\u5206\u9593\u306e\u6e2c\u5b9a\u5024\u3082\u53d6\u5f97\u3057\u307e\u3059\u3002<br \/>\n(4)join\u3057\u305f\u30c6\u30fc\u30d6\u30eb\u304b\u3089\u306f\u8907\u6570\u306e\u30c7\u30fc\u30bf\u304c\u304f\u308b\u306e\u3067\u3001TemperatureHistories.measuring_datetime \u3067\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u307e\u3059\u3002<br \/>\n(5)\u4e0a\u8a18(3)\u3067join\u3057\u305fsubtbl\u304b\u3089\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u306e\u5e73\u5747\u5024\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002<br \/>\n(6)\u5f53\u305f\u308a\u524d\u3067\u3059\u304c\u3001\u6e2c\u5b9a\u6642\u9593\u3067\u30bd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\n<p>temperature \u3092 CAST \u3057\u3066\u3044\u308b\u306e\u306f\u3001temperature\u304c\u6570\u5024\u578b\u3067\u306f\u306a\u304f\u6587\u5b57\u5217\u578b\u306e\u305f\u3081\u3067\u3059\u3002<br \/>\n\u6700\u521d\u306b\u3001\u3042\u307e\u308a\u6df1\u304f\u8003\u3048\u305a\u306b\u3001\u6587\u5b57\u5217\u578b\u306b\u3057\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3001\u3053\u3093\u306a\u3053\u3068\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\ndayhhmm \u306f\u30b0\u30e9\u30d5\u5316\u3059\u308b\u6642\u306b\u6a2a\u8ef8\u3067\u4f7f\u7528\u3059\u308b\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>\u3067\u3001\u5f97\u3089\u308c\u305f\u30c7\u30fc\u30bf\u3092\u30b0\u30e9\u30d5\u5316\u3057\u305f\u3089\u3001\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br \/>\n<a href=\"https:\/\/blog.fourthgate.jp\/wp-content\/uploads\/2019\/03\/ondo.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.fourthgate.jp\/wp-content\/uploads\/2019\/03\/ondo-300x159.png\" alt=\"\" width=\"300\" height=\"159\" class=\"aligncenter size-medium wp-image-1489\" srcset=\"https:\/\/blog.fourthgate.jp\/wp-content\/uploads\/2019\/03\/ondo-300x159.png 300w, https:\/\/blog.fourthgate.jp\/wp-content\/uploads\/2019\/03\/ondo-768x406.png 768w, https:\/\/blog.fourthgate.jp\/wp-content\/uploads\/2019\/03\/ondo-1024x542.png 1024w, https:\/\/blog.fourthgate.jp\/wp-content\/uploads\/2019\/03\/ondo.png 1599w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u65e5\u306e\u30e9\u30ba\u30d1\u30a4\u6e29\u5ea6\u8a08\u3001\u5ef6\u3005\u3068\u6e29\u5ea6\u8a08\u6e2c\u3092\u7d9a\u3051\u3066\u3044\u307e\u3059\u3002 \u4e00\u65e5\u306e\u6e29\u5ea6\u5909\u5316\u306f\u3001\u6e2c\u5b9a\u30c7\u30fc\u30bf\u3092\u5168\u3066\u53d6\u5f97\u3059\u308c\u3070\u3088\u3044\u3067\u3059\u3067\u304c\u3001\u9031\u9593\u3068\u304b\u6708\u9593\u3068\u3044\u3063\u305f\u9577\u3044\u30b9\u30d1\u30f3\u306b\u306a\u308b\u3068\u3001\u30c7\u30fc\u30bf\u3092\u306f\u3057\u3087\u3063\u305f\u307b\u3046\u304c\u3088\u3044\u3067\u3059\u3002 \u3068\u3044\u3046\u3053\u3068\u3067\u3001\u6e2c\u5b9a\u30c7\u30fc\u30bf\u306e\u79fb\u52d5\u5e73 &hellip; <a href=\"https:\/\/blog.fourthgate.jp\/?p=1482\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1482","post","type-post","status-publish","format-standard","hentry","category-web"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/posts\/1482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1482"}],"version-history":[{"count":9,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/posts\/1482\/revisions"}],"predecessor-version":[{"id":1492,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=\/wp\/v2\/posts\/1482\/revisions\/1492"}],"wp:attachment":[{"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.fourthgate.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}