-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


: Ubuntu RPI Azure IoT Hub

, 12 2017 . 18:47 +
, , ? , , . , . . .



(@andvis).

Disclaimer:
, . - . , Linux.

, Raspberry Pi 2 Model B. .



Ubuntu Mate , , .

img SDCard Win32 Disk Imager, Windows 10.



Raspberry Pi, , . .




.

sudo update-rc.d ssh enable


sudo service ssh restart


sudo ifconfig


update upgrade .

sudo apt-get update


sudo apt-get upgrade


.


( , ).



, I2C: sudo raspi-config.

SSH .





- .

, Azure! c .

.

1.


2.


3.


4.


, ! node -v RPI.



Node.js. : sudo apt install nodejs-legacy.



node -v .



.



NPM : sudo apt-get install npm. , !



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



IoT Hub transport package: sudo npm install -g azure-iot-device@latest.



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



IoT Explorer: sudo npm install -g iothub-explorer@latest.



iothub-explorer login " ".



: iothub-explorer create muzeyrpi-1 --connection-string. !



Azure .



JS :
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);

:
  1. /usr/lib /usr/local/lib.
  2. . .



node MyScript.js , .



Device Explorer ( .



Enter :)



PRI Azure IoT Hub

! , ( BME280 ).

,


, , Raspberry Pi 3. 2 , Microsoft Developer : Raspberry Pi? .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/332940/

:  

: [1] []
 

:
: 

: ( )

:

  URL