{"action":"created","issue":{"url":"https://api.github.com/repos/spark/particle-cli/issues/48","labels_url":"https://api.github.com/repos/spark/particle-cli/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/spark/particle-cli/issues/48/comments","events_url":"https://api.github.com/repos/spark/particle-cli/issues/48/events","html_url":"https://github.com/spark/particle-cli/issues/48","id":90701921,"number":48,"title":"[Photon] `particle setup` fails on OSX due to hardcoded Wi-Fi interface","user":{"login":"siddMahen","id":823940,"avatar_url":"https://avatars.githubusercontent.com/u/823940?v=3","gravatar_id":"","url":"https://api.github.com/users/siddMahen","html_url":"https://github.com/siddMahen","followers_url":"https://api.github.com/users/siddMahen/followers","following_url":"https://api.github.com/users/siddMahen/following{/other_user}","gists_url":"https://api.github.com/users/siddMahen/gists{/gist_id}","starred_url":"https://api.github.com/users/siddMahen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/siddMahen/subscriptions","organizations_url":"https://api.github.com/users/siddMahen/orgs","repos_url":"https://api.github.com/users/siddMahen/repos","events_url":"https://api.github.com/users/siddMahen/events{/privacy}","received_events_url":"https://api.github.com/users/siddMahen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spark/particle-cli/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-06-24T15:02:06Z","updated_at":"2015-08-18T01:14:41Z","closed_at":null,"body":"I just received my Photon today. After connecting it to my computer via USB, installing the particle cli and running `particle setup`, I encountered the following problem:\r\n\r\n```\r\n! Woops. Something went wrong connecting to Photon-JTTY. Please manually re-connect to your Wi-Fi network.\r\n```\r\n\r\nAfter digging through the code, I isolated the problem to a bug in WirelessCommand/connect/darwin.js:\r\n\r\n```\r\n\tvar params = 'networksetup -setairportnetwork en0 ' + opts.ssid;\r\n\tif(opts.password) { params += ' ' + opts.password; }\r\n\r\n\t// TODO: something with opts & interfaces?\r\n\texec(params, results);\r\n\tfunction results(err, stdin, stderr) {\r\n\r\n\t\tif(err || stderr) {\r\n\r\n\t\t\t// TODO: more research into failure modes of this command\r\n\t\t\treturn cb(err || stderr);\r\n\t\t}\r\n\t\tcb(null, opts);\r\n\t};\r\n```\r\n\r\nHere, the particle cli is trying to connect to a particular Wi-Fi network using the `networksetup` utility. The problem is that on certain Darwin machines, `en0` is not a valid Wi-Fi interface, and thus this method fails every time it's called. In turn, this causes the following code in WirelessCommand/index.js to consistently fail:\r\n\r\n```\r\n\t\tif(!self.__manual) {\r\n\r\n\t\t\tself.newSpin('Attempting to connect to ' + photon + '...').start();\r\n\t\t\tmgr.connect({ ssid: photon }, connected);\r\n\t\t}\r\n\r\n...\r\n\r\n\tfunction connected(err, opts) {\r\n\r\n\t\tself.stopSpin();\r\n\t\tif(err) {\r\n\t\t\t// TODO: Max retries, help output when reached.\r\n\t\t\tconsole.log(\r\n\t\t\t\tchalk.bold.red('!'),\r\n\t\t\t\tchalk.bold.white('Woops. Something went wrong connecting to ' + photon + '. Please manually re-connect to your Wi-Fi network.')\r\n\t\t\t);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tconsole.log(\r\n\t\t\tarrow,\r\n\t\t\t'Hey! We successfully connected to',\r\n\t\t\tchalk.bold.cyan(opts.ssid)\r\n\t\t);\r\n\t\tself.__configure(opts.ssid, done);\r\n\t};\r\n```\r\n\r\nRunning `networksetup -listallhardwareports` shows me that `en1` is the correct hardware port for the Wi-Fi interface on my machine:\r\n\r\n```\r\n$  ~  networksetup -listallhardwareports\r\n\r\nHardware Port: Bluetooth DUN\r\nDevice: Bluetooth-Modem\r\nEthernet Address: N/A\r\n\r\nHardware Port: Ethernet\r\nDevice: en0\r\nEthernet Address: ac:87:a3:2e:bf:ef\r\n\r\nHardware Port: Wi-Fi\r\nDevice: en1\r\nEthernet Address: b8:09:8a:d3:5e:2f\r\n\r\nHardware Port: Bluetooth PAN\r\nDevice: en4\r\nEthernet Address: b8:09:8a:d3:5e:30\r\n\r\nHardware Port: Thunderbolt 1\r\nDevice: en2\r\nEthernet Address: 32:00:1a:a0:80:00\r\n\r\nHardware Port: Thunderbolt 2\r\nDevice: en3\r\nEthernet Address: 32:00:1a:a0:80:01\r\n\r\nHardware Port: Thunderbolt Bridge\r\nDevice: bridge0\r\nEthernet Address: N/A\r\n\r\nVLAN Configurations\r\n===================\r\n```\r\n\r\nChanging `en0` to `en1` allowed me to complete `particle setup` without any further trouble.\r\n\r\nFixing this issue would require a reliable method of obtaining the correct hardware port. Parsing the output of `networksetup -listallhardwareports` or `networksetup -listnetworkserviceorder` seems to work, but this is ugly."},"comment":{"url":"https://api.github.com/repos/spark/particle-cli/issues/comments/132016653","html_url":"https://github.com/spark/particle-cli/issues/48#issuecomment-132016653","issue_url":"https://api.github.com/repos/spark/particle-cli/issues/48","id":132016653,"user":{"login":"brycekahle","id":1010430,"avatar_url":"https://avatars.githubusercontent.com/u/1010430?v=3","gravatar_id":"","url":"https://api.github.com/users/brycekahle","html_url":"https://github.com/brycekahle","followers_url":"https://api.github.com/users/brycekahle/followers","following_url":"https://api.github.com/users/brycekahle/following{/other_user}","gists_url":"https://api.github.com/users/brycekahle/gists{/gist_id}","starred_url":"https://api.github.com/users/brycekahle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brycekahle/subscriptions","organizations_url":"https://api.github.com/users/brycekahle/orgs","repos_url":"https://api.github.com/users/brycekahle/repos","events_url":"https://api.github.com/users/brycekahle/events{/privacy}","received_events_url":"https://api.github.com/users/brycekahle/received_events","type":"User","site_admin":false},"created_at":"2015-08-18T01:14:41Z","updated_at":"2015-08-18T01:14:41Z","body":"I think we can use `networksetup -listallhardwareports` and find all ports with `Wi-Fi` in the `Hardware Port`.\r\n\r\nExample output:\r\n```\r\nHardware Port: Bluetooth DUN\r\nDevice: Bluetooth-Modem\r\nEthernet Address: N/A\r\n\r\nHardware Port: Wi-Fi\r\nDevice: en0\r\nEthernet Address: 34:36:3b:d2:fb:3e\r\n```"}}