{"id":1177,"date":"2025-01-02T22:46:15","date_gmt":"2025-01-03T04:46:15","guid":{"rendered":"https:\/\/thecweb.com\/?p=1177"},"modified":"2025-01-02T22:46:57","modified_gmt":"2025-01-03T04:46:57","slug":"dht22-is-logging","status":"publish","type":"post","link":"https:\/\/thecweb.com\/index.php\/2025\/01\/02\/dht22-is-logging\/","title":{"rendered":"DHT22 is logging"},"content":{"rendered":"\n<p>For my indoor garden I wanted to monitor the temperature inside and outside the tent.  It is in the basement, which I don&#8217;t think ever gets above 70 or below 50, but to control the plant&#8217;s cycles I need to control light and temp.  The light came with an App so I just needed to get temp data into my database.  Here is the code I&#8217;m using at the moment.  I&#8217;d also like to log outside temperature data, but I haven&#8217;t figured that out yet.  I&#8217;m think there has got to be an API for the NWS that I can put in a zip code and get the temp and humidity.  Here is the code, and some notes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"400\" src=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/dht22-logo.png\" alt=\"\" class=\"wp-image-1185\" style=\"border-radius:43px\" srcset=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/dht22-logo.png 400w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/dht22-logo-300x300.png 300w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/dht22-logo-150x150.png 150w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/figure>\n\n\n\n<p>We need to get some libraries and connect to the sensors.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"501\" height=\"256\" src=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-1.png\" alt=\"\" class=\"wp-image-1178\" srcset=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-1.png 501w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-1-300x153.png 300w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/figure>\n\n\n\n<p>I have two functions.  One to get the data from the sensors, and one to insert the data into the database.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"701\" height=\"378\" src=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-2.png\" alt=\"\" class=\"wp-image-1179\" srcset=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-2.png 701w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-2-300x162.png 300w\" sizes=\"auto, (max-width: 701px) 100vw, 701px\" \/><figcaption class=\"wp-element-caption\">sensors<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"669\" height=\"432\" src=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-4.png\" alt=\"\" class=\"wp-image-1181\" srcset=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-4.png 669w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-4-300x194.png 300w\" sizes=\"auto, (max-width: 669px) 100vw, 669px\" \/><figcaption class=\"wp-element-caption\">insert data<\/figcaption><\/figure>\n\n\n\n<p>Where the magic happens<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"303\" height=\"57\" src=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-5.png\" alt=\"\" class=\"wp-image-1182\" srcset=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-5.png 303w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-5-300x56.png 300w\" sizes=\"auto, (max-width: 303px) 100vw, 303px\" \/><\/figure>\n\n\n\n<p>and some cleanup<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"551\" height=\"91\" src=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-6.png\" alt=\"\" class=\"wp-image-1183\" srcset=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-6.png 551w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-6-300x50.png 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/figure>\n\n\n\n<p>So I calculated the space needed by putting 10 readings in the db, and if the average holds(which it should only go down) I will use about 840 MB a year to get a reading every minute, which I don&#8217;t really think I would need, so I&#8217;ll probably lower it to once an hour maybe later.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"943\" height=\"152\" src=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-7.png\" alt=\"\" class=\"wp-image-1184\" srcset=\"https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-7.png 943w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-7-300x48.png 300w, https:\/\/thecweb.com\/wp-content\/uploads\/2025\/01\/image-7-768x124.png 768w\" sizes=\"auto, (max-width: 943px) 100vw, 943px\" \/><\/figure>\n\n\n\n<p>1638 average row size, in bytes(i think)<\/p>\n\n\n\n<p>so 1.6kb a reading.<\/p>\n\n\n\n<p>60 minutes * 24 hours * 1.6kb = 2,304kb a day<\/p>\n\n\n\n<p>2.3MB * 365 = 839.5MB a year<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For my indoor garden I wanted to monitor the temperature inside and outside the tent. It is in the basement, which I don&#8217;t think ever gets above 70 or below 50, but to control the plant&#8217;s cycles I need to control light and temp. The light came with an App so I just needed to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1185,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[14,49,48,50,45],"class_list":["post-1177","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-linux","tag-mariadb","tag-mysql","tag-pi","tag-python"],"_links":{"self":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=1177"}],"version-history":[{"count":1,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1177\/revisions"}],"predecessor-version":[{"id":1186,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/posts\/1177\/revisions\/1186"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/media\/1185"}],"wp:attachment":[{"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=1177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=1177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thecweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=1177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}