Can't connect to mqtt

So that I am telling you that hardware is working with Blynk is not enough?

did you try the tiny gsm code?

Blynk is using Tiny GSM and it works
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

    // Select your modem:
    #define TINY_GSM_MODEM_SIM800
    //#define TINY_GSM_MODEM_SIM900
    //#define TINY_GSM_MODEM_M590
    //#define TINY_GSM_MODEM_A6
    //#define TINY_GSM_MODEM_A7
    //#define TINY_GSM_MODEM_BG96
    //#define TINY_GSM_MODEM_XBEE

    // Default heartbeat interval for GSM is 60
    // If you want override this value, uncomment and set this option:
    //#define BLYNK_HEARTBEAT 30

    #define B1 V5
    #define B2 V6
    #define B3 V7
    #define B4 V8
    #define B5 V9

    #define TMP V4

    #define BLYNK_GREEN     "#23C48E"
    #define BLYNK_BLUE      "#04C0F8"
    #define BLYNK_YELLOW    "#ED9D00"
    #define BLYNK_RED       "#D3435C"
    #define BLYNK_DARK_BLUE "#5F7CD8"

    #include <TinyGsmClient.h>
    #include <BlynkSimpleTinyGSM.h>
    #include <OneWireSTM.h>

okay, let me check what is the issue here. Did the tiny gsm code worked ?

Your code above only has a setup function and no loop. What is in the loop?

So TINY_GSM work.
Initializing modem…
[3518] ### Unhandled: ⸮
[8172] ### TinyGSM Version: 0.7.9
[8570] ### Modem: SIMCOM SIM800L
[8570] ### Modem: SIMCOM SIM800L
Modem Info: SIM800 R14.18
Waiting for network… success
Network connected
Connecting to internet success
GPRS connected
[24265] ### Available: 0 on 1
=== MQTT NOT CONNECTED ===
Connecting to broker.hivemq.com[25578] ### Available: 0 on 1
[25881] ### Got Data: 1
[25931] ### Available: 4 on 1
[25984] ### READ: 4 from 1
success
[26144] ### Available: 0 on 1
[26646] ### Available: 0 on 1
[27145] ### Available: 0 on 1
[27648] ### Available: 0 on 1
[28147] ### Available: 0 on 1
[28649] ### Available: 0 on 1
[29150] ### Available: 0 on 1

And Blynk works too
[10131]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.6.1 on STM32F1

[10131] Modem init…
[11146] Connecting to network…
[17258] Network: UMC
[17258] Connecting to internet …
[22813] Connected to GPRS
[22821] Connecting to blynk-cloud.com:80
[23960] Ready (ping: 513ms).

And Cayenne is not working
[5450] Connected to GPRS
[5455] IP: 10.60.64.8
[5455] Connecting to mqtt.mydevices.com:1883
[36740] MQTT connect failed, error -1
[69945] MQTT connect failed, error -1

Just add your new MQTT credentials and upload the code. Dont change anything else.

/*
This example shows how to connect to Cayenne using a GSM device and send/receive sample data.
The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Install the TinyGSM library (https://github.com/vshymanskyy/TinyGSM) from the Arduino Library Manager.
2. Set the Cayenne authentication info to match the authentication info from the Dashboard.
3. Uncomment the correct GSM modem type and set the GSM connection info, if needed.
4. Compile and upload the sketch.
5. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/

#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

// Uncomment your modem type:
#define TINY_GSM_MODEM_SIM800
// #define TINY_GSM_MODEM_SIM808
// #define TINY_GSM_MODEM_SIM900
// #define TINY_GSM_MODEM_UBLOX
// #define TINY_GSM_MODEM_BG96
// #define TINY_GSM_MODEM_A6
// #define TINY_GSM_MODEM_A7
// #define TINY_GSM_MODEM_M590
// #define TINY_GSM_MODEM_ESP8266
// #define TINY_GSM_MODEM_XBEE

#include <CayenneMQTTGSM.h>

// This sketch uses a software serial connection.
#include <SoftwareSerial.h>
//SoftwareSerial gsmSerial(2, 3); // RX, TX
// If you are using a device that supports a hardware serial (Mega, Leonardo, etc.) and prefer to use
// that you can comment out the above lines and uncomment the one below.
#define gsmSerial Serial1

// GSM connection info.
char apn[] = ""; // Access point name. Leave empty if it is not needed.
char gprsLogin[] = ""; // GPRS username. Leave empty if it is not needed.
char gprsPassword[] = ""; // GPRS password. Leave empty if it is not needed.
char pin[] = ""; // SIM pin number. Leave empty if it is not needed.

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

void setup() {
	Serial.begin(9600);
	// Auto-detect the GSM serial baud rate. You can manually set it instead if you want to save a bit of space.
	TinyGsmAutoBaud(gsmSerial);
	Cayenne.begin(username, password, clientID, gsmSerial, apn, gprsLogin, gprsPassword, pin);
}

void loop() {
	Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
	// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
	Cayenne.virtualWrite(0, millis());
	// Some examples of other functions you can use to send data.
	//Cayenne.celsiusWrite(1, 22.0);
	//Cayenne.luxWrite(2, 700);
	//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
	//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}

[38306] MQTT connect failed, error -1
[70744] MQTT connect failed, error -1
[103502] MQTT connect failed, error -1
[135899] MQTT connect failed, error -1
[168640] MQTT connect failed, error -1
[201067] MQTT connect failed, error -1

I tested it on too diferent PCs with Arduino IDE

let me check what is the issue here.

i tried at my end with GSM 900 and arduino uno and it connected right away.

[14297] Initializing modem
[14935] Waiting for network
[15076] Connecting to GPRS
[70900] Connected to GPRS
[71050] IP: 100.72.125.31
[71050] Connecting to mqtt.mydevices.com:1883
[75288] Connected
[77513] Publish: topic 4, channel 65534, value Arduino Uno, subkey , key 
[77906] Publish: topic 6, channel 65534, value ATmega328P, subkey , key 
[78301] Publish: topic 7, channel 65534, value 16000000, subkey , key 
[78688] Publish: topic 5, channel 65534, value 1.3.0, subkey , key 
[79067] Publish: topic 8, channel 65534, value GSM, subkey , key 
[86514] Publish: topic 1, channel 0, value 86513, subkey , key 
[94327] Connection ok
[104952] Publish: topic 1, channel 0, value 104952, subkey , key 
[105690] Connection ok
[116314] Connection ok
[123398] Publish: topic 1, channel 0, value 123398, subkey , key

I am happy that you can. What a hell i need to do?

there is nothing you need to do or you can do. i am just testing if there is an issue on the cayenne side.

Are there any others Cayenne servers adresses to try?

i dont known what you mean by cayenne server address, but you can try

$ host mqtt.mydevices.com
mqtt.mydevices.com has address 34.236.59.34
mqtt.mydevices.com has address 34.206.242.200

Ок I figured out where my problem is. My Cellphone Operator somehow had blocked connection to mqtt server of Cayenne. I just inserted SIMcard of another operator, and everything is fine. I am sorry for being so rude and Thanks for your help.

1 Like

Glad to hear it is working now.