{"id":130,"date":"2015-01-12T08:10:01","date_gmt":"2015-01-12T08:10:01","guid":{"rendered":"http:\/\/parablog-wordpress.dockerbox.rei.moe\/?p=130"},"modified":"2015-01-12T08:15:44","modified_gmt":"2015-01-12T08:15:44","slug":"easyiot-ds18b20-temperature-sensor-esp8266","status":"publish","type":"post","link":"https:\/\/blog.lewys.eu\/?p=130","title":{"rendered":"EasyIoT DS18B20 Temperature Sensor &#8211; ESP8266"},"content":{"rendered":"<p>I needed a temperature node, but I didn&#8217;t have a DHT22 temp\/humidity sensor!?<\/p>\n<p>So I modified the example sketch for the DHT to use a DS18B20 Digital Temperature Sensor instead!<\/p>\n<p>It works great!<\/p>\n<p>The sensor is connected as shown here:<\/p>\n<p>http:\/\/www.hobbytronics.co.uk\/ds18b20-arduino<\/p>\n<p>Heres the code:<\/p>\n<p>&nbsp;<\/p>\n<p>\/*<\/p>\n<p>DS18B20 Digital Sensor Node Sketch for EasyIoT Server<br \/>\nModified by Lewys Martin &lt;l@lewys.eu&gt;<br \/>\nSee: blog.lewys.eu for details<\/p>\n<p>Original Code:<br \/>\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<\/p>\n<p>V1.0 &#8211; first version<\/p>\n<p>Created by Igor Jarc &lt;igor.jarc1@gmail.com&gt;<br \/>\nSee http:\/\/iot-playground.com for details<br \/>\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<\/p>\n<p>This program is free software; you can redistribute it and\/or<br \/>\nmodify it under the terms of the GNU General Public License<br \/>\nversion 2 as published by the Free Software Foundation.<br \/>\n*\/<br \/>\n#include &lt;Esp8266EasyIoT.h&gt;<br \/>\n#include &lt;SoftwareSerial.h&gt;<br \/>\n#include &lt;DallasTemperature.h&gt;<br \/>\n#include &lt;OneWire.h&gt;<\/p>\n<p>#define CHILD_ID_TEMP 1<br \/>\n#define SENSOR_DIGITAL_PIN 2<br \/>\nEsp8266EasyIoT esp;<\/p>\n<p>SoftwareSerial serialEsp(10, 11);<\/p>\n<p>OneWire oneWire(SENSOR_DIGITAL_PIN);<br \/>\nDallasTemperature sensors(&amp;oneWire);<\/p>\n<p>float lastTemp;<\/p>\n<p>Esp8266EasyIoTMsg msgTemp(CHILD_ID_TEMP, V_TEMP);<br \/>\nvoid setup()<br \/>\n{<br \/>\nserialEsp.begin(9600);<br \/>\nSerial.begin(115200);<\/p>\n<p>Serial.println(&#8220;EasyIoTEsp init&#8221;);<br \/>\nesp.begin(NULL, 3, &amp;serialEsp, &amp;Serial);<br \/>\n\/\/esp.begin(NULL, &amp;serialEsp);<br \/>\nesp.present(CHILD_ID_TEMP, S_TEMP);<\/p>\n<p>sensors.begin();<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\nwhile(!esp.process());<\/p>\n<p>sensors.requestTemperatures();<br \/>\nfloat temperature = (sensors.getTempCByIndex(0));<br \/>\nif (isnan(temperature)) {<br \/>\nSerial.println(&#8220;Failed reading temperature from sensor&#8221;);<br \/>\n}<br \/>\nelse if (temperature != lastTemp)<br \/>\n{<br \/>\nlastTemp = temperature;<br \/>\nesp.send(msgTemp.set(temperature, 1));<br \/>\nSerial.print(&#8220;T: &#8220;);<br \/>\nSerial.println(temperature);<br \/>\n}<br \/>\n}<\/p>\n<p>And some pictures:<br \/>\n<a href=\"http:\/\/172.16.0.6:8683\/wp-content\/uploads\/2015\/01\/wpid-wp-1421050417164.png\"><img decoding=\"async\" title=\"wp-1421050417164\" class=\"alignnone size-full\"  alt=\"image\" src=\"http:\/\/172.16.0.6:8683\/wp-content\/uploads\/2015\/01\/wpid-wp-1421050417164.png\" \/><\/a> <\/p>\n<p><a href=\"http:\/\/172.16.0.6:8683\/wp-content\/uploads\/2015\/01\/wpid-wp-1421050422905.jpeg\"><img decoding=\"async\" title=\"wp-1421050422905\" class=\"alignnone size-full\"  alt=\"image\" src=\"http:\/\/172.16.0.6:8683\/wp-content\/uploads\/2015\/01\/wpid-wp-1421050422905.jpeg\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I needed a temperature node, but I didn&#8217;t have a DHT22 temp\/humidity sensor!? So I modified the example sketch for the DHT to use a DS18B20 Digital Temperature Sensor instead! It works great! The sensor is connected as shown here: http:\/\/www.hobbytronics.co.uk\/ds18b20-arduino Heres the code: &nbsp; \/* DS18B20 Digital Sensor Node Sketch for EasyIoT Server Modified &hellip; <a href=\"https:\/\/blog.lewys.eu\/?p=130\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">EasyIoT DS18B20 Temperature Sensor &#8211; ESP8266<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,23,19,18],"tags":[],"class_list":["post-130","post","type-post","status-publish","format-standard","hentry","category-arduino-2","category-esp8266","category-home-automation-2","category-projects"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=130"}],"version-history":[{"count":2,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":134,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions\/134"}],"wp:attachment":[{"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lewys.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}