I am trying to connect to a MQTT server with my couple year old MKR 1400 (not sure how old exactly). I got the GSMSSLWebClient example working by editing line 124 of GSMClient.cpp to
MODEM.send("AT+USECPRF=0");
The code I am trying to get to work is an edited version of the ArduinoMQTTClient library example WiFiSimpleSender.
My server is getting the message, but it refuses the connection saying
1702044025: Client connection from 195.226.133.56 failed: error:0A0000C1:SSL routines::no shared cipher.
My previous tests with the MKR 1010 works, so I think it is something to do with the code on the GSM side. I am guessing I don't have the right SSL certificates?
The server uses LetsEncrypt.
Here is the code too:
/*
ArduinoMqttClient - WiFi Simple Sender
This example connects to a MQTT broker and publishes a message to
a topic once a second.
The circuit:
- Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board
This example code is in the public domain.
*/
#include <ArduinoMqttClient.h>
#include <MKRGSM.h>
#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = SECRET_PINNUMBER;
// APN data
const char GPRS_APN[] = SECRET_GPRS_APN;
const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN;
const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD;
GSMSSLClient client;
GPRS gprs;
GSM gsmAccess;
MqttClient mqttClient(client);
const char broker[] = "*******";
int port = 8883;
const char topic[] = "Tempdata";
const long interval = 15000;
unsigned long previousMillis = 0;
float SERIESRESISTOR = 9.87;
float TEMPERATURENOMINAL = 25.0;
float BCOEFFICIENT = 3540.0;
float thermistor = 0.0;
float THERMISTORNOMINAL = 10;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
Serial.println("Starting Arduino web client.");
// connection state
bool connected = false;
// After starting the modem with GSM.begin()
// attach the shield to the GPRS network with the APN, login and password
while (!connected) {
if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
(gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("You're connected to the network");
Serial.println();
// You can provide a unique client ID, if not set the library uses Arduino-millis()
// Each client must have a unique client ID
mqttClient.setId("pump-house-gsm");
// You can provide a username and password for authentication
//mqttClient.setUsernamePassword("****", "****");
mqttClient.setConnectionTimeout(30000);
Serial.print("Attempting to connect to the MQTT broker: ");
Serial.println(broker);
if (!mqttClient.connect(broker, port)) {
Serial.print("MQTT connection failed! Error code = ");
Serial.println(mqttClient.connectError());
while (1);
}
Serial.println("You're connected to the MQTT broker!");
Serial.println();
// set analog resulotion to 12
analogReadResolution(12);
}
void loop() {
// call poll() regularly to allow the library to send MQTT keep alives which
// avoids being disconnected by the broker
mqttClient.poll();
// to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay
// see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
/*Read analog outputof NTC module,
i.e the voltage across the thermistor */
float average = ((float)analogRead(A0) / 4095.0) * 3.3;
average = (average * SERIESRESISTOR) / (3.3 - average);
Serial.print("Thermistor resistance ");
Serial.println(average);
float steinhart;
steinhart = average / THERMISTORNOMINAL; // (R/Ro)
steinhart = log(steinhart); // ln(R/Ro)
steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro)
steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
steinhart = 1.0 / steinhart; // Invert
steinhart -= 273.15; // convert absolute temp to C
Serial.print("Temperature ");
Serial.print(steinhart);
Serial.println(" *C");
// save the last time a message was sent
previousMillis = currentMillis;
Serial.print("Sending message to topic: ");
Serial.println(topic);
Serial.print("The temperature is");
Serial.println(thermistor);
// send message, the Print interface can be used to set the message contents
mqttClient.beginMessage(topic);
mqttClient.print("The temperature is ");
mqttClient.print(steinhart);
mqttClient.endMessage();
Serial.println();
}
}