nodejs-mesosfer-integration

How to Store Data from IoT Device into Cloud Server using NodeJS

Introduction

Here you will learn about How to Store Data from IoT Device into Cloud Server using NodeJS.

In this tutorial, we will try to create a real time data storing from IoT Devices that have an operating system such as Intel Edison, RaspberryPi, OrangePi, and etc into Mesosfer cloud platform. Script, code, and all of them are already handled by Mesosfer. You only need to install and config then run. It’s very simple, isn’t it?

Prerequisites

To follow this tutorial, you will need to prepare these items below :

  • Sign up for an account in mesosfer cloud platform.
  • RaspberryPi2, RaspberryPi3 or Intel Edison that are connected network and  installed with NodeJS.

Getting Started

Firstly, you have to create application on Mesosfer cloud platform and choose EMBEDDED for Application Type  like picure below :

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-create-apps

If you have an embedded application on Mesosfer cloud platform, click detail to create bucket or schema that used to collect your data from your Embedded/IoT Devices. Follow the step to create bucket like picture below :

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-create-bucket

After bucket created, you can define column based on your need. Click menu add column on right toolbar then do everything you want. It’s so flexible, isn’t it?

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-add-column

Mesosfer provide many data types for each column such as String, Number, Boolean, Date, etc.

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-bucket

When your bucket is ready to receive metadata, you can setup the devices data. Go to device menu then define our topic as channel for communication, don’t forget to connect with a bucket that has been defined.

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-add-device

Everything in the Mesosfer setup has been completed, let’s jump in to device configuration. In this section you do not need to code. Click link code in list device then copy into your device.

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-code

In the picture above, Mesosfer provide sample code for publish data to our bucket. When you execute action publish, the data will be automatically stored in your bucket.  But if you want to consume data in your server, copy code in panel consumer then copy in your environment server.

This tutorial can implemented in various devices that have an operating system, but in this section you will try to push data using RaspberryPi. Please login to the device first, you can use putty or ssh client like picture below :

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-ssh-raspi

Before running code, make sure nodejs has been installed in your device and don’t forget about internet connection. After that, you can create folder to save publisher code then initialize json file configuration like command below :

Fill and follow instructions, just enter and leave it empty if we don’t understand about the question. Then you can create publisher file and put the code in panel publisher from Mesosfer cloud to this file.

Save with command ctrl+x then y. Don’t forget to install mqtt package like command below :

Then run the publisher with run command :

If there is no error, data will be stored in your bucket, like picture below :

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-result-store

Beside that you can show up this data in our web application using web socket. Just copy code in panel Web Socket then place on your html file.

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-web-socket

Web socket code requires file browserMqtt.js, you can build by following instructions in npm site or download directly here. If you try to run in browser that html file, the result is like the picture below :

how-to-store-data-from-iot-device-into-cloud-server-using-nodejs-web-socket-browser

Conclusion

We’ve tried to store data using RaspberryPi with zero coding. So It can reduce your development time. Mesosfer provide almost all the items you need. So enjoy creating your Mobile application using Mesosfer Cloud Platform.

Mesosfer helps you connect your project to the cloud. Cut off the development process so you can straight into the delivery process instead stumble on the complicated infrastructure.