Marketer notes: How to install Ubuntu on an RPI and connect to Azure IoT Hub

  • Tutorial
What does a marketer do when asked to tell how to use the technology, but he can’t find the instructions? Usually begins to pull all the surrounding techies, search the Internet or silently wait for a miracle, or cry. But, this story is about another marketer. He simply took and wrote the instructions himself. I invite you to evaluate the work under cat and share my opinion.



I pass the floor to Andrei .

Disclaimer :
Colleagues, I do not pretend to be true - I just share my experience. Perhaps he will save someone a little effort and time. And yes, at the time of writing, I saw the Linux command line for the first time in my life.

Let's agree that below we will talk about the Raspberry Pi 2 Model B. It was during work with him that all the screenshots were taken.



The Ubuntu Mate distribution can be downloaded, for example, here .

Having an img file - create a bootable SDCard - for this I used Win32 Disk Imager, which I installed on my Windows 10.



We insert the resulting boot card into the Raspberry Pi, connect the keyboard, mouse and display. After a successful download, we see the windows below.




Immediately after installation, we execute several commands.

sudo update-rc.d ssh enable


sudo service ssh restart


sudo ifconfig- will show us the network settings of the device


Important update and upgrade commands - to update the system.

sudo apt-get update


sudo apt-get upgrade


Next, add the Russian language for the keyboard.


This is how you can change the combination of switch keys (I spent a couple of minutes until I found this item).



On one of the forums I read that I2C should be turned on: by a team sudo raspi-config.

Here by the way, and SSH settings can be changed.





While there are no sensors at hand - I’m trying to do at least something ... I’m reading this article .

Let's start with the fact that we need an Azure subscription! A trial version can be obtained here .

Our next steps.

Step 1 .


Step 2 .


Step 3 .


Step 4 .


So, back to the device! The command node -vreturns an error on my RPI.



Install Node.js. To do this, trying to drive command sudo apt install nodejs-legacy.



Now the command node -vreturns the current version.



Just in case.



Now need NPM - install command: sudo apt-get install npm. The team is not fast, but it worked!



Then run: sudo npm install -g npm@2.x.



Now you have to put the latest version of the Hub transport package the IoT: sudo npm install -g azure-iot-device@latest.



And another team: sudo npm install -g azure-iot-device-http@latest.



Now you have to set the Explorer the IoT: sudo npm install -g iothub-explorer@latest.



The next step is to run this command iothub-explorer login "строка подключения".



Further connect device: iothub-explorer create muzeyrpi-1 --connection-string. Successfully!



The device is visible on the Azure portal.



Copy the JS script to the device from the page :
var connectionString = '';
var clientFromConnectionString = require('/usr/lib/node_modules/azure-iot-device-http').clientFromConnectionString;
var client = clientFromConnectionString(connectionString);
var Message = require('/usr/lib/node_modules/azure-iot-device').Message;
var msg = new Message('some data from my device');
var connectCallback = function (err) {
  if (err) {
    console.error('Could not connect: ' + err);
  } else {
    console.log('Client connected');
    var message = new Message('some data from my device');
    client.sendEvent(message, function (err) {
      if (err) console.log(err.toString());
    });
    client.on('message', function (msg) {
      console.log(msg);
      client.complete(msg, function () {
        console.log('completed');
      });
    });
  }
};
client.open(connectCallback);

The script itself will not start - you must:
  1. The paths inside the file must be changed /usr/libto /usr/local/lib.
  2. Add connection string. Moreover, the connection string is to the device.



The script is launched by the command node MyScript.jsfrom the folder where the script is located.



We try again - this time in Device Explorer (more about it and the download link in the article .



Press Enter ... :)



Congratulations - the first messages from our RPI reached the Azure IoT Hub.

I sincerely hope to finalize this instruction and make it even more useful! For example, following this path (with or without a BME280 sensor on hand).

For those who have read


In order for you to try to do this exercise yourself, Andrey and I decided to play two pieces of Raspberry Pi 3. They will be received by the first 2 people who will answer correctly in the messages of the Microsoft Developer community to the question: “Based on which microcontroller was the earliest version developed Raspberry Pi? ” General Rules .

Also popular now: