gpt4 book ai didi

cpu-usage - 测量 ESP32 CPU 利用率

转载 作者:行者123 更新时间:2023-12-02 03:06:41 28 4
gpt4 key购买 nike

我正在与连接到 Wifi 网络的两个 ESP32 板进行通信。一 block ESP32 板是服务器,另一 block 是客户端。我想测量客户端 ESP32 上的 ESP32 CPU 利用率。我不知道该怎么做,也没有在互联网上找到任何有用的资源。有人可以帮我解决这个问题吗?

这是服务器上的代码

#include <WiFi.h>
#include <ESPAsyncWebServer.h>
const char* ssid = "XXXXX";
const char* password = "XXXX";
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid,password);
while (WiFi.status()!= WL_CONNECTED){
delay(200);
Serial.println("Connecting to Wifi...");
}
Serial.println("Connected to Wifi");
Serial.println(WiFi.localIP());
server.on("/test", HTTP_GET, [](AsyncWebServerRequest *request){
Serial.println("Request received from esp32client");
request->send(200, "text/plain", "Hello from ESP32Server to ESP32Client");
});
server.on("/test1", HTTP_GET, [](AsyncWebServerRequest *request){
Serial.println("Request received from PC-Client");
request->send(300, "text/plain", "Hello from ESP32Server to PC");
});

server.begin();

}

void loop() {
// put your main code here, to run repeatedly:

}

这是客户端的代码

#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "XXXXX";
const char* password ="XXXXX";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid,password);
while (WiFi.status()!= WL_CONNECTED){
delay(500);
Serial.println("Connecting to Wifi...");
}
Serial.println("Connected to Wifi Network...");
Serial.println(WiFi.localIP());

}

void loop() {

HTTPClient http;

http.begin("http://192.168.43.35/test");
int httpCode = http.GET();

if (httpCode > 0) {

String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}

else {
Serial.println("Error on HTTP request");
}

http.end();

delay(30000);

}

最佳答案

使用该函数获取CPU负载

vTaskGetRunTimeStats(char *buffer);

它通过当前在 esp32 上运行的任务来告诉 CPU 利用率。

API文档here .

关于cpu-usage - 测量 ESP32 CPU 利用率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58857060/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com