Код: Выделить всё
HTTP GET... failed, error: connection refused
< /code>
Вот эскиз: < /p>
#define TINY_GSM_MODEM_SIM7600
#include
#include
#include
#include
#define SerialMon Serial
#define SerialAT Serial1
// Set serial pins for GSM module
#define RXD2 27
#define TXD2 26
const char apn[] = "airtelgprs.com"; // Replace with your APN
const char user[] = ""; // APN username, if required
const char pass[] = ""; // APN password, if required
const char* server = "api.example.io";
const int port = 443;
const char* apiEndpoint = "/api/controller/GetMqttCredentials";
TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
void setup() {
SerialMon.begin(115200);
SerialAT.begin(115200, SERIAL_8N1, RXD2, TXD2);
// Restart modem
SerialMon.println("Initializing modem...");
if (!modem.restart()) {
SerialMon.println("Failed to restart modem");
return;
}
SerialMon.println("Modem initialized!");
// Connect to network
SerialMon.println("Connecting to network...");
if (!modem.waitForNetwork()) {
SerialMon.println("Network connection failed!");
return;
}
SerialMon.println("Network connected!");
// GPRS connection
SerialMon.println("Connecting to GPRS...");
if (!modem.gprsConnect(apn, user, pass)) {
SerialMon.println("GPRS connection failed!");
return;
}
SerialMon.println("GPRS connected!");
}
void loop() {
WiFiClientSecure wifiClient;
HTTPClient http;
// Construct URL
String url = String("https://") + server + apiEndpoint;
if (http.begin(wifiClient, url)) {
SerialMon.println("Starting HTTPS GET request...");
int httpCode = http.GET();
if (httpCode > 0) {
SerialMon.printf("HTTP GET... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK) {
String payload = http.getString();
SerialMon.println("Received payload:");
SerialMon.println(payload);
// Parse JSON
StaticJsonDocument doc;
DeserializationError error = deserializeJson(doc, payload);
...
}
} else {
SerialMon.printf("HTTP GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
} else {
SerialMon.println("Unable to connect");
}
delay(60000);
}
[*] библиотеки < /strong>:
- tinygsm для модема < /li>
< li>, httpclient из ядра ESP32Код: Выделить всё
WiFiClientSecure
Подробнее здесь: https://stackoverflow.com/questions/793 ... 0-module-a
Мобильная версия