Recently, the “Internet of Things” (sometimes “the Internet of everything”) has become an integral part of everyday life. Gigabytes of data come from various sensors and sensors, which allows you to transfer the scope of analysis to a radically new level. IoT is becoming the next megatrend in the development of technology and is gaining increasing popularity in various business areas.
Today we want to draw your attention to DeviceHive - a fast, convenient and easy-to-use IoT project and open source software that provides powerful solutions for communication between devices and building your own “smart home”. It combines sensors, cloud services and mobile applications into a single infrastructure, saves huge amounts of information, starts the processes of its analysis and processing using machine learning algorithms both for historical data and in real time. To understand how the machine communication mechanism works within DeviceHive, let's try to create our own little application.
Let's start with the central part - DeviceHive Java-server. Since it was published in the
Microsoft Azure Marketplace , the installation and configuration process has become very simple. Follow the instructions below and the process will not take more than five minutes:
- open this link and click on “creating a virtual machine”, after redirecting, click “create” again;
- On the first page you will be prompted to enter the name of your virtual machine, configure authentication, and select the location and group of resources;
- In the next step, you will need to specify the VM parameters: memory size and type (these values depend on what the future application needs to work, but it is not recommended to use a weaker dual-core machine with 4 GB RAM);
- in the last step, specify the specific settings for your tasks, if necessary, and, after a brief overview, create a virtual machine.

Congratulations - your DeviceHive server is deployed in the cloud! On the information page you can find the external IP-address, even if it will be
public.ip.address within the article.
')
The next step is the initial configuration of our server. For further use of REST & Websocket connections, we will need the appropriate url-addresses. Open the
public.ip.addres s: 8080 / dh - DeviceHive Java-server information page, where you can see the version and build time. If you did everything right, the necessary endpoints are there too, but for now they should be equal to 'null'. To make them valid, you will need to click the Configure button. This action requires authentication. For these purposes (including) the system creates a user by default with administrator rights and
dhadmin / dhadmin_ # 911 credentials. Copy this into the login and password fields and in a couple of seconds you will see valid addresses on the updated page. After that, you can open the DeviceHive admin panel by going to
public.ip.address : 8080 / admin (log in with the same user). Let's take a closer look at it.
As far as you remember, dhadmin is an admin user, which is easy to recognize by the Admin button in the upper left corner of the page. Click on it and the Users-, Device Classes- and OAuth clients-goda menu will appear below. To begin with, let's open a page with users and change the password for the current one (in terms of data privacy, it is highly undesirable to continue using the default password). Create other users if necessary.

Next to Admin is the link to Access Keys. This is the central part of all authentication in the system. Each Access key (AK) is a randomly generated token with a set of custom accesses that can be created from the admin panel and with the help of a RESTful
endpoint . AK can use any member of the Devicehive ecosystem from the user to the device. For a deeper understanding of the authorization details in the system (and the use of keys in particular) within the framework of Devicehive, you can read
this article , but at this stage we will have enough of the simplest AK, which has no expiration date and has all admin access assigned. To create it, repeat exactly what you see in the image below:

Super! You have just created your own
demo_access_key , which can and should be used for further work with Devicehive and its components.
It's time to talk a bit about messaging algorithms. Our system provides for this three types of structures, each has features of use.
- DeviceNotification - information received from the device (usually data from various sensors and sensors, but there may also be configuration details).
- DeviceCommand - information that is sent to a device (a special command with its own parameters, which the device, in turn, knows how to process).
- DeviceCommandUpdate - the message sent by the device in response to the received DeviceCommand. Contains the result and status of the active team.
Let's go a little further and create our own device simulator (if words like RaspberryPI, BeagleBone and Arduino are not scary, you may not need it, but in this article we will have enough HTTP HTTP requests). Each device must be added to the corresponding Network, it is easy to do with the admin panel. Open the Networks page and create a new network, let it be a
dh-demo-network with a
dh-demo-key . To register a simulator, you need to send the following request to the server:
curl -H 'Content-Type: application / json' -H 'Authorization: Bearer demo_access_key' -X PUT -d '{"id": "dh-demo-device", "key": "dh-demo-key" , "Name": "dh-demo-device", "deviceClass": {"name": "demo-device-class", "version": "0.1", "equipment": []}, "network": {"Name": "dh-demo-network", "key": "dh-demo-key"}, "status": "Online"} ' public.ip.address : 8080 / dh / rest / device / dh -demo-deviceIf we did everything correctly, dh-demo-device should appear on the admin panel in the Devices section.

Let's send the notification, do it again using an HTTP request:
curl -H 'Content-Type: application / json' -H 'Authorization: Bearer demo_access_key' '-X POST -d' {"notification": "$ device-add", "parameters": {"param1": "value1 "}} 'Http // public.ip.address: 8080 / dh / rest / device / dh-demo-device / notificationThis message is now available on the detail page of the device and, if everything went well, you will see the following image:

Voila! We have just created a real device simulator with sensors and sent a notification from it to the DeviceHive cloud. Pretty simple, is not it? If you liked the article, and you are interested in IoT, contact us.

about the author
Tatyana Matvienko - Java & Scala Developer "DataArt"
Since 2012, DataArt has been developing various products in the field of BigData and Internet of Things, in particular, solutions based on the Spark ecosystem.