我有一个 esp-32 cam Ai thinker board。我已使用 FTDI 将其连接到我的笔记本电脑。 现在,当我上传此代码时:
#include "esp_camera.h"
#include <WiFi.h>
#include <WiFiClientSecure.h>
// Define your WiFi credentials
const char* ssid = "mywifiId";
const char* password = "MyPass";
WiFiClientSecure client;
const char* host = "myproject.cognitiveservices.azure.com";
const int Port = 443;
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("WiFi connected.");
Serial.printf("Connecting to %s:%d... ", host, Port);
if (!client.connect(host, Port))
{
Serial.println("Failure in connection with the server");
}
}
void loop() {
}
此代码成功连接到wifi,但随后无法连接到服务器。 我的服务器主机是正确的,我仔细检查了。我使用Python的套接字库来测试与主机的连接。在我的笔记本电脑上使用 Python 中的套接字库成功建立了连接,但在 arduino ide wificlientsecure 中,我无法连接到服务器。 可能是什么问题,请帮我解决一下。基本上我正在连接到我的天蓝色主机。
我会将连接检查放在循环()内,有一点延迟,因为连接并不总是立即发生。
void loop() {
response = client.connect(host, Port)
Serial.println(response);
delay(2000);
}