SIM800L and hivemq not working

Hello,
I am working on publishing data sensor from TTGO T-CALL SIM800L to hiveMQ.
Concerning hiveMQ public broker MQTT client, it is connected but it is not publishing data to the broker.


I also tried with the hiveMQ MQTT cloud but it did not connect.

I can’t undrstand what is the problem.

Best,

Hello @yassk ,

With a quick review of the connection details utilized here, it looks like we are using port 8884. Typically, this is the port configured for HiveMQ Cloud brokers for WebSocket connections, rather than traditional client TCP connections. Additionally, is this connection request also submitting an MQTT connection, or is this request just initiating a TCP connection to the provided address? In order to submit MQTT messages, both a TCP connection and the submission of an MQTT connection packet is required. More specifics on MQTT connectivity can be found in our essentials series, here.

Please verify if a connection via port 8883, and a submission of a connect packet, then publish requests offer proper MQTT traffic. Please note that HiveMQ Cloud brokers require a TLS connection, as well. Some devices may require a server CA cert in order to establish connectivity, and that can be found on our FAQ page here in the community forum. Additionally, if you have further questions or encounter additional roadblocks, please share as much of the TCP connection, MQTT connection, and publish code blocks as possible, obfuscating any private information, so we can diagnose further.

Best,
Aaron from the HiveMQ Team

Hello Aaron,

Thank you for your answer and I apologize for the late response.

In this connection it is submitting a TCP and MQTT connection.

It is true I was using the wrong port.

I have been reading FAQ and I figured out that a TSL connection is missed but I did not know how to. How can I get one ?

This is a sample of the code sending temperature from ttgo SIM800L to hivemq cloud :

//importing libraries
const char apn = “”;
const char gprsUser = “”;
const char gprsPass = “”;
const char simPIN = “”;

const char* mqtt_server = "********.s2.eu.hivemq.cloud";
const char
Topic_Temperature = “test/test”;

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

uint32_t lastReconnectAttempt = 0;

// I2C for SIM800 (to keep it running when powered from battery)
TwoWire I2CPower = TwoWire(0);
TwoWire I2CBME = TwoWire(1);
#define IP5306_ADDR 0x75
#define IP5306_REG_SYS_CTL0 0x00

#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

float temperature = 0;
long lastMsg = 0;

bool setPowerBoostKeepOn(int en){
I2CPower.beginTransmission(IP5306_ADDR);
I2CPower.write(IP5306_REG_SYS_CTL0);
if (en) {
I2CPower.write(0x37);
} else {
I2CPower.write(0x35);
}
return I2CPower.endTransmission() == 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(mqtt_server);

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

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

return mqtt.connected();
}

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

// Start I2C communication
I2CPower.begin(I2C_SDA, I2C_SCL, 400000);
I2CBME.begin(I2C_SDA_2, I2C_SCL_2, 400000);

// Set modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
SerialMon.println(“Wait…”);

// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(10000);

// 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(mqtt_server, 8883);
mqtt.setCallback(mqttCallback);

//*******************************
dht.begin();
}

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;

   float t = dht.readTemperature();
    if ( isnan(t) ) {
Serial.println(F("Failed to read from DHT sensor!"));
return;


// Convert the value to a char array
char tempString[8];
dtostrf(t, 1, 2, tempString);
Serial.print("Temperature: ");
Serial.println(tempString);
mqtt.publish(Topic_Temperature, tempString);

}

mqtt.loop();
}
}

====>
=== MQTT NOT CONNECTED ===
Connecting to *****.s2.eu.hivemq.cloudAT+CIPCLOSE=0,1

+CME ERROR: operation not allowed
AT+CIPSSL=0

OK
AT+CIPSTART=0,“TCP”,“***.s2.eu.hivemq.cloud”,8883

+CME ERROR: operation not allowed

Thank you
Best,

Hello @yassk ,

Based on the information provided, it looks as though we may be attempting an SSL connection, and receiving an ‘Operation not allowed’ error in response. In the code snippet above, it looks like we are using the TinyGSMClient. Reviewing some documentation and other users inquiries both here on the Community Forum and on Arduino forums, it looks like TinyGSMClient may not offer SSL/TLS support natively. This would prevent you from supplying the server or client certificates on the MQTT connection attempt, preventing a SSL/TLS connection.

That said, it does appear that there are some libraries that extend the features of TinyGSMClient, such as this public repository. Please keep in mind that this is not a library supported or maintained by HiveMQ, and as such, implementation details and configuration will best be handled through the repository or by repository contributors.

Once the MQTT connection request for this device is able to utilize TLS/SSL and provide certificates, the server certificate for HiveMQ Cloud Brokers can always be obtained on our Frequently Asked Questions page, or linked directly here.

Best,
Aaron from the HiveMQ Team

Hello Aaron,
Thank you for your answer.
I will consider that.

Hello @yassk were you able to figure out how to connect and send data to the hivemq broker? Im stuck on the same problem and i was wondering if you would be able to help me out.
Thank you!