{"id":273,"date":"2021-12-07T18:17:01","date_gmt":"2021-12-07T22:17:01","guid":{"rendered":"http:\/\/www.functionalprototype.com\/news\/?p=273"},"modified":"2022-09-06T17:57:58","modified_gmt":"2022-09-06T21:57:58","slug":"self-configuring-sensors-self-configure-and-thats-a-problem","status":"publish","type":"post","link":"https:\/\/www.functionalprototype.com\/news\/2021\/12\/07\/self-configuring-sensors-self-configure-and-thats-a-problem\/","title":{"rendered":"Self-configuring sensors self-configure, and that&#8217;s a problem"},"content":{"rendered":"<p>Little backstory on the sensorBox project.\u00a0 Things were going well until early in the Summer when the sensors threw out what I&#8217;d call garbage data.\u00a0 CO2 levels so high I should have headaches on a day whet the windows were all open is when I thought, &#8220;maybe I&#8217;m getting exactly what I&#8217;m paying for: sensors where the low price reflects that are disposable\/replaceable&#8221;.<\/p>\n<p>I worked on some other projects, did a little more research, and learned something about the CCS811, not well documented, if at all:<\/p>\n<p>It <em>continually<\/em> self-configures.<\/p>\n<p>The docs are pretty spare, but it&#8217;s clear that you calibrate by reading the baseline in a stable, normal CO2 environment; store it somewhere permanent; then use that value to set the baseline when you launch your code.\u00a0 That works pretty good when you&#8217;re launching the code at least once a day or several times a week &#8212; you&#8217;re repeatedly resetting the baseline.<\/p>\n<p>What if you let it run for weeks without resetting?\u00a0 It can reset the baseline in an high CO2 environment and now all the readings are off.<\/p>\n<p>Here&#8217;s how I started figuring things out &#8212; I started doing a get_baseline() every hour and logging it in the events file.\u00a0 Here&#8217;s the event log for one night when I baked a potato in a gas oven using my sensorBox in the kitchen.\u00a0 Entries starting with a comment (&#8220;#&#8221;) are automatic, the rest I did using the log-entry.py tool.\u00a0 The baseline is clearly wandering in a kitchen where I&#8217;m not doing anything, then gets worse when I start using my gas oven in convection mode.<\/p>\n<blockquote><p>$ more kitchen-events-2021-11-12.log<br \/>\n#boot time 2021-10-31 14:25:09<br \/>\n#description of event<br \/>\n1636693203,#baseline at day rollover 48713<br \/>\n1636693203,#baseline 60 min read 48713<br \/>\n1636696812,#baseline 60 min read 48713<br \/>\n1636700421,#baseline 60 min read 48713<br \/>\n1636704031,#baseline 60 min read 48713<br \/>\n1636707640,#baseline 60 min read 48713<br \/>\n1636711250,#baseline 60 min read 48713<br \/>\n1636714859,#baseline 60 min read 48713<br \/>\n1636718408,#baseline 60 min read 48691<br \/>\n1636722017,#baseline 60 min read 48670<br \/>\n1636725627,#baseline 60 min read 48670<br \/>\n1636729236,#baseline 60 min read 48670<br \/>\n1636732845,#baseline 60 min read 48655<br \/>\n1636736455,#baseline 60 min read 48655<br \/>\n1636740004,#baseline 60 min read 48655<br \/>\n1636743613,#baseline 60 min read 48630<br \/>\n1636747223,#baseline 60 min read 48572<br \/>\n1636750831,#baseline 60 min read 48572<br \/>\n1636754438,#baseline 60 min read 48572<br \/>\n1636758046,#baseline 60 min read 48572<br \/>\n1636761654,#baseline 60 min read 48572<br \/>\n1636763990,set oven to 350F<br \/>\n1636764253,turned on kitchen exhaust fan<br \/>\n1636764904,oven to 350 convection<br \/>\n1636765162,added potato<br \/>\n1636765201,#baseline 60 min read 48531<br \/>\n1636768811,#baseline 60 min read 48416<br \/>\n1636769479,remove potato from oven, turn off oven<br \/>\n1636772420,#baseline 60 min read 48416<br \/>\n1636772792,CO2 and tVOC aren&#8217;t dropping, forcing a restart<br \/>\n1636772797,sensor-box.py started at 2021-11-12 22:06:37.084918<br \/>\n#boot time 2021-10-31 14:25:09<br \/>\n#description of event<br \/>\n1636772798,#baseline at day rollover 48713<br \/>\n1636772985,turned off exhaust fan<br \/>\n1636776046,#baseline 60 min read 48717<\/p><\/blockquote>\n<p>Here&#8217;s a simple graph, you can see at the end where things go wonky as the self-configured baseline self-configures in a high CO2 environment:<\/p>\n<p><a href=\"http:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211112.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-274\" src=\"http:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211112-150x150.jpg\" alt=\"kitchen log with sensor errors\" width=\"150\" height=\"150\" srcset=\"https:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211112-150x150.jpg 150w, https:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211112-100x100.jpg 100w, https:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211112-50x50.jpg 50w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<p>It took some iterations and checking the baseline and it turns out it&#8217;s best to reset it every <em>ten<\/em> minutes.<\/p>\n<p>Here&#8217;s me baking another potato but resetting it every ten minutes:<\/p>\n<p><a href=\"http:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211206.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-thumbnail wp-image-275\" src=\"http:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211206-150x150.jpg\" alt=\"kitchen log with baseline fix\" width=\"150\" height=\"150\" srcset=\"https:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211206-150x150.jpg 150w, https:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211206-100x100.jpg 100w, https:\/\/www.functionalprototype.com\/news\/wp-content\/uploads\/2021\/12\/kitchen-20211206-50x50.jpg 50w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/p>\n<p>Here&#8217;s a clip from the event log with debug logging and how often the baseline changes while I&#8217;m using the oven.\u00c2\u00a0 It changes once while the oven is preheating, then nine more times while the potato is baking.\u00c2\u00a0 Each of those times is a self-calibration *changing* the baseline.\u00c2\u00a0 Since I can only read the sensors once a minute, resetting every ten minutes seems like a decent adjustment.<\/p>\n<blockquote><p>1638830503,set oven to 350F convection<br \/>\n1638831035,#baseline 10 min read 48635<br \/>\n1638831035,#baseline 48635 does not match baseValue 48713, resetting<br \/>\n1638831132,put potato in oven<br \/>\n1638831637,#baseline 10 min read 48654<br \/>\n1638831637,#baseline 48654 does not match baseValue 48713, resetting<br \/>\n1638832238,#baseline 10 min read 48452<br \/>\n1638832238,#baseline 48452 does not match baseValue 48713, resetting<br \/>\n1638832840,#baseline 10 min read 48324<br \/>\n1638832840,#baseline 48324 does not match baseValue 48713, resetting<br \/>\n1638833441,#baseline 10 min read 48226<br \/>\n1638833441,#baseline 48226 does not match baseValue 48713, resetting<br \/>\n1638834042,#baseline 10 min read 48168<br \/>\n1638834042,#baseline 48168 does not match baseValue 48713, resetting<br \/>\n1638834644,#baseline 10 min read 48093<br \/>\n1638834644,#baseline 48093 does not match baseValue 48713, resetting<br \/>\n1638835246,#baseline 10 min read 48072<br \/>\n1638835246,#baseline 48072 does not match baseValue 48713, resetting<br \/>\n1638835623,turned on exhaust fan in kitchen<br \/>\n1638835686,opened oven to check potato temp<br \/>\n1638835847,#baseline 10 min read 48062<br \/>\n1638835847,#baseline 48062 does not match baseValue 48713, resetting<br \/>\n1638836142,opened oven to check potato temp<br \/>\n1638836449,#baseline 10 min read 48098<br \/>\n1638836449,#baseline 48098 does not match baseValue 48713, resetting<br \/>\n1638836509,opened oven to check potato temp<br \/>\n1638836556,0ven off<br \/>\n1638836565,took potato out of oven<br \/>\n1638837050,#baseline 10 min read 48260<br \/>\n1638837050,#baseline 48260 does not match baseValue 48713, resetting<br \/>\n1638837651,#baseline 10 min read 48713<br \/>\n1638838253,#baseline 10 min read 48713<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Little backstory on the sensorBox project.\u00a0 Things were going well until early in the Summer when the sensors threw out what I&#8217;d call garbage data.\u00a0 CO2 levels so high I should have headaches on a day whet the windows were all open is when I thought, &#8220;maybe I&#8217;m getting exactly what I&#8217;m paying for: sensors [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[21,34],"tags":[42,43,45,44],"class_list":["post-273","post","type-post","status-publish","format-standard","hentry","category-design","category-environmental","tag-ccs811","tag-co2","tag-sensors","tag-tvoc"],"_links":{"self":[{"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/posts\/273"}],"collection":[{"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":0,"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/posts\/273\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/media?parent=273"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/categories?post=273"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.functionalprototype.com\/news\/wp-json\/wp\/v2\/tags?post=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}