-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error occured during connecting to TLS secured MQTT broker ( 34 – open SSL session failed) #99
Comments
AT+CMQTTCONNECT: 0,34 open SSL session failed refer to https://github.com/Xinyuan-LilyGO/T-SIM7600X/issues/49. In my case and your case its firmware and that it has deprecated Cyphers. |
Thank you for the reply. Do you have a supported firmware? |
There is none available that I am aware of for my exact model .... |
Hi Everyone,
I have tried to connect to mqqt.datacke.co broker which provides TLS-enabled security. In this process, I have downloaded the CA signed server certificate to the SIM7600 module and configure the server root CA of specified SSL context. Both these commands are returns successfully but SIM7600 module didn’t connect to the MQTT broker and it returns the error number 34 which identifies the error as open SSL session failed. In the below I have attached my code and screenshots of the results.
Firmware of the SIM7600 G-H module
Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM7600G-H
Revision: SIM7600M22_V2.0.1 (identification of firmware)
SVN: 01
+GCAP: +CGSM
Code
#include <Arduino.h>
#include <Wire.h>
#include <WiFi.h> // Include the WiFi library for MAC address
#include <ArduinoJson.h>
//#include "Secret.h" // Include the file to get the username and pasasword of MQTT server
#include"datacake.h"
String gsm_send_serial(String command, int delay);
#define SerialMon Serial
#define SerialAT Serial1
#define GSM_PIN ""
#define D0 36
#define D1 35
#define D2 32
#define D3 33
#define R0 4
// Your GPRS credentials, if any
const char apn[] = "dialogbb";
const char gprsUser[] = "";
const char gprsPass[] = "";
// MQTT details
String broker = "mqtt.datacake.co";
String MQTTport = "8883";
String username = "";
String password = "";
#define uS_TO_S_FACTOR 1000000ULL // Conversion factor for micro seconds to seconds
#define TIME_TO_SLEEP 60 // Time ESP32 will go to sleep (in seconds)
#define UART_BAUD 115200
#define MODEM_TX 23
#define MODEM_RX 18
#define GSM_RESET 34
#define MAC_ADDRESS_SIZE 18 // Assuming MAC address is in format "XX:XX:XX:XX:XX:XX"
byte mac[6];
String str_macAddress;
unsigned long prevMillis = 0;
const unsigned long interval = 60000; // Interval for sending messages
// Device-specific details
const char* deviceSerial = "34865D461830"; // Replace with your device serial
void Init(void); // Function prototype for network and GPRS initialization
void connectToGPRS(void); // Function prototype for GPRS connection
void connectToMQTT(void); // Function prototype for MQTT connection
bool isNetworkConnected(); // Function prototype to check if network is connected
bool isGPRSConnected(); // Function prototype to check if GPRS is connected
void mqttCallback(char* topic, byte* payload, unsigned int len) {
SerialMon.print("Message arrived [");
SerialMon.print(topic);
SerialMon.print("]: ");
SerialMon.write(payload, len);
SerialMon.println();
// Extract serial number from the topic
String topicStr = String(topic);
int firstSlash = topicStr.indexOf('/');
int lastSlash = topicStr.lastIndexOf('/');
String MAC_ID = topicStr.substring(firstSlash + 1, lastSlash);
SerialMon.print("MAC ID: ");
SerialMon.println(MAC_ID);
if (MAC_ID == deviceSerial) {
// Decode the received message
StaticJsonDocument<200> doc;
DeserializationError error = deserializeJson(doc, payload, len);
if(state == 0){
digitalWrite(R0,LOW);
}else if(state == 1){
digitalWrite(R0,HIGH);
}
} else {
SerialMon.println("Received message for a different serial number");
}
}
void setup() {
// Set console baud rate
Serial.begin(115200);
delay(10);
SerialAT.begin(UART_BAUD, SERIAL_8N1, MODEM_RX, MODEM_TX);
}
void loop() {
if (millis() - prevMillis >= interval) {
prevMillis = millis();
// StaticJsonDocument<200> doc;
// doc["D0"] = IN1 ? 1 : 0;
// doc["D1"] = IN2 ? 1 : 0;
// doc["D2"] = IN3 ? 1 : 0;
// doc["D3"] = IN4 ? 1 : 0;
// String jsonString;
// //char jsonBuffer[512];
// serializeJson(doc, jsonString);
str_macAddress.toUpperCase();
String Digital_input = "dtck-pub/dc_mqtt_broker/9ccc450d-96ec-4676-8e57-a3661bf528a6/D0";
}
void handleIncomingMessages() {
while (SerialAT.available()) {
String response = SerialAT.readStringUntil('\n');
response.trim();
}
void Init(void) {
delay(5000);
gsm_send_serial("AT+CFUN=1", 10000);
gsm_send_serial("AT+CPIN?", 10000);
gsm_send_serial("AT+CSQ", 1000);
gsm_send_serial("AT+CREG?", 1000);
gsm_send_serial("AT+COPS?", 1000);
gsm_send_serial("AT+CGATT?", 1000);
gsm_send_serial("AT+CPSI?", 500);
gsm_send_serial("AT+CGDCONT=1,"IP","dialogbb"", 1000);
gsm_send_serial("AT+CGACT=1,1", 1000);
gsm_send_serial("AT+CGATT?", 1000);
gsm_send_serial("AT+CGPADDR=1", 500);
gsm_send_serial("AT+NETOPEN", 500);
gsm_send_serial("AT+NETSTATE", 500);
}
void connectToGPRS(void) {
gsm_send_serial("AT+CGATT=1", 1000);
gsm_send_serial("AT+CGDCONT=1,"IP","dialogbb"", 1000);
gsm_send_serial("AT+CGACT=1,1", 1000);
gsm_send_serial("AT+CGPADDR=1", 500);
gsm_send_serial("AT+NETOPEN", 500);
gsm_send_serial("AT+NETSTATE", 500);
}
void connectToMQTT(void) {
// Upload the CA certificate
gsm_send_serial("AT+CCERTDELE="datacake_ca.pem"", 1000);
gsm_send_serial("AT+CCERTLIST", 1000);
//gsm_send_serial("AT+CCERTDOWN="datacake_ca.pem"," + String(strlen(mqtt_ca_cert)), 1000);
int cert_length = mqtt_ca_cert.length(); // Get the length of the CA certificate
// Construct the command string with the certificate length
String command5 = "AT+CCERTDOWN="datacake_ca.pem"," + String(cert_length);
gsm_send_serial(command5, 1000); // Send the command
// String command4 = mqtt_ca_cert + "\x1A";
gsm_send_serial(mqtt_ca_cert, 10000);
delay(10000);
gsm_send_serial("AT+CCERTLIST", 1000);
delay(1000);
//gsm_send_serial("AT+CSSLCFG=0", 1000);
gsm_send_serial("AT+CSSLCFG="sslversion",0,3", 1000);
gsm_send_serial(" AT+CSSLCFG="authmode",0,1", 1000);
// String downlinkTopic = "NORVI/+/OUTPUT";
// gsm_send_serial("AT+CMQTTSUB=0,14,1", 1000);
// gsm_send_serial(downlinkTopic + "\x1A", 1000);
// delay(2000);
}
bool isNetworkConnected() {
String response = gsm_send_serial("AT+CREG?", 3000);
return (response.indexOf("+CREG: 0,1") != -1 || response.indexOf("+CREG: 0,5") != -1);
}
bool isGPRSConnected() {
String response = gsm_send_serial("AT+CGATT?", 3000);
return (response.indexOf("+CGATT: 1") != -1);
}
String gsm_send_serial(String command, int delay) {
String buff_resp = "";
Serial.println("Send ->: " + command);
SerialAT.println(command);
long wtimer = millis();
while (wtimer + delay > millis()) {
while (SerialAT.available()) {
buff_resp += SerialAT.readString();
}
}
Serial.println(buff_resp);
return buff_resp;
}
Results
Thank You in Advance.
The text was updated successfully, but these errors were encountered: