Connecting sim800l module to Azure IoT Hub

i am try to connect my sim800l to azure MQTT but not connect broker(whma1.azure-devices.net) help me for same

15:44:32.934 -> [14090] ### TinyGSM Version: 0.11.5
15:44:32.934 -> [14090] ### TinyGSM Compiled Module: TinyGsmClientSIM800
15:44:33.253 -> [14407] ### Modem: SIMCOM SIM800L
15:44:33.253 -> [14407] ### Modem: SIMCOM SIM800L
15:44:35.261 -> Modem Info: SIM800 R14.18
15:44:35.261 -> Connecting to APN: [23058] ### Network time and time zone updated.
15:44:41.898 -> [23058] ### Daylight savings time state updated.
15:44:43.663 -> [24849] ### Network time zone updated.
15:44:43.663 -> [24855] ### Network time and time zone updated.
15:44:43.713 -> [24855] ### Daylight savings time state updated.
15:44:44.599 -> OK
15:44:44.644 -> GPRS connected
15:44:44.644 -> === MQTT NOT CONNECTED ===
15:44:44.644 -> Connecting to whma1.azure-devices.net[35147] ### Closed: 0
15:45:01.423 -> fail

#define TINY_GSM_MODEM_SIM800 // Modem is SIM800L

// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands
#define SerialAT Serial1

// Define the serial console for debug prints, if needed
#define TINY_GSM_DEBUG SerialMon

// set GSM PIN, if any
#define GSM_PIN ""

// Your GPRS credentials, if any
const char apn[] = ""; // APN (example: internet.vodafone.pt) use https://wiki.apnchanger.org
const char gprsUser[] = "";
const char gprsPass[] = "";

// SIM card PIN (leave empty, if not defined)
const char simPIN[] = "";

// MQTT details
//const char* broker = "40.77.64.56"; // Public IP address or domain name
//
//const char* topicTemperature = "esp/test";

const char* broker = "whma1.azure-devices.net";
const char* mqtt_user = "whma1.azure-devices.net/esp32";
const char* mqtt_pass = "SharedAccessSignature sr=whma1.azure-devices.net%2Fdevices%2Fesp32&sig=IX8GgNU3Hpt2wwkJn1MFn2VjSvmVUe66w2kGL9J2hAQ%3D&se=1663314510";

const char* topicTemperature = "esp/test";

// Define the serial console for debug prints, if needed
//#define DUMP_AT_COMMANDS

#include <Wire.h>
#include <TinyGsmClient.h>

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif

#include <PubSubClient.h>

TinyGsmClient client(modem);
PubSubClient mqtt(client);

// TTGO T-Call pins
#define MODEM_RST 5
#define MODEM_PWKEY 4
#define MODEM_POWER_ON 23
#define MODEM_TX 27
#define MODEM_RX 26
#define I2C_SDA 21
#define I2C_SCL 22

// BME280 pins
#define I2C_SDA_2 18
#define I2C_SCL_2 19

#define OUTPUT_1 2
#define OUTPUT_2 15

uint32_t lastReconnectAttempt = 0;

float temperature = 0;

long lastMsg = 0;

void mqttCallback(char* topic, byte* message, unsigned int len) {
Serial.print("Message arrived on topic: ");
Serial.print(topic);
Serial.print(". Message: ");
String messageTemp;

for (int i = 0; i < len; i++) {
Serial.print((char)message[i]);
messageTemp += (char)message[i];
}
Serial.println();
}

boolean mqttConnect() {
SerialMon.print("Connecting to ");
SerialMon.print(broker);

// Connect to MQTT Broker without username and password
// boolean status = mqtt.connect("GsmClientN");

// Or, if you want to authenticate MQTT:
boolean status = mqtt.connect("GsmClientN", mqtt_user, mqtt_pass);

if (status == false) {
SerialMon.println(" fail");
ESP.restart();
return false;
}
SerialMon.println(" success");

return mqtt.connected();
}

void setup() {
// Set console baud rate
SerialMon.begin(115200);
delay(10);

// Start I2C communication

// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, 33, 25);
delay(6000);

// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
// modem.init();

String modemInfo = modem.getModemInfo();
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);

// Unlock your SIM card with a PIN if needed
if ( GSM_PIN && modem.getSimStatus() != 3 ) {
modem.simUnlock(GSM_PIN);
}

SerialMon.print("Connecting to APN: ");
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(" fail");
ESP.restart();
}
else {
SerialMon.println(" OK");
}

if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}

// MQTT Broker setup
mqtt.setServer(broker, 8883);
mqtt.setCallback(mqttCallback);
}

void loop() {
if (!mqtt.connected()) {
SerialMon.println("=== MQTT NOT CONNECTED ===");
// Reconnect every 10 seconds
uint32_t t = millis();
if (t - lastReconnectAttempt > 10000L) {
lastReconnectAttempt = t;
if (mqttConnect()) {
lastReconnectAttempt = 0;
}
}
delay(100);
return;
}

long now = millis();
if (now - lastMsg > 30000) {
lastMsg = now;

Serial.print("Temperature: ");
mqtt.publish(topicTemperature, "HELLO");

}

mqtt.loop();
}

Installation and Troubleshooting is for Problems with the Arduino IDE itself NOT your project. It says so in the description of the section.

Therefore I have moved your post here. Please be more careful where you post in future.

You may want to read this before you proceed:-
how to get the best out of this forum

It is also best if you format your code correctly as well. It is all in the above link.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.