{"id":830,"date":"2021-04-27T20:18:29","date_gmt":"2021-04-27T18:18:29","guid":{"rendered":"https:\/\/outpost.garf.de\/wordpress\/?p=830"},"modified":"2021-04-27T20:42:48","modified_gmt":"2021-04-27T18:42:48","slug":"outdoor-solar-powered-weather-station-part-3","status":"publish","type":"post","link":"https:\/\/outpost.garf.de\/wordpress\/index.php\/2021\/04\/27\/outdoor-solar-powered-weather-station-part-3\/","title":{"rendered":"Outdoor solar powered weather station \u2013 part 3"},"content":{"rendered":"<h2 class=\"wp-block-heading\">I have a bug!<\/h2>\n\n\n\n<p>Four days ago the microcontroller got stuck. The LED was on, but it was no longer transmitting. So I hit reset and continued testing. One of the things I added was a watchdog trigger. The CubeCell board has a build in <a href=\"https:\/\/github.com\/HelTecAutomation\/CubeCell-Arduino\/tree\/master\/libraries\/LoRa\/examples\/LoRaWAN\/LoRaWan_watchDog\">watchdog<\/a> &#8211; and the only thing you need to do is switch it on &#8211; how cool is that?<\/p>\n\n\n\n<p>I did not think back to the problem until today suddenly the board rebooted. I noticed because the LED I configured to drain the battery was off &#8211; the default after reboot. Looking at the number of messages it sent, I noticed it always rebooted after 165 or 164 messages. This is to much of a coincidence to be random. Even if you are not a seasoned developer (reminder: I am a network engineer, not a software developer) this smells like a memory leak. The <a href=\"https:\/\/heltec.org\/project\/htcc-ab01\/\">CubeCell has only 16kb of RAM<\/a> and that fills up quickly if you are not careful. <\/p>\n\n\n\n<p>But my code does never allocate memory! So I checked when these reboots first occurred and, as I use git to version my code, I found out it started after adding a library to query the <a href=\"https:\/\/www.adafruit.com\/product\/1085\">ADS1115 A\/D converter<\/a>. As the CubeCell goes into deep sleep so often and powers down the sensors I simply re-initialized the sensors every time it woke up. Checking the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_ADS1X15\">ADS1115 library<\/a> I was using I found the <a href=\"https:\/\/github.com\/adafruit\/Adafruit_ADS1X15\/blob\/master\/Adafruit_ADS1X15.cpp\">follwing code<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void Adafruit_ADS1X15::begin(uint8_t i2c_addr, TwoWire *wire) {\n  m_i2c_dev = new Adafruit_I2CDevice(i2c_addr, wire);\n  m_i2c_dev-&gt;begin();\n}<\/code><\/pre>\n\n\n\n<p>So that means each time I call the begin() function a memory object is allocated. And after 165 times free memory is gone. I made sure begin() was only called once (I was a bit concerned about the deep sleep) and it now works fine.<\/p>","protected":false},"excerpt":{"rendered":"<p>I have a bug! Four days ago the microcontroller got stuck. The LED was on, but it was no longer transmitting. So I hit reset and continued testing. One of the things I added was a watchdog trigger. The CubeCell board has a build in watchdog &#8211; and the only thing you need to do [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":833,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"footnotes":""},"categories":[113],"tags":[],"class_list":["post-830","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microcontrollers"],"_links":{"self":[{"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/830","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=830"}],"version-history":[{"count":4,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/830\/revisions"}],"predecessor-version":[{"id":835,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/830\/revisions\/835"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/media\/833"}],"wp:attachment":[{"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/outpost.garf.de\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}