问题描述
我是物联网和AWS的新手,我在通过gsm模块与AWS MQTT交流时遇到了问题
首先,我通过一个示例,使用一个WIFI客户端,通过设置私有,根和证书,使用WIFI库与AWS MQTT进行通信
wiFiClient.setCACert(rootCA);// GSM security API or GSM x509 certificate
wiFiClient.setCertificate(certificate_pem_crt);
wiFiClient.setPrivateKey(private_pem_key);
但是现在我想使用GSM模块而不是wifi进行通信 那么有人可以帮助我如何使用GSM客户端而不是WIFI客户端设置这些x509代码吗?
换句话说,通过使用GSM模块来替代上述3行代码
如果有任何示例或文档或直接答案
在我的代码的一部分之后:
/* ESP32 AWS IoT
*
* Simplest possible example (that I Could come up with) of using an ESP32 with AWS IoT.
*
* Author: Anthony Elder
* License: Apache License v2
*/
//#include <WiFiClientSecure.h>
#include <PubSubClient.h> // install with Library Manager,I used v2.6.0
//const char* ssid = "Labospace";
//const char* password = "Labospace20";
const char* awsEndpoint = "myurl.us-east-2.amazonaws.com";
//*****Author: Saja Saleem
#include <Arduino.h> // arduino library (optional)
#include <DHTesp.h> // Library for DHT
#include <SPI.h> // Library for SPI communication
#include <TinyGPS++.h> // Library for GPS
#include <SoftwareSerial.h>
#include <DHT.h> // Library for DHT
#include "SD_File_Record.h" // Library with SD card functions
#include <ArduinoJson.h>
#define TINY_GSM_MODEM_SIM800 // deFinition of the modem used (SIM800L)
#include <TinyGsmClient.h> // library with GSM commands
HardwareSerial SerialGSM(1); // SIM800L serial communication object
TinyGsm modemGSM(SerialGSM); // library object with GSM functions
TinyGsmClient client(modemGSM);//Create TinyGSM client instances
#define DHTPIN 25 //D15 of ESP32 DevKit
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN,DHTTYPE);
TinyGPSPlus gps; // The TinyGPS object
static const uint32_t GPSBaud = 9600;
SoftwareSerial gpss(0,21); // The serial connection to the GPS device
String gpsData="";
// String that will be written to the txt file
String configLine,recordLine;
String reUpLoadData;
// serial speed of both the SIM800L and the serial monitor
const int BAUD_RATE = 9600;
// variables used to count time without crashing the loop function
// millis of reference
long int millisRefCon,millisUserResp;
// flag indicating the time count (used by the 'timeout' function)
bool flagCon = false,flagUserResp = false;
// pins where RX / TX where the SIM800L will be connected
const int RX_PIN = 2,TX_PIN = 4;
// ESP32-WROOM
#define TFT_DC 12 // A0
#define TFT_CS 13 // CS
#define TFT_MOSI 14 // SDA
#define TFT_CLK 27 // SCK
#define TFT_RST 0 // RESET
#define TFT_MISO 0 // MISO
const int MICROSD_PIN_CHIP_SELECT = 5; // Pino serial
const int MICROSD_PIN_MOSI = 23; // Pino serial
const int MICROSD_PIN_MISO = 19; // Pino serial
const int MICROSD_PIN_SCK = 18; // Clock pin
//Access point
const char *APN = "";
// User,if it doesn't exist,leave it empty
const char *USER = "";
// Password,if not,leave empty
const char *PASSWORD = "";
// number of cell phones,that will receive messages and calls and will be able to send SMS commands
String number = "+972593679079";
float temperature;
const int soundGate = 27;
float soundGateValue;
String arrOfStr [18];
String msg;
bool flag=true;
// Variable that stores an error message in the event of a problem with the SD card
String errorMsg;
// Instantiate an SD_File_Record object by sending the file name and the maximum size of the records (not counting the \ r \ r) in the constructor,that is,the actual size will be 3 + 2 = 5
SD_File_Record ObjSD( "s.txt");
//*****
// Update the two certificate strings below. Paste in the text of your AWS
// device certificate and private key. Add a quote character at the start
// of each line and a backslash,n,quote,space,backslash at the end
// of each line:
// xxxxxxxxxx-certificate.pem.crt
const char* certificate_pem_crt = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIDWjCCAkKgAwIBAgIVAIyLqQv38ap5b/mlN74946CuYoEIMA0GCSqGSIb3DQEB\n" \
"CwUAME0xSzBJBgNVBAsMQkFtYXpvbiBXZWIgU2VydmljZXMgTz1BbWF6b24uY29t\n" \
"IEluYy4gTD1TZWF0dGxlIFNUPVdhc2hpbmd0b24gQz1VUzAeFw0yMDA4MTkwMzIz\n" \
"MjFaFw00OTEyMzEyMzU5NTlaMB4xHDAaBgNVBAMME0FXUyBJb1QgQ2VydGlmaWNh\n" \
"dGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDlbSHE7CkQNwxB0Esk\n" \
"g2OSmRaORD4hcLsuSAEa1/7kxzWnvUFYUiVHNHF85Lmr/uf5fM6R0nfshd5ezemn\n" \
"9277Kl6ELSfxpqpHMSQwVT5G34GtJQhVsqN1lprYqCoaD7zBxtvsRBT4ovTvSGKF\n" \
"YX12c19shM1aaN3r8qxooYBKxKd0ViAjPinlNzXknEzzU9xc50kMdBkuLtNFIe4x\n" \
"RUPOPKmoNi/N0DxxW6wsXG4OMD6SKAMCo/z7jqm3pXQtHojLtmY7PXc/zQeb4Epj\n" \
"c6fiUA9oqSMB6SIWTVdvU/QstY0Fyrtmr6O2iGxeKTREU/WfJDrdVAOBIEofQaCe\n" \
"4H73AgMBAAGjYDBeMB8GA1UdIwQYMBaAFJLvcxjxXLvXCMCRWITgoz9wFW2LMB0G\n" \
"A1UdDgQWBBSBjEdVFqD43lzK8q85f4S70ig07jAMBgNVHRMBAf8EAjAAMA4GA1Ud\n" \
"DwEB/wQEAwIHgDANBgkqhkiG9w0BAQsFAAOCAQEAJJAFriwrAhAE2dh5mKisXwPo\n" \
"aRexLGO1Xn8x8hDMXF/COYyN+QXX7/+/gakG/gxCGXrxNVAflUJeNBvrP032DWUB\n" \
"dWKZKmpuy+wN3eDRXVYw5Q1eGJNYIhHPTuj/xUucGyhZjWfP2bed7ZbCQ9ZcxgsS\n" \
"0r2DolZ/0iYZsfsDEOp1dubkuVRWmDh8/4zrs9CC1dl6cZfsm3Z/y+9+1WiSDTgd\n" \
"194SlQqkpSA7Q27OyPcYUM399H8HMbL4NpfMF8S8x0N0LyKC72PZCU+zbQkxbs2q\n" \
"FA4vFGizf1HLL4pflUrUnzVMtuZ/KWlV7mTv9mP3cHlP6jIesLnucQTjTGfdOg\n" \
"//-----END CERTIFICATE-----\n";
// xxxxxxxxxx-private.pem.key
const char* private_pem_key = \
"-----BEGIN RSA PRIVATE KEY-----\n" \
".... my private key goes here ...\n" \
"-----END RSA PRIVATE KEY-----\n";
/* root CA can be downloaded in:
https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem
*/
const char* rootCA = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIDQTCCaimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n" \
"ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n" \
"b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\n" \
"MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n" \
"b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQocggEBALJ4gHHKeNXj\n" \
"ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n" \
"9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\n" \
"IFAGbHrQgLKm+a/sRxmpuDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\n" \
"VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L\n" \
"93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm\n" \
"jgSubjriqg0CAwEAAaNcmeAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC\n" \
"AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA\n" \
"A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5ipdb/G/wkjUu0yKGX9rbxenDI\n" \
"U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs\n" \
"N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv\n" \
"o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU\n" \
"5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n" \
"rqXRfboQnoZsG4q5WTP468SQvvG5\n" \
"-----END CERTIFICATE-----\n";
//WiFiClientSecure wiFiClient;
void msgReceived(char* topic,byte* payload,unsigned int len);
//PubSubClient pubSubClient(awsEndpoint,8883,msgReceived,wiFiClient);
void setup() {
Serial.begin(BAUD_RATE);
Serial.println("Starting...");
delay(50); Serial.println();
Serial.println("ESP32 AWS IoT Example");
Serial.printf("SDK version: %s\n",ESP.getSdkVersion());
/* Serial.print("Connecting to "); Serial.print(ssid);
WiFi.begin(ssid,password);
WiFi.waitForConnectResult();
Serial.print(",WiFi connected,IP address: "); Serial.println(WiFi.localIP());
wiFiClient.setCACert(rootCA);// GSM security API or GSM x509 certificate
wiFiClient.setCertificate(certificate_pem_crt);
wiFiClient.setPrivateKey(private_pem_key);
*/
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)