{"id":1191,"date":"2014-04-08T10:11:17","date_gmt":"2014-04-08T17:11:17","guid":{"rendered":"https:\/\/logicalelegance.com\/journey\/?p=1191"},"modified":"2014-04-08T10:11:17","modified_gmt":"2014-04-08T17:11:17","slug":"i-need-to-sleep-but-cant","status":"publish","type":"post","link":"https:\/\/logicalelegance.com\/journey\/2014\/04\/i-need-to-sleep-but-cant\/","title":{"rendered":"I need to sleep but can&#8217;t"},"content":{"rendered":"<p>In my ayok widget, I have a battery. To make it last, I want the high power things to sleep as much as possible.<\/p>\n<p>The Electric Imp is the largest power consumer, followed by the accelerometer, and then the battery-monitoring fuel gauge.<\/p>\n<p>Happily, the Imp has a low power mode. When I say imp.sleep(5.0) to sleep for five seconds, in low power mode. Though it isn&#8217;t a very low power mode, for one thing, the WiFi remains powered up.<\/p>\n<p>They offer another mode, a deeper sleep more: imp.deepsleepfor().\u00a0In deep sleep, it consumes only 6uA (which is a tiny amount if you are a cell phone and a medium-to-large amount if you are a wearable device).<\/p>\n<p>Foolish me, I thought I could replace my imp.sleep calls with imp.deepsleepfor calls, do a little bit of tweaking (i.e. tell the server I&#8217;m going to sleep), and it would work.<\/p>\n<p>Suddenly my system kept crashing.<\/p>\n<p>I feel like that represents my often-rocky interactions with Electric Imp. I still think it is a good platform for hobbyists but it is often deeply frustrating. When I first started working with (playing with?) the Imp, I wrote an in-depth review\/rant detailing its shortcomings. I opted not to post it here, instead sending it to the Imp folks in hopes my time and frustration could help them make a better product. Some of those things have gotten better in the intervening six months but many things got worse. Let&#8217;s just say I wouldn&#8217;t dream of using it in a product and if things continue to be bad, well, there are other options for home hobbyists.<\/p>\n<p>Anyway, back to my crashing system.<\/p>\n<p>It turns out that sleep() returns to where it was but deepsleepfor() restarts execution. This is clear in their examples (but not documented in the text). There is a work-around: if the non-volatile RAM is configured, then the system has been booted before. If it has not, then this is a cold-start so I should configure the accelerometer. (I very sincerely hope that &#8220;reprogram the code&#8221; is considered a cold-start and erases the nv space.)<\/p>\n<p>As a developer, I understand why this happens this way, my annoyance is primarily because I feel like they hid it from me. No, they probably didn&#8217;t. But yes, their documentation should be better.<\/p>\n<p>I did fix the crashing (and not through their nv hack, instead they have a function that can tell me what the reason for the wake up is:\u00a0hardware.wakereason(). Yes, I did implement the nv hack before finding that.<\/p>\n<p>Now, my Imp isn&#8217;t crashing any more. I made some tweaks, trying to get rid of the slightly alarming note in the logs:<\/p>\n<p>[Status]\u00a0Device disconnected; 585 bytes sent, 0 received, 585 total<\/p>\n<p><a href=\"https:\/\/logicalelegance.com\/journey\/wp-content\/uploads\/2014\/04\/CaptureStatus.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1196\" alt=\"CaptureStatus\" src=\"https:\/\/logicalelegance.com\/journey\/wp-content\/uploads\/2014\/04\/CaptureStatus.jpg\" width=\"683\" height=\"46\" srcset=\"https:\/\/logicalelegance.com\/journey\/wp-content\/uploads\/2014\/04\/CaptureStatus.jpg 683w, https:\/\/logicalelegance.com\/journey\/wp-content\/uploads\/2014\/04\/CaptureStatus-300x20.jpg 300w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><\/a><\/p>\n<p>I couldn&#8217;t find anything about that in their documentation. But it is worrisome so I tried to remove it. My efforts led to my card not updating and the system not running at all. The error I got was unsatisfying.<\/p>\n<p><a href=\"https:\/\/logicalelegance.com\/journey\/wp-content\/uploads\/2014\/04\/CaptureHippos.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1200\" alt=\"CaptureHippos\" src=\"https:\/\/logicalelegance.com\/journey\/wp-content\/uploads\/2014\/04\/CaptureHippos.png\" width=\"590\" height=\"124\" srcset=\"https:\/\/logicalelegance.com\/journey\/wp-content\/uploads\/2014\/04\/CaptureHippos.png 590w, https:\/\/logicalelegance.com\/journey\/wp-content\/uploads\/2014\/04\/CaptureHippos-300x63.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p>I fiddled with it for a few minutes, updated this post. My device finally came back. But I think I&#8217;ve reached maximum annoyance level for the day. (If I&#8217;m going to be this frustrated, I want to get paid for it.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my ayok widget, I have a battery. To make it last, I want the high power things to sleep as much as possible. The Electric Imp is the largest power consumer, followed by the accelerometer, and then the battery-monitoring fuel gauge. Happily, the Imp has a low power mode. When I say imp.sleep(5.0) to [&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,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[52,37],"class_list":["post-1191","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ayok","tag-rant"],"_links":{"self":[{"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/posts\/1191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/comments?post=1191"}],"version-history":[{"count":7,"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/posts\/1191\/revisions"}],"predecessor-version":[{"id":1201,"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/posts\/1191\/revisions\/1201"}],"wp:attachment":[{"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/media?parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/categories?post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/logicalelegance.com\/journey\/wp-json\/wp\/v2\/tags?post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}