Skip to content

Conversation

monkbroc
Copy link
Member

@monkbroc monkbroc commented Mar 4, 2016

While setting up a Photon at my office where there are 28 WiFi networks I ran into a bug in softap-setup where the JSON response is assumed to fit in one TCP packet.

I changed the algorithm to try JSON parsing with all the data received so far until it succeeds or there is a timeout.

I also had to bump up the default timeout since the scan takes longer than 2 seconds in my office. I didn't find a place in the particle-cli where the SoftAP scan timeout is increased so I bumped it up here.

I also removed the check for the object type in sock.on('data') since that's a relic of the multi-protocol onData function and not needed anymore for the TCP only version.

I realize @brycekahle that you're in the process of making a bunch of changes to this library and the CLI, and that using softap-setup-js 4.0.1 in the current particle-cli doesn't work, but I worked around the integration issues in the CLI to make sure this change works.

Here's an example of the data I receive (captured by a couple console.log in TcpSoftAP.js):

▐ Asking the Photon to scan for nearby Wi-Fi networks...
Receiving data 

{"scans":[{"ssid":"HiveNet","rssi":-68,"sec":4194308,"ch":11,"mdr":216700},{"ssid":"cssw-private","rssi":-55,"sec":4194308,"ch":1,"mdr":144400},{"ssid":"csswjones","rssi":-62,"sec":1,"ch":2,"mdr":54000},{"ssid":"HP-Print-4F-Officejet 4630","rssi":-67,"sec":0,"ch":1,"mdr":54000},{"ssid":"TechBrewery","rssi":-73,"sec":4194308,"ch":1,"mdr":216700},{"ssid":"xfinitywifi","rssi":-81,"sec":0,"ch":1,"mdr":216700},{"ssid":"intergalactic","rssi":-82,"sec":4194308,"ch":1,"mdr":144400},{"ssid":"xfinitywifi","rssi":-79,"sec":0,"ch":11,"mdr":216700},{"ssid":"TechTavern","rssi":-76,"sec":4194308,"ch":11,"mdr":216700},{"ssid":"SBD-NA","rssi":-71,"sec":4194308,"ch":11,"mdr":144400},{"ssid":"avalonet2","rssi":-67,"sec":2097154,"ch":5,"mdr":54000},{"ssid":"A2JW2","rssi":-79,"sec":4194310,"ch":11,"mdr":216700},{"ssid":"zzzzzzz","rssi":-69,"sec":4194308,"ch":11,"mdr":216700},{"ssid":"avalonet2","rssi":-58,"sec":2097154,"ch":5,"mdr":54000},{"ssid":"DIRECT-7b-HP M477 LaserJet","rssi":-75,"sec":4194308,"ch":6,"mdr":72200},{"ssid":"CreativeTechnology","rssi":-70,"sec":4194310,"ch":6,"mdr":300000},{"ssid":"TechBreweryNew","rssi":-64,"sec":4194308,"ch":8,"mdr
Receiving data ":300000}]}
Socket close
Parsing JSON 

{"scans":[{"ssid":"HiveNet","rssi":-68,"sec":4194308,"ch":11,"mdr":216700},{"ssid":"cssw-private","rssi":-55,"sec":4194308,"ch":1,"mdr":144400},{"ssid":"csswjones","rssi":-62,"sec":1,"ch":2,"mdr":54000},{"ssid":"HP-Print-4F-Officejet 4630","rssi":-67,"sec":0,"ch":1,"mdr":54000},{"ssid":"TechBrewery","rssi":-73,"sec":4194308,"ch":1,"mdr":216700},{"ssid":"xfinitywifi","rssi":-81,"sec":0,"ch":1,"mdr":216700},{"ssid":"intergalactic","rssi":-82,"sec":4194308,"ch":1,"mdr":144400},{"ssid":"xfinitywifi","rssi":-79,"sec":0,"ch":11,"mdr":216700},{"ssid":"TechTavern","rssi":-76,"sec":4194308,"ch":11,"mdr":216700},{"ssid":"SBD-NA","rssi":-71,"sec":4194308,"ch":11,"mdr":144400},{"ssid":"avalonet2","rssi":-67,"sec":2097154,"ch":5,"mdr":54000},{"ssid":"A2JW2","rssi":-79,"sec":4194310,"ch":11,"mdr":216700},{"ssid":"zzzzzzz","rssi":-69,"sec":4194308,"ch":11,"mdr":216700},{"ssid":"avalonet2","rssi":-58,"sec":2097154,"ch":5,"mdr":54000},{"ssid":"DIRECT-7b-HP M477 LaserJet","rssi":-75,"sec":4194308,"ch":6,"mdr":72200},{"ssid":"CreativeTechnology","rssi":-70,"sec":4194310,"ch":6,"mdr":300000},{"ssid":"TechBreweryNew","rssi":-64,"sec":4194308,"ch":8,"mdr":300000}]}

@monkbroc monkbroc force-pushed the tcp-multiple-packets branch from 2a8b5ee to 646eb4a Compare March 4, 2016 17:10
@brycekahle
Copy link
Contributor

Initial glance looks good. I'd love to get a test around this. Thoughts on that?

@monkbroc
Copy link
Member Author

monkbroc commented Mar 6, 2016

What about splitting the JSON in the emulator _send_response so it gets sent in multiple calls to sock.write? It might expose other issues.

https://github.com/spark/softap-emulator-js/blob/master/index.js#L94

@monkbroc
Copy link
Member Author

monkbroc commented Mar 8, 2016

I made a change to the SoftAP emulator library to send JSON responses in multiple packets.
particle-iot/softap-emulator-js#2

With the emulator change and softap-setup-js master, 2 tests fail (scan and public key). With this softap-setup-js PR, all tests pass.

When softap-emulator-js is released, I'll update this PR with an updated package.json.

@brycekahle
Copy link
Contributor

softap-emulator-js 1.0.2 released and published.

@monkbroc
Copy link
Member Author

monkbroc commented Mar 8, 2016

Thanks @brycekahle. I updated package.json and checked that all tests now pass.

brycekahle added a commit that referenced this pull request Mar 8, 2016
TCP SoftAP response received in multiple packets
@brycekahle brycekahle merged commit f81e4db into particle-iot:master Mar 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants