-
Notifications
You must be signed in to change notification settings - Fork 53
Closed
Labels
help wantedExtra attention is neededExtra attention is needed
Description
Hello, I am using sim7020 and esp32 to connect to AWS MQTT and I have used digitaldragon/SSLClient@1.1.10 for ssl encryption.
However, in the running process, I found that the certificate file cannot be read normally. I also refer to other people's relevant Settings for the certificate, and the relevant format is correct, but I do not know why the file cannot be read normally. I have used mqttfx to verify that the certificate is valid and can normally connect to AWS.
[ 6135][E][ssl__client.cpp:45] _handle_error(): [start_ssl_client():353]: (-2) BIGNUM - An error occurred while reading from or writing to a file
This is my code
#include <M5Atom.h>
#include "ATOM_DTU_NB.h"
#include <PubSubClient.h>
#include <TinyGsmClient.h>
#include <time.h>
#include <sys/time.h>
#include <SSLClient.h>
#include "ca_cert.h"
#define MQTT_BROKER "a31klw4qph0psl-ats.iot.us-east-2.amazonaws.com"
#define MQTT_PORT 8883
#define UPLOAD_INTERVAL 10000
#define mqtt_devid "44a8c4fe642442f19c71ac54ec18d20d" //client id
TinyGsm modem(SerialAT, ATOM_DTU_SIM7020_RESET);
TinyGsmClient tcpClient(modem);
SSLClient ssl_client(&tcpClient);
PubSubClient mqttClient(ssl_client);
void nbConnect(void);
// For read the MQTT events
void callback(char *topic, byte *payload, unsigned int length)
{
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++)
{
Serial.print((char)payload[i]);
}
Serial.println();
}
void log(String info) {
SerialMon.println(info);
}
// To connect to the broker
void reconnect()
{
// Loop until we're reconnected
while (!mqttClient.connected())
{
Serial.println("Attempting MQTT connection...");
// Attempt to connect
if (mqttClient.connect(mqtt_devid))
//if (client.connect(client_name))
{
Serial.println("-----------------------------------connected-----------------------");
// Once connected, publish an announcement...
// client.publish("outTopic", "hello world");
mqttClient.publish("devices/CHANGE_TO_DEVICE_NAME_AZURE_IOT_HUB/messages/events/","Test"); // Topic to publish telemetry
// ... and resubscribe
mqttClient.subscribe("$iothub/twin/PATCH/properties/desired/#"); //Topic to subscribe Device Twin
}
else
{
Serial.print("failed, rc=");
Serial.print(mqttClient.state());
Serial.println("...try again in 5 seconds");
delay(5000);
}
}
}
void setup() {
M5.begin(true, false, true);
Serial.println(">>ATOM DTU NB MQTT TEST");
SerialAT.begin(SIM7020_BAUDRATE, SERIAL_8N1, ATOM_DTU_SIM7020_RX,
ATOM_DTU_SIM7020_TX);
//log("rootca_data:"+String(root_ca));
//log("certificate_data:"+String(certificate_data));
//log("privatekey_data:"+String(privatekey_data));
ssl_client.setCACert(root_ca);
ssl_client.setCertificate(client_cert_pem_start);
ssl_client.setPrivateKey(client_key_pem_start);
nbConnect();
mqttClient.setServer(MQTT_BROKER, MQTT_PORT);
mqttClient.setCallback(callback);
}
void loop() {
// We maintain connectivity with the broker
if (!mqttClient.connected())
{
reconnect();
}
// We are listening to the events
mqttClient.loop();
delay(15000);
}
void nbConnect(void) {
unsigned long start = millis();
log("Initializing modem...");
while (!modem.init()) {
log("waiting...." + String((millis() - start) / 1000) + "s");
};
start = millis();
log("Waiting for network...");
while (!modem.waitForNetwork()) {
log("waiting...." + String((millis() - start) / 1000) + "s");
}
log("success");
}This is my log
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13964
load:0x40080400,len:3600
entry 0x400805f0
[ 1][D][ssl__client.cpp:206] ssl_init(): Init SSL
[ 17][D][esp32-hal-cpu.c:244] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
M5Atom initializing...OK
>>ATOM DTU NB MQTT TEST
[ 206][D][SSLClient.cpp:484] setCACert(): Set root CA
[ 206][D][SSLClient.cpp:498] setCertificate(): Set client CA
[ 209][D][SSLClient.cpp:513] setPrivateKey(): Set client PK
Initializing modem...
[ 225][E][esp32-hal-gpio.c:102] __pinMode(): Invalid pin selected
E (209) gpio: gpio_set_level(227): GPIO output gpio_num error
E (512) gpio: gpio_set_level(227): GPIO output gpio_num error
Waiting for network...
success
[ 5686][V][SSLClient.cpp:397] read(): This is the iClient->read() implementation
[ 5686][V][SSLClient.cpp:397] read(): This is the iClient->read() implementation
Attempting MQTT connection...
[ 5700][V][SSLClient.cpp:397] read(): This is the iClient->read() implementation
[ 5700][V][SSLClient.cpp:397] read(): This is the iClient->read() implementation
[ 5707][V][SSLClient.cpp:161] connect(): connect with CA
[ 5712][V][SSLClient.cpp:219] connect(): Connecting to a31klw4qph0psl-ats.iot.us-east-2.amazonaws.com:8883
[ 5722][V][SSLClient.cpp:220] connect(): Timeout value: 0
[ 5727][V][SSLClient.cpp:221] connect(): CA Certificate: Provided
[ 5733][V][SSLClient.cpp:222] connect(): Client Certificate: Provided
[ 5739][V][SSLClient.cpp:223] connect(): Private Key: Provided
[ 5745][V][ssl__client.cpp:291] start_ssl_client(): Free internal heap before TLS 328948
[ 5752][V][ssl__client.cpp:292] start_ssl_client(): Connecting to a31klw4qph0psl-ats.iot.us-east-2.amazonaws.com:8883
[ 5763][V][ssl__client.cpp:379] init_tcp_connection(): Client pointer: 0x3ffc1e70
[ 5994][E][ssl__client.cpp:382] init_tcp_connection(): Connection to server failed!
[ 5994][D][ssl__client.cpp:791] stop_ssl_socket(): Cleaning SSL connection.
[ 5997][D][ssl__client.cpp:795] stop_ssl_socket(): Stopping SSL client. Current client pointer address: 0x3ffc1e70
[ 6093][D][ssl__client.cpp:816] stop_ssl_socket(): Freeing SSL context. Current ssl_ctx address: 0x3ffb9d14
[ 6093][D][ssl__client.cpp:819] stop_ssl_socket(): Freeing SSL config. Current ssl_conf address: 0x3ffb9f34
[ 6101][D][ssl__client.cpp:822] stop_ssl_socket(): Freeing DRBG context. Current drbg_ctx address: 0x3ffba01c
[ 6110][D][ssl__client.cpp:825] stop_ssl_socket(): Freeing entropy context. Current entropy_ctx address: 0x3ffba06c
[ 6121][D][ssl__client.cpp:828] stop_ssl_socket(): Finished cleaning SSL connection.
[ 6128][D][ssl__client.cpp:249] cleanup(): Free internal heap after TLS 328948
[ 6135][E][ssl__client.cpp:45] _handle_error(): [start_ssl_client():353]: (-2) BIGNUM - An error occurred while reading from or writing to a file
[ 6148][V][SSLClient.cpp:232] connect(): Return value from start_ssl_client: 0
[ 6155][E][SSLClient.cpp:235] connect(): start_ssl_client failed: 0
[ 6161][D][SSLClient.cpp:90] stop(): Stopping ssl client
[ 6166][D][ssl__client.cpp:791] stop_ssl_socket(): Cleaning SSL connection.
[ 6173][D][ssl__client.cpp:795] stop_ssl_socket(): Stopping SSL client. Current client pointer address: 0x3ffc1e70
[ 6267][D][ssl__client.cpp:816] stop_ssl_socket(): Freeing SSL context. Current ssl_ctx address: 0x3ffb9d14
[ 6267][D][ssl__client.cpp:819] stop_ssl_socket(): Freeing SSL config. Current ssl_conf address: 0x3ffb9f34
[ 6275][D][ssl__client.cpp:822] stop_ssl_socket(): Freeing DRBG context. Current drbg_ctx address: 0x3ffba01c
[ 6284][D][ssl__client.cpp:825] stop_ssl_socket(): Freeing entropy context. Current entropy_ctx address: 0x3ffba06c
[ 6295][D][ssl__client.cpp:828] stop_ssl_socket(): Finished cleaning SSL connection.
failed, rc=-2...try again in 5 secondsReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed
