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://­"); = '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.on("publish", function (pub) {
      console.log("\nNew message received: ");
      console.log("topic: "+pub.topic);
      console.log("message: "+pub.message);
    function onInit() {
      SPI3.setup({ mosi:B5, miso:B4, sck:B3 });
      eth = require("WIZnet").connect(SPI3, A0);
      require("tls").connect(options, function(res) {
        connection = res;
        console.log("tls connected");
        setTimeout(function() {

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


Avatar for lukevanhorn @lukevanhorn started