Azure / azure-iot-sdk-node

A Node.js SDK for connecting devices to Microsoft Azure IoT services
https://docs.microsoft.com/en-us/azure/iot-hub/
Other
261 stars 227 forks source link

Module Twin - Certificate has expired #1049

Closed AlonsoGuerrero closed 3 years ago

AlonsoGuerrero commented 3 years ago

I´m using the example simple_sample_module_twin.js to get info from a Module Identity Twin on a device located in IoT Edge

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

'use strict';

var ModuleClient = require('azure-iot-device').ModuleClient;
var Protocol = require('azure-iot-device-mqtt').Mqtt;

ModuleClient.fromEnvironment(Protocol, function (err, client) {
  if (err) {
    console.error("Could not create client: " + err.toString());
    process.exit(-1);
  } else {
    console.log('got client');

    client.on('error', function (err) {
      console.error(err.message);
    });

    // connect to the edge instance
    client.open(function(err) {
      if (err) {
        console.error(err);
      }  else {
        console.log('client opened');

        // Create device Twin
        client.getTwin(function(err, twin) {
          if (err) {
            console.error('could not get twin');
          } else {
            console.log('twin created');

            console.log('twin contents:');
            console.log(twin.properties);

            twin.on('properties.desired', function(delta) {
                console.log('new desired properties received:');
                console.log(JSON.stringify(delta));
            });

            // create a patch to send to the hub
            var patch = {
              updateTime: new Date().toString(),
              firmwareVersion:'1.2.1',
              weather:{
                temperature: 72,
                humidity: 17
              }
            };

            // send the patch
            twin.properties.reported.update(patch, function(err) {
              if (err) throw err;
              console.log('twin state reported');
            });
          }
        });
      }
    });
  }
});

But unfortunately I'm receiving this error with client.open [UnauthorizedError: mqtt.js returned Failure on first connection (Not authorized): certificate has expired error] {transportError: Error: Failure connection (Not authorized): certificate has expired

I would like to know if there is a way to renew the certificates and how to do it, or what is the reason of this problem. I don't understand what certificates refers this error

anthonyvercolano commented 3 years ago

The certificate may in fact be expired. How long have you had this set up. You should probably check a bit closer in the edge repo. There is also this: https://docs.microsoft.com/en-us/azure/iot-edge/how-to-manage-device-certificates?view=iotedge-2020-11&tabs=linux

AlonsoGuerrero commented 3 years ago

I'm not really sure how long. But has passed several months since this device was created

anthonyvercolano commented 3 years ago

90 days I believe is what you get. Bing (or some other search) something like "azure iot edge certificates". That would be a good start.

Github repo for edge

Was there anything else? @alonsoGuerrero

anthonyvercolano commented 3 years ago

Closed due to inactivity.