测量ESP32 CPU利用率

时间:2019-11-14 12:41:46

标签: cpu-usage esp32

我正在交流连接到Wifi网络的两个ESP32板。一个ESP32板是Server,另一个是客户端。我想评估客户端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);

}

1 个答案:

答案 0 :(得分:2)

使用此功能获取CPU负载

vTaskGetRunTimeStats(char *buffer);

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

API文档here