{"action":"created","issue":{"url":"https://api.github.com/repos/spark/firmware/issues/509","labels_url":"https://api.github.com/repos/spark/firmware/issues/509/labels{/name}","comments_url":"https://api.github.com/repos/spark/firmware/issues/509/comments","events_url":"https://api.github.com/repos/spark/firmware/issues/509/events","html_url":"https://github.com/spark/firmware/issues/509","id":97610981,"number":509,"title":"Spark.process() blocks for extended periods of time, contrary to documentation","user":{"login":"airbornemint","id":1645207,"avatar_url":"https://avatars.githubusercontent.com/u/1645207?v=3","gravatar_id":"","url":"https://api.github.com/users/airbornemint","html_url":"https://github.com/airbornemint","followers_url":"https://api.github.com/users/airbornemint/followers","following_url":"https://api.github.com/users/airbornemint/following{/other_user}","gists_url":"https://api.github.com/users/airbornemint/gists{/gist_id}","starred_url":"https://api.github.com/users/airbornemint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/airbornemint/subscriptions","organizations_url":"https://api.github.com/users/airbornemint/orgs","repos_url":"https://api.github.com/users/airbornemint/repos","events_url":"https://api.github.com/users/airbornemint/events{/privacy}","received_events_url":"https://api.github.com/users/airbornemint/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/spark/firmware/milestones/11","html_url":"https://github.com/spark/firmware/milestones/0.4.6","labels_url":"https://api.github.com/repos/spark/firmware/milestones/11/labels","id":1268393,"number":11,"title":"0.4.6","description":"","creator":{"login":"m-mcgowan","id":2465470,"avatar_url":"https://avatars.githubusercontent.com/u/2465470?v=3","gravatar_id":"","url":"https://api.github.com/users/m-mcgowan","html_url":"https://github.com/m-mcgowan","followers_url":"https://api.github.com/users/m-mcgowan/followers","following_url":"https://api.github.com/users/m-mcgowan/following{/other_user}","gists_url":"https://api.github.com/users/m-mcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/m-mcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-mcgowan/subscriptions","organizations_url":"https://api.github.com/users/m-mcgowan/orgs","repos_url":"https://api.github.com/users/m-mcgowan/repos","events_url":"https://api.github.com/users/m-mcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/m-mcgowan/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":30,"state":"open","created_at":"2015-08-23T22:45:17Z","updated_at":"2015-09-30T07:25:35Z","due_on":"2015-09-28T22:00:00Z","closed_at":null},"comments":6,"created_at":"2015-07-28T04:16:32Z","updated_at":"2015-09-30T07:25:35Z","closed_at":"2015-09-30T07:25:35Z","body":"I am trying to write an app for my Photon with a responsive touch interface. I was under the impression (based on the documentation for Spark.connect and Spark.process) that Spark.process was a lightweight call and could safely be called in what, for me, is the inner loop of my UI code. \r\n\r\nUnfortunately, I am discovering that Spark.process is, in some circumstances, taking a long time to return, which results in UI stutter, My UI refresh/sampling rate falls well below 10 Hz due to the delays in Spark.process.. This is undesirable.\r\n\r\nI narrowed this down to the following test code:\r\n\r\n    SYSTEM_MODE(SEMI_AUTOMATIC);\r\n    \r\n    void setup() {\r\n        pinMode(D7, OUTPUT);\r\n        digitalWrite(D7, LOW);\r\n        Spark.connect();\r\n    }\r\n    \r\n    void loop() {\r\n        digitalWrite(D7, LOW);\r\n        delay(100);\r\n        digitalWrite(D7, HIGH);\r\n    }\r\n\r\nIf you run this, you can eyeball the amount of time spent in Spark.process (implicitly invoked on each loop iteration) based on the brightness of the onboard LED on D7. What you will see is that while the Photon is going through its Wi-Fi and cloud handshake, ~100% of the time is spend outside of loop. It's only after the cloud handshake is complete that % of time spent outside of loop comes down to near zero. \r\n\r\nI had a quick look at the firmware code, and my best guess is that this is happening due to a number of blocking sends inside Spark_Communication_Loop.\r\n\r\n(The behavior is the same in manual mode with an explicit call to Spark.process.)\r\n\r\nMy understanding from the documentation was that Spark.process was supposed to be a lightweight call and return within milliseconds (whereas Spark.connect is heavyweight and blocks for seconds at a time).\r\n\r\nThis is not what I actually observed, and my conclusion is that the only way I can get a good responsive touch UI out of a Photon is if I \r\n\r\n  a. Give up and drop a second MCU into this setup (so that it would run all the non-networking code and the Photon would be relegated to WiFi and Particle cloud duty) or \r\n  b. Turn off all networking code while the user is interacting with the device, and also turn off all interaction while there is network activity. \r\n\r\nI don't imagine that I have to explain why both of those solutions are problematic :-)"},"comment":{"url":"https://api.github.com/repos/spark/firmware/issues/comments/144312657","html_url":"https://github.com/spark/firmware/issues/509#issuecomment-144312657","issue_url":"https://api.github.com/repos/spark/firmware/issues/509","id":144312657,"user":{"login":"m-mcgowan","id":2465470,"avatar_url":"https://avatars.githubusercontent.com/u/2465470?v=3","gravatar_id":"","url":"https://api.github.com/users/m-mcgowan","html_url":"https://github.com/m-mcgowan","followers_url":"https://api.github.com/users/m-mcgowan/followers","following_url":"https://api.github.com/users/m-mcgowan/following{/other_user}","gists_url":"https://api.github.com/users/m-mcgowan/gists{/gist_id}","starred_url":"https://api.github.com/users/m-mcgowan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-mcgowan/subscriptions","organizations_url":"https://api.github.com/users/m-mcgowan/orgs","repos_url":"https://api.github.com/users/m-mcgowan/repos","events_url":"https://api.github.com/users/m-mcgowan/events{/privacy}","received_events_url":"https://api.github.com/users/m-mcgowan/received_events","type":"User","site_admin":false},"created_at":"2015-09-30T07:25:35Z","updated_at":"2015-09-30T07:25:35Z","body":"Multithreading beta will be released in 0.4.6, which addresses this so closing out. "}}