esp32 - 在 ESP32 中运行主程序时如何通过 wifi 接收消息?
问题描述
我已经在一个微控制器程序(ESP32 Wroom32)中加入了我想要的多个功能,并且需要一些关于保持程序运行并在运行时接收消息的最佳方法的建议。
当前代码:
//includes and declarations
setup()
{
//setup up wifi, server
}
main(){
WiFiClient client = server.available();
byte new_command[40];
if (client) // If client object is created, a connection is setup
{
Serial.println("New wifi Client.");
String currentLine = ""; //Used to print messages
while (client.connected())
{
recv_byte = client.read();
new_command = read_incoming(&recv_byte, client); //Returns received command and check for format. If invalid, returns a 0 array
if (new_command[0] != 0) //Checks if message is not zero, None of valid messages start with zero
{
execute_command(new_command);
//new_command is set to zero
}
}//end of while loop
}//end of if loop
}
这样做的缺点是 ESP32 在准备好接收新消息之前一直等到命令执行完毕。希望 ESP32 接收命令并存储它们,并按照自己的节奏执行。我计划更改当前代码以在代码运行时接收消息,如下所示:
main()
{
WiFiClient client = server.available();
byte new_command[40];
int command_count = 0;
byte command_array[50][40];
if (command_count != 0)
{
execute_command(command_array[0]);
//Decrement command_count
//Shift all commands in command_array by 1 row above
//Set last executed command to zero
}
}//end of main loop
def message_interrupt(int recv_byte, WiFiClient& running_client)
{
If (running_client.connected())
{
recv_byte = running_client.read();
new_command = read_incoming(&recv_byte, running_client); //Returns received command and check for format. If invalid, returns a 0 array
//add new command to command_array after last command
//increment command_count
}
}
我使用哪个中断来接收消息并更新 command_array ?https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html未提及任何接收/传输事件。我也找不到任何接收/发送中断,或者我搜索了错误的术语。
解决方案
推荐阅读
- flutter - 无法构建 apk,firebase_admob 出错
- python - 如何将多个图像填充到包含它们的最小形状?
- xcode - Xcode 11 助手编辑器中未显示手动选项以及如何添加 IBOutlet?
- c# - 有没有办法从 .net API 的控制器打开/重定向到网站?
- linux - Linux - 查找文件夹更改时间是否大于 2 小时
- php - 带有 3 个实例的 AWS Elastic Beanstalk 上的 Laravel 验证错误为空
- java - 使用 json-simple (JAVA) 删除 JSON 文件的部分
- java - 我无法完美地将 Java 转换为 Kotlin
- python - 模拟 ldap 调用总是返回 True
- python - 从heroku服务器中的python脚本运行节点子进程