{"action":"created","issue":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1481","repository_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware","labels_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1481/labels{/name}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1481/comments","events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1481/events","html_url":"https://github.com/nodemcu/nodemcu-firmware/issues/1481","id":173670351,"number":1481,"title":"crash after calling wifi.setmode(wifi.NULLMODE)","user":{"login":"joysfera","id":2862144,"avatar_url":"https://avatars.githubusercontent.com/u/2862144?v=3","gravatar_id":"","url":"https://api.github.com/users/joysfera","html_url":"https://github.com/joysfera","followers_url":"https://api.github.com/users/joysfera/followers","following_url":"https://api.github.com/users/joysfera/following{/other_user}","gists_url":"https://api.github.com/users/joysfera/gists{/gist_id}","starred_url":"https://api.github.com/users/joysfera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joysfera/subscriptions","organizations_url":"https://api.github.com/users/joysfera/orgs","repos_url":"https://api.github.com/users/joysfera/repos","events_url":"https://api.github.com/users/joysfera/events{/privacy}","received_events_url":"https://api.github.com/users/joysfera/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-08-28T21:56:38Z","updated_at":"2016-08-29T06:38:57Z","closed_at":null,"body":"I think I'm experiencing a crash inside of NodeMCU firmware after calling ```wifi.setmode(wifi.NULLMODE)``` - this happens only when called after wake up from ```rtctime.dsleep(xxx, 4)```. I am not 100% sure that I managed to isolate the case properly (I'm editing a larger source code) but it seems so.\r\n\r\n### Expected behavior\r\nno crash\r\n\r\n### Actual behavior\r\ncrash and a reboot: (please see the unedited serial console output below)\r\n\r\n```\r\nStarting\r\nbootreason: 2, 6\r\nWaking up from sleep\r\nCalling wifi.setmode(wifi.NULLMODE)\r\n> \r\n ets Jan  8 2013,rst cause:2, boot mode:(3,2)\r\n\r\nload 0x40100000, len 24368, room 16 \r\ntail 0\r\nchksum 0xc3\r\nload 0x3ffe8000, len 2324, room 8 \r\ntail 12\r\nchksum 0xd6\r\nho 0 tail 12 room 4\r\nload 0x3ffe8914, len 8, room 12 \r\ntail 8\r\nchksum 0x42\r\ncsum 0x42\r\n��\u0002�\u001B�n��{��o|�\u0004�d�p{l��{�d�l\u001B�\r\n                               \u0004�d`�\r\n\r\nNodeMCU custom build by frightanic.com\r\n\tbranch: dev\r\n\tcommit: 3328c66f2c1c4b83f96b3c869b2167bb2ab183a2\r\n\tSSL: false\r\n\tmodules: adc,bit,file,gpio,http,i2c,net,node,rtctime,sntp,spi,tmr,u8g,uart,wifi\r\n build \tbuilt on: 2016-08-28 14:34\r\n powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)\r\n>\r\nStarting\r\nbootreason: 2, 2\r\n```\r\n### Test code\r\n```Lua\r\nprint(\"Starting\")\r\nlocal boot_reason, reset_cause = node.bootreason()\r\nlocal wakeup = false\r\nprint(\"bootreason: \" .. boot_reason .. \", \" .. reset_cause)\r\nif reset_cause == 5 or reset_cause == 6 then wakeup = true end\r\nif wakeup then print(\"Waking up from sleep\") end\r\n--\r\nif not wakeup then\r\n    wifi.setmode(wifi.STATION)\r\n    wifi.sta.config(\"X\",\"Y\")\r\n    sntp.sync(\"tak.cesnet.cz\")\r\nelse\r\n    print(\"Calling wifi.setmode(wifi.NULLMODE)\")\r\n    wifi.setmode(wifi.NULLMODE)\r\nend\r\n```\r\n\r\nand then type in the Lua console:\r\n```\r\nrtctime.dsleep(1000000, 4)\r\n```\r\n\r\nWhat should happen is that the device goes to sleep immediately, wakes up in a second, the Lua code recognizes that it's being waked up, sets the ```wakeup``` to ```true``` and then just sets the NULLMODE and that's it - you should end up in a command prompt (because there are no more Lua commands). \r\n\r\nWhat actually happens is that the device goes to sleep, wakes up but then reboots again after (or during?) processing the ```setmode()``` call, prints the usual garbage on the serial line (see above in the console output) and as you can notice this time it's (re)booted with a different bootreason \"2, 2\" - an exception reset. I believe there's been an exception inside the firmware code but I don't know how to find out more (without modifying the firmware code and building some kind of a debug version).\r\n\r\nPlease note that this issue is caused by trying to find a work-around for #1472. When the ESP wakes up with modem turned off (like the ```option``` parameter's value ```4``` suggests) then there'll be no need to call ```wifi.setmode(wifi.NULLMODE)``` and this issue will kind of disappear (or at least becomes far smaller).\r\n\r\n### NodeMCU version\r\nbranch: dev\r\n\tcommit: 3328c66f2c1c4b83f96b3c869b2167bb2ab183a2\r\n\r\n### Hardware\r\nplain ESP8266 with GPIO16 wired to RST"},"comment":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/comments/243043608","html_url":"https://github.com/nodemcu/nodemcu-firmware/issues/1481#issuecomment-243043608","issue_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1481","id":243043608,"user":{"login":"joysfera","id":2862144,"avatar_url":"https://avatars.githubusercontent.com/u/2862144?v=3","gravatar_id":"","url":"https://api.github.com/users/joysfera","html_url":"https://github.com/joysfera","followers_url":"https://api.github.com/users/joysfera/followers","following_url":"https://api.github.com/users/joysfera/following{/other_user}","gists_url":"https://api.github.com/users/joysfera/gists{/gist_id}","starred_url":"https://api.github.com/users/joysfera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joysfera/subscriptions","organizations_url":"https://api.github.com/users/joysfera/orgs","repos_url":"https://api.github.com/users/joysfera/repos","events_url":"https://api.github.com/users/joysfera/events{/privacy}","received_events_url":"https://api.github.com/users/joysfera/received_events","type":"User","site_admin":false},"created_at":"2016-08-29T06:38:57Z","updated_at":"2016-08-29T06:38:57Z","body":"Before I try that I'd like to mention that there seems to be some sort of timing issue because when I call the ```wifi.setmode(wifi.NULLMODE)``` manually few seconds later afer waking up it seems to work fine.\r\n\r\nAnd a real work-around for this issue is to simply disable the WiFi modem before falling to dsleep - that way I don't have to set it after waking up."}}
{"actor":{"display_login":"joysfera"}}