{"id":267,"date":"2014-05-14T22:16:41","date_gmt":"2014-05-14T21:16:41","guid":{"rendered":"http:\/\/www.anginf.de\/?p=267"},"modified":"2015-12-16T16:05:28","modified_gmt":"2015-12-16T15:05:28","slug":"monitor-raspberry-pi-temperature-from-an-external-server","status":"publish","type":"post","link":"https:\/\/www.anginf.de\/?p=267","title":{"rendered":"Monitor Raspberry Pi temperature from an external server"},"content":{"rendered":"<p>I&#8217;m using a raspberry pi with XBMC as a mediaplayer. As I didn&#8217;t want to have a lot of trouble maintaining it, I decided to try <a href=\"http:\/\/openelec.tv\/\" title=\"OpenELEC Homepage\" target=\"_blank\">OpenELEC<\/a>. It works fine, but it&#8217;s really limited to only the media-related parts.<\/p>\n<p>I wanted to know how much the temperature changes when using my raspberry pi and I already had a working cacti-server in my LAN. But what would be the best way to read the temperature from the pi without pushing too many binaries onto the system?<\/p>\n<p>The answer is &#8222;socat&#8220; &#8211; and of course, the binary is NOT part of the OpenELEC-distribution. But I was able to compile the socat as a static binary on another raspberry pi, which was runnning <a href=\"http:\/\/www.raspbian.org\/\" title=\"Raspbian Homepage\" target=\"_blank\">raspbian<\/a>.<\/p>\n<pre lang=\"bash\">\r\n.\/configure LDFLAGS=\"-static\"\r\nmake\r\n<\/pre>\n<p>Copy the resulting binary <code>socat<\/code> to the OpenELEC-raspberry. If you can&#8217;t create the binary yourself, you can download it from here:<\/p>\n<p><a href=\"https:\/\/www.anginf.de\/download\/raspi\/socat\" target=\"_blank\">socat 1.7.2.4 statically linked<\/a><\/p>\n<pre>socat: ELF 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU\/Linux 2.6.26, BuildID[sha1]=8ca6f5b38a7836cefe0721295d946dd9f90fb98e, not stripped<\/pre>\n<p>Put the socat in a new directory called <code>\/storage\/tempservice\/<\/code>.<\/p>\n<p>Add the following two files in the same directory <code>\/storage\/tempservice\/<\/code>:<\/p>\n<p><code>socat-service.sh<\/code><\/p>\n<pre lang=\"bash\">\r\n#!\/bin\/bash\r\n\/storage\/tempservice\/socat -T 1 -d -d tcp-l:9888,reuseaddr,fork,crlf system:\"\/storage\/tempservice\/t.sh\"\r\n<\/pre>\n<p><code>t.sh<\/code><\/p>\n<pre lang=\"bash\">\r\n#!\/bin\/bash\r\ncat \/sys\/class\/thermal\/thermal_zone0\/temp\r\n<\/pre>\n<p><code>socat-service.sh<\/code> will later start the service, while <code>t.sh<\/code> reads the temperature itself.<\/p>\n<p>To make sure that the service is started on startup, we introduce a new system service in <code>system.d<\/code>: Change to the directory <code>\/storage\/.config\/system.d<\/code> and add the following file:<\/p>\n<p><code>socat.service<\/code><\/p>\n<pre lang=\"ini\">\r\n[Unit]\r\nDescription=SocatTempServer\r\n\r\n[Service]\r\nType=simple\r\nExecStart=\/storage\/tempservice\/socat-service.sh\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\n<p>And enable the service:<\/p>\n<pre lang=\"bash\">\r\nsystemctl enable socat.service\r\n<\/pre>\n<p>Reboot and test from the other system in the LAN whether we can read the temperature:<\/p>\n<pre lang=\"bash\">\r\nnc PI-IP 9888 | tr -d '\\r'\r\n<\/pre>\n<p>Now all you have to do is include the result in a cacti script and show the result. \ud83d\ude42<\/p>\n<p>Here&#8217;s what it may look like:<br \/>\n<figure id=\"attachment_278\" aria-describedby=\"caption-attachment-278\" style=\"width: 581px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.anginf.de\/wp-content\/uploads\/pitemps.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.anginf.de\/wp-content\/uploads\/pitemps.png\" alt=\"An example for a cacti picture measuring raspberyy pi temperatures\" width=\"581\" height=\"266\" class=\"size-full wp-image-278\" srcset=\"https:\/\/www.anginf.de\/wp-content\/uploads\/pitemps.png 581w, https:\/\/www.anginf.de\/wp-content\/uploads\/pitemps-300x137.png 300w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/a><figcaption id=\"caption-attachment-278\" class=\"wp-caption-text\">An example for a cacti picture measuring raspberry pi temperatures<\/figcaption><\/figure><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m using a raspberry pi with XBMC as a mediaplayer. As I didn&#8217;t want to have a lot of trouble maintaining it, I decided to try OpenELEC. It works fine, but it&#8217;s really limited to only the media-related parts. I wanted to know how much the temperature changes when using my raspberry pi and I &hellip; <a href=\"https:\/\/www.anginf.de\/?p=267\" class=\"more-link\"><span class=\"screen-reader-text\">Monitor Raspberry Pi temperature from an external server<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,3,2],"tags":[],"class_list":["post-267","post","type-post","status-publish","format-standard","hentry","category-allgemein","category-cacti","category-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=267"}],"version-history":[{"count":12,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/267\/revisions"}],"predecessor-version":[{"id":417,"href":"https:\/\/www.anginf.de\/index.php?rest_route=\/wp\/v2\/posts\/267\/revisions\/417"}],"wp:attachment":[{"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anginf.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}