MQTT integration
This section provides guidance for using the NervesKey with popular MQTT brokers.

Last updated
Was this helpful?
Was this helpful?
{:ok, engine} = NervesKey.PKCS11.load_engine()
{:ok, i2c} = ATECC508A.Transport.I2C.init([])
signer_cert = X509.Certificate.to_der(NervesKey.signer_cert(i2c, :primary))
cert = X509.Certificate.to_der(NervesKey.device_cert(i2c, :primary))
key = NervesKey.PKCS11.private_key(engine, {:i2c, 1})
cacerts = [signer_cert | aws_root_certs()]
Tortoise.Supervisor.start_child(
client_id: manufacturing_serial_number(),
handler: {MQTTHandler, []},
server: {
Tortoise.Transport.SSL,
verify: :verify_peer,
host: mqtt_host(),
port: mqtt_port(),
alpn_advertised_protocols: alpn_advertised_protocols(),
server_name_indication: server_name_indication(),
cert: cert,
key: key,
cacerts: cacerts,
versions: [:"tlsv1.2"]
},
subscriptions: topics()
)