Hello, ive been wanting to make my arduino mkr1400 connect to InfluxDB and send data there via POST.
However it seems like the InfluxDB cloud only accepts requests via HTTPS.
I implemented commands from the SSLCertificateManagement_Example.ino into GSMSSLWebClient.ino like this after adding the keys into arduino_secrets.h:
// libraries
#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;
// initialize the library instance
GSMSSLClient client;
GPRS gprs;
GSM gsmAccess(true);
// URL, path and port (for example: arduino.cc)
char server[] = "europe-west1-1.gcp.cloud2.influxdata.com";
int port = 443; // port 443 is the default for HTTPS
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
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);
}
}
client.eraseTrustedRoot();
client.setUserRoots(SECRET_GSM_ROOT_CERTS, SECRET_GSM_ROOT_SIZE);
client.setSignedCertificate(SECRET_CERT, "MKRGSM01", sizeof(SECRET_CERT));
client.setPrivateKey(SECRET_KEY, "MKRGSMKEY01", sizeof(SECRET_KEY));
client.useSignedCertificate("MKRGSM01");
client.usePrivateKey("MKRGSMKEY01");
client.setTrustedRoot("Let_s_Encrypt_Authority_X3");
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, port)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /api/v2 HTTP/1.1");
client.print("Host: europe-west1-1.gcp.cloud2.influxdata.com");
client.println();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.available() && !client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for (;;)
;
}
}
I looked at debug output from the modem and what looks suspicious to me is that the arduino sends "AT+USECMNG=2,0,"AddTrust_External_CA_Root"" command into the modem, however according to the documentation of the modem, the first parameter can only be 0,1 or 3.
Modem responds with "ERROR" as can be seen here:
17:29:52.168 -> Starting Arduino web client.
17:29:56.049 -> ⸮AT
17:29:56.234 -> OK
17:29:56.280 -> AT+IPR=921600
17:29:56.280 -> OK
17:29:56.374 -> AT
17:29:56.374 -> OK
17:29:56.374 -> AT+UPSV=3
17:29:56.374 -> OK
17:29:56.513 -> AT+CPIN?
17:29:56.513 -> ERROR
17:29:56.699 -> AT+CPIN?
17:29:56.699 -> ERROR
17:29:56.930 -> AT+CPIN?
17:29:56.930 -> +CPIN: READY
17:29:56.930 ->
17:29:56.930 -> OK
17:29:57.115 -> AT+CMGF=1
17:29:57.115 -> OK
17:29:57.300 -> AT+UDCONF=1,1
17:29:57.300 -> OK
17:29:57.532 -> AT+CTZU=1
17:29:57.532 -> OK
17:29:57.720 -> AT+UDTMFD=1,2
17:29:57.720 -> OK
17:29:57.905 -> AT+CREG?
17:29:57.905 -> +CREG: 0,0
17:29:57.905 ->
17:29:57.905 -> OK
17:29:58.138 -> AT+CREG?
17:30:03.976 -> +CREG: 0,1
17:30:03.976 ->
17:30:03.976 -> OK
17:30:04.208 -> AT+UCALLSTAT=1
17:30:04.208 -> OK
17:30:04.302 -> AT+CGATT=1
17:30:04.302 -> OK
17:30:04.488 -> AT+UPSD=0,1,"internet"
17:30:04.488 -> OK
17:30:04.718 -> AT+UPSD=0,6,3
17:30:04.718 -> OK
17:30:04.905 -> AT+UPSD=0,2,""
17:30:04.905 -> OK
17:30:05.091 -> AT+UPSD=0,3,""
17:30:05.138 -> OK
17:30:05.323 -> AT+UPSD=0,7,"0.0.0.0"
17:30:05.323 -> OK
17:30:05.507 -> AT+UPSDA=0,3
17:30:06.110 -> OK
17:30:06.297 -> AT+UPSND=0,8
17:30:06.342 -> +UPSND: 0,8,1
17:30:06.342 ->
17:30:06.342 -> OK
17:30:06.342 -> AT+USECMNG=2,0,"AddTrust_External_CA_Root"
17:30:06.342 -> ERROR
17:30:06.390 -> AT+USECMNG=2,0,"Baltimore_CyberTrust_Root"
17:30:06.390 -> ERROR
17:30:06.390 -> AT+USECMNG=2,0,"COMODO_RSA_Certification_Authority"
17:30:06.390 -> ERROR
17:30:06.437 -> AT+USECMNG=2,0,"DST_Root_CA_X3"
17:30:06.437 -> OK
17:30:06.484 -> AT+USECMNG=2,0,"DigiCert_High_Assurance_EV_Root_CA"
17:30:06.484 -> ERROR
17:30:06.484 -> AT+USECMNG=2,0,"Entrust_Root_Certification_Authority"
17:30:06.484 -> ERROR
17:30:06.531 -> AT+USECMNG=2,0,"Equifax_Secure_Certificate_Authority"
17:30:06.531 -> ERROR
17:30:06.531 -> AT+USECMNG=2,0,"GeoTrust_Global_CA"
17:30:06.531 -> ERROR
17:30:06.578 -> AT+USECMNG=2,0,"GeoTrust_Primary_Certification_Authority_G3"
17:30:06.578 -> ERROR
17:30:06.578 -> AT+USECMNG=2,0,"GlobalSign"
17:30:06.578 -> ERROR
17:30:06.625 -> AT+USECMNG=2,0,"Go_Daddy_Root_Certificate_Authority_G2"
17:30:06.625 -> ERROR
17:30:06.625 -> AT+USECMNG=2,0,"VeriSign_Class_3_Public_Primary_Certification_Authority_G5"
17:30:06.625 -> ERROR
17:30:06.672 -> AT+USECMNG=2,0,"AmazonRootCA1"
17:30:06.672 -> ERROR
17:30:06.672 -> AT+USECMNG=2,0,"Starfield_Services_Root_Certificate_Authority_G2"
17:30:06.718 -> ERROR
17:30:06.718 -> AT+USECMNG=0,1,"MKRGSM01",0
17:30:06.718 -> ERROR
17:30:06.764 -> AT+USECMNG=0,2,"MKRGSMKEY01",0
17:30:06.764 -> ERROR
17:30:06.764 -> AT+USECPRF=0,5,"MKRGSM01"
17:30:06.764 -> OK
17:30:06.810 -> AT+USECPRF=0,6,"MKRGSMKEY01"
17:30:06.810 -> OK
17:30:06.810 -> AT+USECPRF=0,3,"Let_s_Encrypt_Authority_X3"
17:30:06.810 -> OK
17:30:06.810 -> connecting...
17:30:06.856 -> AT+USECMNG=0,0,"DST_Root_CA_X3",846
>
17:30:07.041 -> +USECMNG: 0,0,"DST_Root_CA_X3","410352dc0ff7501b16f0028eba6f45c5"
17:30:07.041 ->
17:30:07.041 -> OK
17:30:07.041 -> AT+USECMNG=0,0,"Let_s_Encrypt_Authority_X3",1174
>
17:30:07.227 -> +USECMNG: 0,0,"Let_s_Encrypt_Authority_X3","b15409274f54ad8f023d3b85a5ecec5d"
17:30:07.227 ->
17:30:07.227 -> OK
17:30:07.366 -> AT+USOCR=6
17:30:07.366 -> +USOCR: 0
17:30:07.366 ->
17:30:07.366 -> OK
17:30:07.549 -> AT+USOSEC=0,1,0
17:30:07.549 -> OK
17:30:07.779 -> AT+USECPRF=0,0,1
17:30:07.779 -> OK
17:30:07.965 -> AT+USOCO=0,"europe-west1-1.gcp.cloud2.influxdata.com",443
17:30:09.874 -> ERROR
17:30:09.967 ->
17:30:09.967 -> +UUSOCL: 0
17:30:10.107 -> AT+USOCL=0
17:30:10.107 -> ERROR
17:30:10.107 -> connection failed
17:30:10.107 ->
17:30:10.107 -> disconnecting.
Did anyone encounter similar problem?
Is there any way how to fix this?