• 1000
//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 Не упоминаются события приема / передачи. Я не смог найти ни одного прерывания приема / передачи, или, возможно, я искал неправильный термин.