IoT devices are everywhere, from Industry 4.0 to Smart City projects. Developers of IoT applications deserve the same agility and cloud hosting ease than web developers. That’s why we unveil today the TCP Gateway addon to make IoT applications first class citizens on Scalingo. Let’s see how you can benefit from this.
The TCP Gateway addon
The majority of Platform as a Service providers are limited to web applications hosting, reachable via the HTTP protocol. However, in memory, CPU and battery constrained environment, like in the IoT world, folks don’t always use HTTP. Usually a custom, fast and lightweight TCP based protocol is preferred.
When you think about it, the application “BUILD” and “RUN” stages are very similar from those of a web application. Programming languages (NodeJS especially) and databases are usually shared as well. Therefore, the only limiting factor for a PaaS to host IoT apps is to have a TCP Gateway. We explained earlier how this feature can be achieved technically.
Today, we are unveiling the TCP Gateway addon which is the concretization of the previous technical article. That makes IoT apps, and of course any TCP based apps, first class citizens on Scalingo.
How to deploy your IoT/TCP app on Scalingo
Deploying your TCP app is very simple. You just have to follow these 3 easy steps:
- Create an app on Scalingo and provision the TCP Gateway addon
- Define a
tcpline in your Procfile
- Push your code.
Let’s go deeper in the procedure.
First, create your app. The wizard will guide you through a few steps. Give it a name and select the TCP Gateway addon.
When the app has been created. you’ll be given a Git endpoint. This is where you will have to push your code:
Before pushing your code, you need to define a
tcp line in your Procfile, it instructs the platform which process will handle the TCP traffic. The Procfile is a simple text file defining one or several types of process (one per line). For HTTP/HTTPS protocols, the
web line describes the process handling incoming web requests. For the TCP protocol, the
tcp line is responsible to start the process responsible to receive TCP connections.
Here is a Procfile sample to be able to handle web and TCP requests at the same time:
web: npm start tcp: npm run start-tcp
Once the code has been pushed, the deployment of the app will begin:
As usual on Scalingo, the programming language you’re using will be automagically detected.
Once the TCP Gateway addon has been provisionned, it will automatically inject a TCP_URL environment variable in your app context. The variable is shaped like:
tcp://tcp-gateway-1.eu-fr-agora-1.scalingo.com:20000. This is the TCP endpoint to contact yoru app.
Things to consider when deploying your IoT app on Scalingo
While we advise you to read the complete technical documentation about the TCP Gateway addon there are 3 main topics that you should be aware of.
Source IP identification
TCP connections are load balanced to application containers via NAT. The consequence is that the source IP address is replaced by our front end servers internal IP. Thus, the device identification must be intrinsically integrated in the protocol you designed over TCP.
Web and TCP process inter-communications
While it’s perfectly possible for a single application hosted on Scalingo to define 2 different process types that will handle web and TCP traffic, it’s not possible to handle both traffic by the same process. Indeed, by defining both
tcp lines in the Procfile of your app, this will results in two different process types started by Scalingo. Each process type can be handled separately: you can start, stop, scale each one. For example, you can have 10 tcp processes of size S and only 1 web process of size M.
However, it questions web/tcp inter-communications. To answer this problem you will certainly have to use a database acting as a middle man. The incoming TCP requests will be handled by your TCP processes, they will extract and store any valuable data in a database. Your web processes will then be able to query this database. Fortunately, Scalingo provides MongoDB, Redis and InfluxDB hosting that can do this job. While it’s a little pain for some developers, it will really help you scale your app horizontally.
While there’s no rate limit yet we may introduce one in the future though.
The Mosca NodeJS/MQTT sample
Mosca is a NodeJS MQTT broker which can be used as a standalone app or embedded in another NodeJS application.
We’ve made Mosca one-click deployable on Scalingo (thanks to our One Click Deployment API). An MQTT broker hosted in the cloud in the snap of a finger! All you have to do to deploy your own Mosca is to click the following button:
Here is the source code of this sample.
With this new addition, Scalingo becomes the first Platform as a Service to officially support TCP applications. In fact, we support any app, be it a web app or an IoT app.
Wants to hear about real world success stories built on this feature? Just wait a few more days…