使用芯片型号为ESP32-WROOM-32D,发送端为usb供电经过3.3V 1117 LDO压降。当我尝试通过ESP_NOW提供的esp_now_send()函数对多个目标ESP32芯片发送数据时,触摸感觉芯片发热温度烫手,虽然程序可以运行,但是还是想了解一下是否和我代码不够优化有关?另外相对应的我也有在同款芯片上跑过udp广播的代码,明显发热情况较ESP_NOW通信会轻很多。请问有没有减少功耗的方法?谢谢!
代码如下:
[Codebox]
#include <esp_now.h>
#include <WiFi.h>
//addresses
uint8_t broadcastAddress1[] = {0x24,0x4c,0xab,0x05,0xa3,0xe1};
uint8_t broadcastAddress2[] = {0x24,0x4c,0xab,0x05,0x71,0x81};
uint8_t broadcastAddress3[] = {0x24,0x4c,0xab,0x06,0xf2,0xf1};
uint8_t broadcastAddress4[] = {0x24,0x4c,0xab,0x06,0xdb,0xc9};
typedef struct test_struct {
int a1;
int a2;
int a3;
int a4;
} test_struct;
test_struct test;
String comdata = "";
int numdata[4] = {0, 0, 0, 0}, mark=0;
int databuffer[4] = {0, 0, 0, 0};
// callback when data is sent
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
char macStr[18];
Serial.print("Packet to: ");
// Copies the sender mac address to a string
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
Serial.print(macStr);
Serial.print(" send status:\t");
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("Error initializing ESP-NOW");
return;
}
esp_now_register_send_cb(OnDataSent);
// register peer
esp_now_peer_info_t peerInfo;
peerInfo.channel = 0;
peerInfo.encrypt = false;
// register first peer
memcpy(peerInfo.peer_addr, broadcastAddress1, 6);
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
// register second peer
memcpy(peerInfo.peer_addr, broadcastAddress2, 6);
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
// register third peer
memcpy(peerInfo.peer_addr, broadcastAddress3, 6);
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
// register fourth peer
memcpy(peerInfo.peer_addr, broadcastAddress4, 6);
if (esp_now_add_peer(&peerInfo) != ESP_OK){
Serial.println("Failed to add peer");
return;
}
}
void loop() {
int j = 0;
while (Serial.available() > 0)
{
//append read in character
comdata += char(Serial.read());
//delay a bit, otherwise will lose signal
delay(1);
//mark data has been read
mark = 1;
}
if(mark == 1) //if data received start parsing comdata, otherwise pass
{
int sign_neg = false;
/*******************main parsing logic*******************/
//traverse comdata
for(int i = 0; i < comdata.length() ; i++)
{
// split with comma
if(comdata == ',')
{
if(sign_neg==true)
{
databuffer[j] = -numdata[j];
sign_neg=false;
}
else
{
databuffer[j] = numdata[j];
}
j++;
}
else
{
if (comdata == '-')sign_neg=true;
else{
if ((comdata == '0'&&comdata[i+1]>='0'&&comdata[i+1]<='9')||comdata=='1'||comdata=='2'||comdata=='3'||comdata=='4'||comdata=='5'||comdata=='6'||comdata=='7'||comdata[i]=='8'||comdata[i]=='9')
{
numdata[j] = numdata[j] * 10 + (comdata[i] - '0');
}
}
}
}
// databuffer[3]=numdata[3];
// clear comdata
comdata = String("");
// open for next round data read-in
mark = 0;
}
//assign actuating signal
if (numdata[0]==0&&numdata[1]==0&&numdata[2]==0&&numdata[3]==0){
test.a1 = databuffer[0];
test.a2 = databuffer[1];
test.a3 = databuffer[2];
test.a4 = databuffer[3];
}
//clear numdata buff
numdata[0] = 0;
numdata[1] = 0;
numdata[2] = 0;
numdata[3] = 0;
esp_err_t result = esp_now_send(0, (uint8_t *) &test, sizeof(test_struct));
if (result == ESP_OK) {
Serial.println("Sent with success");
}
else {
Serial.println("Error sending the data");
}
Serial.println(comdata);
// char * s="";
// sprintf(s, "(%s)", comdata);
Serial.print("a1: ");
Serial.println(test.a1);
Serial.print("a2: ");
Serial.println(test.a2);
Serial.print("a3: ");
Serial.println(test.a3);
Serial.print("a4: ");
Serial.println(test.a4);
delay(1);
}
[/Codebox]
请教一下通过ESP_NOW发送数据时的发热问题
Re: 请教一下通过ESP_NOW发送数据时的发热问题
请问你解决功耗问题了吗,我也遇到了功耗太大的问题
-
- Posts: 2
- Joined: Thu Jul 07, 2022 3:16 am
Re: 请教一下通过ESP_NOW发送数据时的发热问题
你好我后来还是加风扇降温,问了很多人都说esp_now的功耗没法降
Who is online
Users browsing this forum: No registered users and 17 guests