{"action":"opened","issue":{"url":"https://api.github.com/repos/spark/firmware/issues/1314","repository_url":"https://api.github.com/repos/spark/firmware","labels_url":"https://api.github.com/repos/spark/firmware/issues/1314/labels{/name}","comments_url":"https://api.github.com/repos/spark/firmware/issues/1314/comments","events_url":"https://api.github.com/repos/spark/firmware/issues/1314/events","html_url":"https://github.com/spark/firmware/issues/1314","id":224762829,"number":1314,"title":"Cellular.ready returns true after modem reset","user":{"login":"sstelian","id":17343698,"avatar_url":"https://avatars0.githubusercontent.com/u/17343698?v=3","gravatar_id":"","url":"https://api.github.com/users/sstelian","html_url":"https://github.com/sstelian","followers_url":"https://api.github.com/users/sstelian/followers","following_url":"https://api.github.com/users/sstelian/following{/other_user}","gists_url":"https://api.github.com/users/sstelian/gists{/gist_id}","starred_url":"https://api.github.com/users/sstelian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sstelian/subscriptions","organizations_url":"https://api.github.com/users/sstelian/orgs","repos_url":"https://api.github.com/users/sstelian/repos","events_url":"https://api.github.com/users/sstelian/events{/privacy}","received_events_url":"https://api.github.com/users/sstelian/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-04-27T12:08:55Z","updated_at":"2017-04-27T12:08:55Z","closed_at":null,"body":"<details>\r\n  <summary><i>Summary</i></summary>\r\n  Cellular.ready() returns true immediately after calling Cellular.off, Cellular.on and Cellular.connect regardless of the actual state of the modem. A delay of 500 ms between Cellular.connect and Celluar.ready causes the function to return the correct value.\r\n</details>\r\n\r\n\r\n</details>\r\n\r\n## Bug Report\r\nIn my project I need to recover from Cellular connection faults without resetting the microcontroller, but after resetting the modem the board would not reconnect. I was using the Electron with MQTT without connecting it to the cloud. The attempt to reconnect to the MQTT broker failed due to the system not waiting for the modem and TCP stack to initialize. With some help from @ScruffR , I found that Cellular.ready returns true immediately after calling Celluar.off, Cellular.on and Cellular.connect, which is wrong because it caused the waitFor instruction to skip. As suggested by @ScruffR , I added a delay between Cellular.connect and waitFor and this fixed the issue. I still consider this counts as a bug in the Cellular class.\r\n@ScruffR  also filed an issue that may be related to this bug : \r\nhttps://github.com/spark/firmware/issues/1028\r\n\r\n\r\n\r\n### Expected Behavior\r\n\r\nWhat should it do?\r\nThe Cellular.ready function should return the correct value immediately after calling Cellular.connect. I expect this value to be false for a few seconds, until the modem connects.\r\n\r\n### Observed Behavior\r\n\r\nWhat did it actually do?\r\nThe Cellular.ready function returns true with the modem uninitialized.\r\n### Steps to Reproduce\r\n\r\nHow did you make it do that, and which system/user firmware versions were tested?\r\n\r\n### Test App\r\n\r\n```c\r\nSYSTEM_THREAD(ENABLED);\r\nSYSTEM_MODE(MANUAL);\r\n\r\n//setup for third party SIM card\r\n#include \"cellular_hal.h\"\r\nSTARTUP(cellular_credentials_set(\"net\", \"\", \"\", NULL));\r\n\r\n//uncomment to cause the correct behaviour\r\n//#define APPLY_FIX\r\n\r\nvoid setup()\r\n{\r\n  Serial.begin(115200);\r\n  Serial.println(\"Test started.\");\r\n}\r\n\r\nvoid loop()\r\n{\r\n    Serial.println(\"Connecting...\");\r\n    unsigned long initialTime = millis();\r\n    Cellular.connect();\r\n\r\n    #ifdef APPLY_FIX\r\n      delay(500);\r\n    #endif\r\n\r\n    if (!waitFor(Cellular.ready, 60000))\r\n    {\r\n        Serial.println(\"Connection attempt timeout.\");\r\n    }\r\n    Serial.print(\"Connected in \");\r\n    Serial.print((millis () - initialTime) / 1000);\r\n    Serial.println(\" seconds\");\r\n    Serial.println(\"Turning Cellular off.\");\r\n    Cellular.off();\r\n    Serial.println(\"Turning Cellular on.\");\r\n    Cellular.on();\r\n}\r\n\r\n```\r\n\r\n### References\r\n\r\nLinks to the Community, Docs, Other Issues, etc..\r\nHere's the related topic : https://community.particle.io/t/how-to-handle-cellular-connection-loss-on-electron/31925/10\r\n---\r\n\r\n## Feature/Enhancement Request\r\n\r\nPlease investigate this problem. I expect it to either be fixed in the upcoming firmware version, or mentioned in the documentation in case it's my fault for not using the Cellular class properly."}}
{"actor":{"display_login":"sstelian"}}