IoT Cloud Starter Guide - Networking for Mobile Apps

A common application for the Internet of Things is sending data to some cloud service, for further processing storage and analysis. Data analysis and Business intelligence are important areas for IoT. This guide helps you sorting out the options for communication with cloud servers from a mobile app.

Secure connections - HTTP vs HTTPS and WS vs WSS

One thing to be aware of when writing code that communicates with servers from a web page is that web protocols come in two flavours, standard HTTP (non-encrypted data transfer) and HTTPS (encrypted secure data transfer).

The tricky part is that an app loaded over HTTPS is not allowed to access resources over HTTP, you must use HTTPS also when loading images, css, scripts, and when using XHR. Web views only allow secure connections from a securely loaded page. This is something to keep in mind when working with Evothings Studio, since Evothings Viewer uses HTTPS to communicate with the server that hooks up to the Workbench.

Similarly if you are using WebSockets (WS) you must use Secure WebSockets (WSS).

To sum it up, if you need to access data on a server, the server must support HTTPS or WSS (WebSocket Secure) and it must be configured with a proper certificate (not self signed) and the certificate must include all intermediates. This is because the Evothings Viewer does not bundle a lot of the known intermediates, as a regular browser typically does.


To work around this restriction for regular HTTP requests, the Cordova HTTP plugin can be used. See below for further details.

Network programming

A mobile phone uses TCP (or UPD) sockets to communicate with servers, either over WiFi or 3G/4G. Here are the ways available for hybrid HTML/JavaScript apps to do network programming.

XHR (XMLHttpRequest - also known as "Ajax")

With XHR ("Ajax requests") it is possible to communicate with servers right from JavaScript with no native plugins.

Keep in mind that the server must support HTTPS when you use Evothings Studio (see section above for explanation).

If you use the jQuery library, it is easy to DO XHR calls using the ajax() function.

WebSockets (WS or WSS)

WebSockets is the latest technology for communicating with servers right from JavaScript. Note again that you need to use Secure WebSockets when you are running in the viewer served via the Workbench, as described above. See our articles around MQTT below for more details around WebSockets since that is the protocol used to talk to the MQTT servers.

Cordova HTTP plugin

Using the plugin cordova-HTTP you can access and download data from any server, without HTTPS/HTTP restrictions or cross-origin restrictions.

With this plugin the app can fetch JSON data, HTML code, basically any text-encoded data. Fetching binary data is not supported. You can also upload JSON data with this plugin.

The HTTP plugin is included with Evothings Viewer.

Chrome Sockets - TCP networking support

The Mobile Chrome Apps socket plugins can be used to access data and communicate with servers using the basic TPC protocol. The UPD protocol is also supported, but is not commonly used by IoT Cloud services.

Have a look at the API reference for the Chrome Socket TCP plugin.

This plugin is included with Evothings Viewer.

Custom plugins

As a final option for communicating with servers and Cloud services, you can write a custom Cordova plugin. Consult the Apache Cordova documentation for an overview of how to make your own plugin.

Cloud tutorials

Related tutorials