Spark Core-based proxy

By: on August 10, 2015

Regular readers of this blog will have seen my earlier post on Dalek remote control where I used a Spark Core to connect the Dalek’s remote control to the internet. However, in the second post I noted how hotel Wi-Fi is basically evil, and so I ran into all manner of problems with connecting the Spark to the Wi-Fi in the hotel where I actually wanted to demo the Dalek…

I’ve therefore spent the last week or so writing a way around this problem in the form of the Spark Proxy. It lets you proxy a web browser’s requests through a Spark Core, and so deal with browser-based Wi-Fi authentication mechanisms for this embedded device that doesn’t have a web browser.

Here’s how to install it:

  1. While in a nice Wi-Fi environment (e.g. at home before the convention), download the spark-proxy and install the Particle CLI
  2. Get your Spark’s id with particle list
  3. Make sure your Spark Core is powered up and then run particle flash [your Spark's id] . (don’t forget that last ‘.’ as it indicates to use the files in the current directory) from the directory with the Spark proxy code in
  4. Your Spark Core is now running the proxy code, and you can now go to to the event with the crappy Wi-Fi
  5. Connect the Spark Core to your laptop and run particle serial list to get the serial port of your device
  6. Now run python wifi.py [path to serial port] [wifi network name] [wifi network password] to get it to talk to the annoying Wi-Fi network
  7. Run python proxy.py [path to serial port] and you’ve now got an HTTP proxy up and running. HTTPS, not so much, but generally that’s enough for this limited use case.
  8. Boot up a browser (ideally a different one to your main one so you can use the main one to check things) and get it to talk to the proxy at http://localhost:1080
  9. Go through the relevant Wi-Fi authentication pages, and then disconnect your Spark Core from your laptop

Congratulations! You’ve now got a Spark that’s trusted by the local Wi-Fi network, and has the Tinker functions installed so all of that will work nicely which is what most apps need. Hopefully they’ll trust it for at least a day or so… Alternately, go to an event like the one I was at this last weekend where the Wi-Fi just works nicely with none of this web browser stuff, and your life is much easier, but meant I couldn’t beta-test this in full real-world conditions 🙁

Other things learned along the way:

  • The Spark built-in String functions are a little buggy, and you’re better off just doing your own stuff with malloc.
  • “Breathing” Green LED is undocumented, but means talking to Wi-Fi but not talking to the Spark cloud
  • Blinking Red LED is also possible if you do enough stupid things, and I’ve got no idea what that means (not in the documentation), other than “time to reflash your device”
  • I suspect there’s some internal bug with the serial code on the Spark (or I’ve done something daft), as this sometimes craps itself after running the proxy for a while. It’s a tad flakey, but probably good enough to get you through a registration screen or two.
  • The apple.com “is this a good connection?” page is really very useful.
Share

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*