{"id":112,"date":"2017-05-10T21:02:24","date_gmt":"2017-05-10T19:02:24","guid":{"rendered":"https:\/\/dev.drun.net\/?p=112"},"modified":"2017-05-10T21:02:24","modified_gmt":"2017-05-10T19:02:24","slug":"reading-hc-12-from-rpi-and-sending-to-domoticz","status":"publish","type":"post","link":"https:\/\/dev.krasi.net\/?p=112","title":{"rendered":"Reading Data from HC-12 on Raspberry Pi and sending it to Domoticz"},"content":{"rendered":"<h4>Hardware.<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-124\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2017\/05\/DSCF5116-1024x683.jpg\" alt=\"\" width=\"960\" height=\"640\" \/><\/p>\n<p>Okay, to read data from HC-12 to the Raspberry PI is practically very easy :). All you need to do is hook it up and power from RPi.<\/p>\n<ul>\n<li>VIN \u2013 Connect to RPi\u00a05V (PIN 4)<\/li>\n<li>GND \u2013 Connect to RPi\u00a0GND (PIN 6)<\/li>\n<li>RX\u00a0\u2013 Connect to RPi GPIO14 (PIN 8, UART0_TXD)<\/li>\n<li>TX \u2013 Connect to RPi GPIO15 (PIN 10, UART0_RXD)<\/li>\n<\/ul>\n<p>I &#8220;stole&#8221; that image from Internet, so you can see which pins exactly are those that we need:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large\" src=\"https:\/\/i.stack.imgur.com\/sVvsB.jpg\" width=\"1000\" height=\"873\" \/><\/p>\n<h4>Software.<\/h4>\n<p>Simple Python script can be downloaded\u00a0<a href=\"https:\/\/dev.drun.net\/wp-content\/uploads\/2017\/05\/sensors_reader.py_.txt\">here<\/a>. It&#8217;s not that &#8220;pretty&#8221;, but I just learned python, lol :). The idea of the script is to read the HC-12 sensor&#8217;s values on the serial port as text lines, split them, and depending on some basic configuration, send the value to the dummy device in Domoticz, by it&#8217;s\u00a0<strong>idx<\/strong>. You need to add the dummy devices before that, in our case &#8211; One dummy device type temperature, it has idx 26 in our sample, and another one type lux, it has idx 27 in the example.<\/p>\n<p>You will need to make the script run at start, if you need persistency. For my test purposes I will not explain that right now. Btw, make sure you have python3, pip3, and wiringPi libraries installed, and also make sure the serial port at \/dev\/ttyS0 is activated and accessible ( you can configure\u00a0it in <em>raspi-config<\/em> -&gt;\u00a0Interfacing Options\u00a0-&gt; Serial ).<\/p>\n<p>After this, you can see the values being read to Domoticz.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-130\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2017\/05\/domoticz_temp.png\" alt=\"\" width=\"780\" height=\"250\" \/><\/p>\n<p>and<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-129\" src=\"https:\/\/dev.krasi.net\/wp-content\/uploads\/2017\/05\/domoticz_light.png\" alt=\"\" width=\"800\" height=\"256\" \/><\/p>\n<p>That&#8217;s it, very very simple \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hardware. Okay, to read data from HC-12 to the Raspberry PI is practically very easy :). All you need to do is hook it up and power from RPi. VIN \u2013 Connect to RPi\u00a05V (PIN 4) GND \u2013 Connect to RPi\u00a0GND (PIN 6) RX\u00a0\u2013 Connect to RPi GPIO14 (PIN 8, UART0_TXD) TX \u2013 Connect to RPi GPIO15 (PIN 10, UART0_RXD) I &#8220;stole&#8221; that image from Internet, so you can see which pins exactly are those that we need: Software. Simple Python script can be downloaded\u00a0here. It&#8217;s not that &#8220;pretty&#8221;, but I just learned python, lol :). The idea of the script is to read the HC-12 sensor&#8217;s values on the serial port as text lines, split them, and depending on some basic configuration, send the value to the dummy device in Domoticz, by it&#8217;s\u00a0idx. You need to add the dummy devices before that, in our case &#8211; One dummy device type temperature, it has idx 26 in our sample, and another one type lux, it has idx 27 in the example. You will need to make the script run at start, if you need persistency. For my test purposes I will not explain that right now. Btw, make sure you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":124,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hardware","category-software"],"_links":{"self":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=112"}],"version-history":[{"count":0,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.krasi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}