Upcoming maintenance
Dear Customers and Partners.
This website will be undergoing scheduled maintenance on June 14, 2023. Please be aware there may be disruption to the developer portal website and associated services during the scheduled maintenance period.
This upgrade is essential to ensure the continued performance, reliability, and security of Developer World.
We apologize for any inconvenience.
LTE TLS connection to MQTT Broker without CACert
-
I am using the Spresense main board with the LTE extension. I am using the Arduino IDE to flash the program to the device. I am trying to connect to a MQTT client using TLS but without having a CERT file. I just use a username and password. Is this something that is possible? Currently I am using LTETLSClient and MqttClient arduino libraries.
#include <LTE.h> #include <ArduinoMqttClient.h> #include <Arduino_JSON.h> // APN name #define APP_LTE_APN "apn.com" // APN IP type #define APP_LTE_IP_TYPE (LTE_NET_IPTYPE_V4V6) // APN authentication type #define APP_LTE_AUTH_TYPE (LTE_NET_AUTHTYPE_NONE) // RAT to use #define APP_LTE_RAT (LTE_NET_RAT_CATM) LTE lteAccess; LTETLSClient client; MqttClient mqttClient(client); // MQTT settings (WEST IOT) const char broker[] = "mqtt.broker.com"; int port = 8883; const char uname[] = "username"; const char client_id[] = "clientId"; const char pass[] = "password"; void setup() { char apn[LTE_NET_APN_MAXLEN] = APP_LTE_APN; LTENetworkAuthType authtype = APP_LTE_AUTH_TYPE; // initialize serial communications and wait for port to open: Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } while (true) { /* Power on the modem and Enable the radio function. */ if (lteAccess.begin() != LTE_SEARCHING) { Serial.println("Could not transition to LTE_SEARCHING."); Serial.println("Please check the status of the LTE board."); for (;;) { sleep(1); } } /* The connection process to the APN will start. * If the synchronous parameter is false, * the return value will be returned when the connection process is started. */ if (lteAccess.attach(APP_LTE_RAT, apn, "", "", authtype, APP_LTE_IP_TYPE) == LTE_READY) { Serial.println("attach succeeded."); break; } /* If the following logs occur frequently, one of the following might be a cause: * - APN settings are incorrect * - SIM is not inserted correctly * - If you have specified LTE_NET_RAT_NBIOT for APP_LTE_RAT, * your LTE board may not support it. * - Rejected from LTE network */ Serial.println("An error has occurred. Shutdown and retry the network attach process after 1 second."); lteAccess.shutdown(); sleep(1); } Serial.print("Attempting to connect to the MQTT broker: "); Serial.println(broker); mqttClient.setUsernamePassword(uname, pass); mqttClient.setId(client_id); if (!mqttClient.connect(broker, port)) { Serial.print("MQTT connection failed! Error code = "); Serial.println(mqttClient.connectError()); while (1); } Serial.println("You're connected to the MQTT broker!"); Serial.println(); }
-
Hey, SudoObey
I believe the TLS protocol requires a certificate.
Are you unsure of where to get the certificate you need? -
@CamilaSouza
Thank you for getting back to me. I am fairly new to this MQTT and LTE thing. Is there a way to have a TLS connection using PSK without a Cert file? -
Hi,
have you tried using the 'unsecure' MQTT port 1883?
Using this one you should not need a certificate or PSK.
BR