GPRS上的esp32 x509至AWS MQTT8883

如何解决GPRS上的esp32 x509至AWS MQTT8883

我是物联网和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" \
"MjFaFw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xxxxxxxx-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 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-