Photon to Owncloud's protocol: CoAP --- Why did not use UDP instead of

Hey guys,

My company is working on ownclod developing recently days.

We are study on the spark-protocol source code, and find out that, it’s using and CoAP protocol. And we

searched a lot of CoAP applications, they are using UDP with CoAP.

I was woundering that, why “spark-protocol” using with COAP not UDP?

And, if we want to use UDP instead of to connect the ownload that we are developing, how to do it?

Thanks, waiting for response :wink:

Hi @ZachBergh

I am not sure I understand the terminology you are using but the Particle Cloud protocol using CoAP can be carried on either TCP or UDP. Each has its tradeoffs and so in general TCP is used with the WiFi products like Photon and UDP is used with the cellular products like Electron.

Good luck with your project.

Hey @bko

Thanks for response.

I checked out the document in, find out from firmware side we can setup a UDP server:

Is this a configuration for start a UDP server in Electron, then we can use our UDP owncloud connect Electron?

And i use Phonton connect with our TCP-socket owncloud, i can see the traffic like “CoAP” + “TCP” connections, can we set this connection to UDP?

Thank you very much. :slight_smile:

And for study

I was wundering while Electron connect Owndcloud with UDP, what will it do exactly from the inside logic.

And why using TCP in Photon, not UDP? What’s the inside reason?

Hi @ZachBergh

The internal Particle cloud connection does not use the Arduino interface that you pointed to the doc for above–that is for you as programmer to create your own UDP connections to other hosts. It uses a similar but lower level interface.

See this changelog entry for Electron:

There is a way to convert an Electron to use TCP but it will use more cellular data. The public key of the Particle cloud is also different for UDP vs. TCP. The CLI is the best way to change this.

1 Like

Hey @bko

Got it, thanks for your response, it helps a lot :wink:

Good luck bro.

I’m not entirely certain this is relevant to your project, but just in case I’ll mention it:

UDP behaves a little differently than you might expect on the Electron because of the way mobile carriers run their networks. In particular, your Electron does not have its own unique IP address assigned to it. The IP address is shared with many other mobile users, and port mapping is used, similar to how a home network shares an IP address. This isn’t specific to the Electron; it applies to your phone as well.

Because of this, even though you can query your public IP address, you cannot make connections out of the blue to a TCPServer or UDP listener running on an Electron, because the mobile carrier has not set up a port mapping for it. There’s no way around that.

If you first send an outgoing UDP request, however, it is possible to receive a UDP response back for a short period of time. This allows most UDP protocols like DNS to work properly. One important thing if you’re writing your own server: Make sure you respond to the port the request came from, not the port you are listening on on the Electron. Because of the port mapping they won’t be the same. The amount of time the mapping is kept active varies by carrier, about 23 minutes for a Particle SIM to 30 seconds for some carriers.