You are reading a single comment by @lukevanhorn and its replies. Click here to read the full conversation.
  • I just put in a pull request for the feature that reads from the file system. PEM files can be stored in the default format and the certificate/key data will be parsed, removing beginning, ending delimiters and newline characters.

    Here's example code using the file paths instead of cert strings:

    var eth;
    var connection;
    
    var options = url.parse("mqtt://A1123456789AA.iot.us-e­ast-1.amazonaws.com:8883");
    options.ca = 'certs/rootCA.pem';
    options.cert = 'certs/cert.pem';
    options.key = 'certs/key.pem';
    
    var mqtt = require("MQTT").create();
    mqtt.on("connected", function() {
      console.log("connected to AWS IoT Service...");
      mqtt.subscribe("test/topic");
    });
    
    mqtt.on("publish", function (pub) {
      console.log("\nNew message received: ");
      console.log("topic: "+pub.topic);
      console.log("message: "+pub.message);
    });
    
    function onInit() {
    
      SPI2.setup({mosi:B15,miso:B14,sck:B13,ba­ud:1000000});
      E.connectSDCard(SPI2,B1);
      
      SPI3.setup({ mosi:B5, miso:B4, sck:B3 });
      eth = require("WIZnet").connect(SPI3, A0);
      eth.setIP();
      
      require("tls").connect(options, function(res) {
        connection = res;
        console.log("tls connected");
        setTimeout(function() {
          mqtt.connect(res);
        },2000);
      });
    }
    

    The timeout is necessary to allow the certificate exchange and verification to complete before calling mqtt.connect. Maybe this can be event driven.

About

Avatar for lukevanhorn @lukevanhorn started