Need some basic advice on where I am going wrong.
Simply want to connect to xxx.s1.eu.hivemq.cloud 8883 have it working on 1883
Similar to this link
Code
boolean mqttConnect() //boolean true or false
{
SerialMon.print("Connecting to ");
SerialMon.println(broker);
SerialMon.println(""); //add CR
// Connect to MQTT Broker
//boolean status = mqtt.connect("xxxx"); //works 1883
// Or, if you want to authenticate MQTT:
// boolean status = mqtt.connect("xxxx", "xxxx", "xxxx"); //doesnt work 8883
//List files in SPIFFS e.g., isrgrootx1.pem
ListFilesSPIFFS(); //Only list when booting
String serverAddress = "xxxx.s1.eu.hivemq.cloud";
int serverPort = 8883;
int keepAliveSeconds = 60;
int cleanSession = 1;
String username = "xxxx";
String password = "xxxxx";
// Set SSL version and authentication mode
modem.sendAT("+CSSLCFG=\"sslversion\",0,4"); //ALL Set the SSL version of the first SSL context
if (!modem.waitResponse(1000)) {
Serial.println("CSSLCFG command failed");
return false;
}
modem.sendAT("+CSSLCFG=\"authmode\",0,1"); //Server authentication. It needs the root CA of the serverSet the authentication mode(verify server) of the first SSL context
if (!modem.waitResponse(1000)) {
Serial.println("CSSLCFG command failed");
return false;
}
// modem.sendAT("+CSSLCFG=\"ignoreltime\",0,1"); //1 – ignore time check for certification default is 1
// if (!modem.waitResponse(1000)) {
// Serial.println("CSSLCFG command failed");
// return false;
// }
// Set server root CA
modem.sendAT("+CSSLCFG=\"cacert\",0,\"isrgrootx1.pem\""); //Set the server root CA of the first SSL context
if (!modem.waitResponse(1000)) {
Serial.println("CSSLCFG command failed");
return false;
}
/*
// Set client cert
modem.sendAT("+CSSLCFG=\"clientcert\",0,\"clientcert.pem\""); //Set the client cert
if (!modem.waitResponse(1000)) {
Serial.println("CSSLCFG command failed");
return false;
}
// Set client cert
modem.sendAT("+CSSLCFG=\"clientkey\",0,\"clientkey.pem\""); //Set the clientkey
if (!modem.waitResponse(1000)) {
Serial.println("CSSLCFG command failed");
return false;
}
*/
// Set client cert
modem.sendAT("+CSSLCFG?");
if (!modem.waitResponse(1000)) {
Serial.println("CSSLCFG command failed");
return false;
}
// Start MQTT service and activate PDP context
modem.sendAT("+CMQTTSTART");
if (!modem.waitResponse(1000)) {
Serial.println("MQTT START command failed");
return false;
}
// Acquire a client
modem.sendAT("+CMQTTACCQ=0,\"client1\",1,4"); //1 MQTT server with SSL/TLS 4 MQTT version 3.1.1
if (!modem.waitResponse(1000)) {
Serial.println("MQTT ACCQ command failed");
return false;
}
// Set the first SSL context to be used in the SSL connection
modem.sendAT("+CMQTTSSLCFG=0,0");
if (!modem.waitResponse(1000)) {
Serial.println("MQTT SSLCFG command failed");
return false;
}
// Connect to MQTT server
//String mqttConnectCommand = "AT+CMQTTCONNECT=0,\"ssl://" + serverAddress + ":" + String(serverPort) + "\"," + String(keepAliveSeconds) + "," + String(cleanSession) + ",\"" + username + "\",\"" + password + "\"";
String mqttConnectCommand = "AT+CMQTTCONNECT=0,\"tcp://" + serverAddress + ":" + String(serverPort) + "\"," + String(keepAliveSeconds) + "," + String(cleanSession) + ",\"" + username + "\",\"" + password + "\"";
boolean status = SerialAT.print(mqttConnectCommand);
if (status == false) {
SerialMon.println("MQTT Connect fail");
return false;
}
SerialMon.println("MQTT Connect success");
Logs
19:09:29.401 -> AT+NETOPEN?
19:09:29.401 ->
19:09:29.401 -> +NETOPEN: 1
19:09:29.448 ->
19:09:29.448 -> OK
19:09:29.448 -> AT+IPADDR
19:09:29.494 ->
19:09:29.494 -> +IPADDR: xx.xx.xx.xx
19:09:29.541 ->
19:09:29.541 -> OK
19:09:29.541 -> Connecting to xxxx.s1.eu.hivemq.cloud
19:09:29.541 ->
19:09:29.728 -> File: /isrgrootx1.pem Size: 1939
19:09:29.774 -> AT+CSSLCFG="sslversion",0,4
19:09:29.774 ->
19:09:29.774 -> OK
19:09:29.774 -> AT+CSSLCFG="authmode",0,1
19:09:29.774 ->
19:09:29.821 -> OK
19:09:29.821 -> AT+CCERTLIST
19:09:29.821 ->
19:09:29.821 -> OK
19:09:29.821 -> AT+CCERTDOWN="data/isrgrootx1.pem"1939
19:09:29.868 ->
19:09:29.868 -> ERROR
19:09:29.868 -> AT+CSSLCFG="cacert",0,"isrgrootx1.pem"
19:09:29.868 ->
19:09:29.868 -> ERROR
19:09:29.914 -> AT+CSSLCFG?
19:09:29.914 ->
19:09:29.914 -> +CSSLCFG: 0,4,1,1,300,"","","",0,"",0x0
19:09:30.009 -> +CSSLCFG: 1,4,0,1,300,"","","",0,"",0x0
19:09:30.103 -> +CSSLCFG: 2,4,0,1,300,"","","",0,"",0x0
19:09:30.150 -> +CSSLCFG: 3,4,0,1,300,"","","",0,"",0x0
19:09:30.244 -> +CSSLCFG: 4,4,0,1,300,"","","",0,"",0x0
19:09:30.336 -> +CSSLCFG: 5,4,0,1,300,"","","",0,"",0x0
19:09:30.429 -> +CSSLCFG: 6,4,0,10,1,CSSLCFG command failed
19:09:30.989 -> AT+CGREG?
19:09:31.035 ->
19:09:31.035 -> +CGREG: 0,1
So my questions are this
When compiling and writing the sketch to the ESP32/SIM7600 uploaded the /data/isrgrootx1.pem file which you can see listed as /isrgrootx1.pem in the logs confirming its located on SPIFFS. So to me I dont have the cert on the module? I know its located in SPIFFS can see it and the size.
Also used MQTT Explorer and set the same isrgrootx1.pem CERT with both validate cert and TLS enabled so I know the CERT works.