Particle Device Setup Android using HTTP

I was wondering, why does the Android Device Setup library connects to the Photon in Soft AP mode using TCP instead of HTTP? I want to connect without the setup library. So far, I’ve been connecting to the AP, and sending HTTP requests, but have run into issues. One is that Android no longer allows clear text HTTP traffic by default, which I’ve circumvented with a custom network security config. Another issue is how OkHttp gets confused by a raw ip address, because it tries to use DNS on a local address. I’ve overcome this by implementing the DNS interface for the local 192.168.0.1 address, and passing it into the HttpClient builder. But still, after connecting to the Photon, turning off cellular data, and making an HTTP request for something like http://192.168.0.1/device-id, I get a 404. This is not the case when navigating to http://192.168.0.1/device-id in Chrome. Are there any other pitfalls anyone knows about when going down this route?

Was TCP chosen for the implementation to circumvent these issues? Is it possible to use HTTP instead of TCP for the Android setup process? Thanks.

HTTP is sat ontop off TCP, so when using HTTP you are in fact using TCP too.
Directly sitting on the base protocol provides you with more felxibility.

I already responded to Brady via email, but I’m sharing here so that everyone benefits:

Photon setup uses a very simple, custom socket protocol to communicate; HTTP isn’t used at all. If anyone’s interested in the implementation details, this class is probably a good starting point.

2 Likes

@jensck_particle thank you so much for your correspondence! It’s been very encouraging. I really want to add to your library to support setting up products as well as devices.

@ScruffR I really didn’t want to use a raw TCP socket if we have the opportunity to use HTTP. If we could have used HTTP without much fuss, then making an Android client would be trivial, thanks to OkHttp, Retrofit2, and especially Retrofit’s recent support for coroutines. Unfortunately, the Android restrictions on cleartext network traffic, DNS issues on a LAN, as well as others that I haven’t figured out yet make it harder than I realized. So hence the socket command client. It looks like this is how the iOS setup library also works, whereas the JS library implements both a TCP and HTTP version (https://github.com/particle-iot/softap-setup-js#protocols). Would love to get to the bottom of the issue, but until then, sockets it is.

1 Like