Wifi卡死

RTL8721D[Driver]: skb_unavailable=1 in last 2 seconds

RTL8721D[Driver]: skb_unavailable=1 in last 2 seconds

log口打印出来这个两个日志后,wifi和client的访问就变奇怪了,client.connected()会返回正常,但是client.available()会返回失败。

您好 @oxygenben,

感謝您使用 Ameba 開發板。

我想了解一下,您遇到這個問題是在什麼情況下?
如果可能的話,是否可以提供一些程式碼,以便我重現這個問題?謝謝!

#include <WiFi.h>
#include "FreeRTOS.h"
#include "task.h"
#include "sys_api.h"
// global variables
//#define XIAONING
#define WIFI_VERSION  0x04

TaskHandle_t Handle_ClientTask;
TaskHandle_t Handle_FcTask;

char ssid[12] = "Floor4_Test_5G";      // your network SSID (name)
char pass[] = "floor4123";           // your network password (use for WPA, or use as key for WEP)
IPAddress server(192,168,1,116);    // numeric IP for Google (no DNS)

int keyIndex = 0;                   // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
int wifi_disconnect_count=0;
int server_disconnect_count=0;
int cp_result=0;
int ssid_result=0;
int client_maybe_fail_count =0;
int loss_link_count =0;
WiFiClient client;
int try_time=0;
uint8_t version_buff[8] = {0xEE,0x16,0xFF,WIFI_VERSION,0x00,0x00,0xDA,0x1E};
long real_rssi=0;
uint8_t err_state=0;
int reinit_net_thread_count = 0;
int net_thread_running = 0;


void printWifiStatus() {
    // print the SSID of the network you're attached to:
    Serial.print("SSID: ");
    Serial.println(WiFi.SSID());

    // print your WiFi shield's IP address:
    IPAddress ip = WiFi.localIP();
    Serial.print("IP Address: ");
    Serial.println(ip);

    // print the received signal strength:
    real_rssi = WiFi.RSSI();
    Serial.print("signal strength (RSSI):");
    Serial.print(real_rssi);
    Serial.println(" dBm");
}

void threadClient(void* pvParameters) {
    int client_len =0;
    int result = 0;
    uint8_t client_buff[2048]={0};
    (void) pvParameters;
    for (;;) 
    {
        reinit_net_thread_count = 0;
        if(WL_CONNECTED != WiFi.status())
        {
            wifi_disconnect_count++;
            err_state |= 0x01;
            result = 0;
            status = WiFi.begin(ssid, pass);
            delay(10000);
            for(int i =0;i<2;i++)
            {
                if(WL_CONNECTED == WiFi.status())
                {
                    client.stop();
                    if (client.connect(server, 8888))
                    {
                        Serial.println("connected to server");
                        result = 100;
                        break;
                    }
                    else
                    {
                        delay(1000);
                    }
                }
                Serial.print("Try ");
                Serial.print(i+1);
                Serial.println(" times to reconnect wifi&server!");
            }
            if(100 == result) 
            {
                Serial.print("SSID: ");
                Serial.println(WiFi.SSID());
                real_rssi = WiFi.RSSI();
                Serial.print("signal strength (RSSI):");
                Serial.print(real_rssi);
                Serial.println(" dBm");
                Serial.println("Succeed reconnect wifi&server!");
            }
            else
            {
                Serial.println("Failed reconnect wifi&server!");
            }
            loss_link_count =0;
        }
        //优先连接5G
        else
        {
            // if the server's disconnected, stop the client:
            if (!client.connected()) 
            {
                err_state |=0x02;
                server_disconnect_count++;
                Serial.println("Server(exit) reconnect!");
                client.stop();
                delay(1000);
                if (client.connect(server, 8888))
                {
                    Serial.println("Succeed reconnected to server(exit)");
                }
                else
                {
                    delay(1000);
                }
                Serial.println("loss link");
                loss_link_count =0;
            }
            else if(client.available())
            {
                err_state &=0xF8;
                client_maybe_fail_count=0;
                client_len = client.read(client_buff,1540);
                Serial1.write(client_buff,client_len);
                Serial.print("net:");
                Serial.println(client_len);
                loss_link_count = 0;
                net_thread_running = 1;
            }
            else
            {
                loss_link_count++;
                if(loss_link_count > 200)
                {
                    err_state |=0x04;
                    Serial.println("Server(unplug) reconnect!");
                    client.stop();
                    if (client.connect(server, 8888))
                    {
                        Serial.println("Succeed reconnect to server(unplug)");
                    }
                    delay(1000);
                    loss_link_count = 0;
                }
                delay(10);
            }
        }
    }
}

void threadFc(void* pvParameters) {
    int recv_length;
    uint8_t recv_buff[1024];
    uint8_t send_data[1024];
    (void) pvParameters;
    for (;;) 
    {
        recv_length = Serial1.available();
        if(recv_length>0)
        {
            printf("c_u:%d ",recv_length);
            Serial1.readBytes(recv_buff,recv_length);
            memcpy(send_data,recv_buff,recv_length);
            client.write(send_data,recv_length);
        }
        else
        {
            delay(5);
        }
    }
}

void setup() {
    static uint16_t crc=0;

    //Initialize serial and wait for port to open:
    Serial.begin(115200);
    Serial1.begin(2000000);
    while (!Serial) {
        ;
    }
    // check for the presence of the shield:
    if (WiFi.status() == WL_NO_SHIELD) {
        Serial.println("WiFi shield not present");
        // don't continue:
        while (true);
    }

    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to SSID: ");
        Serial.println(ssid);
        // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
        status = WiFi.begin(ssid, pass);
        try_time++;
        Serial.print("\r\nTry ");
        Serial.print(try_time);
        Serial.println(" times");
        // wait 9 seconds for connection:
        Serial1.write(version_buff,6);
        delay(1000);
        Serial1.write(version_buff,6);
        delay(1000);
        Serial1.write(version_buff,6);
        delay(1000);
        if(try_time>=3) break;
    }
    if(3 <= try_time)
    {
      Serial.println("First Connected Failed");
    }
    delay(100);
    xTaskCreate(threadClient, "Task Client", 4096, NULL, tskIDLE_PRIORITY + 2, &Handle_ClientTask);
    xTaskCreate(threadFc, "Task Fc", 4096, NULL, tskIDLE_PRIORITY + 3, &Handle_FcTask);
}

void loop() {
    //idel task
    delay(2000);
    Serial.print("wifi dis: ");
    Serial.print(wifi_disconnect_count);
    Serial.print(" ,server dis: ");
    Serial.print(server_disconnect_count);
    Serial.print(" ,version: ");
    Serial.print(WIFI_VERSION,DEC);
    Serial.print(" ,ssid: ");
    Serial.print(WiFi.SSID());
    Serial.print(" ,rssi: ");
    real_rssi = WiFi.RSSI();
    Serial.print(real_rssi);
    Serial.print(" ,err: 0x");
    Serial.println(err_state,HEX);
}

这个是全部的代码,用的板子是AMB23,主要是把192.168.1.116:8888发的数据(一包1024Kb大小,频率是10Hz),转发给串口,串口接收到数据后会回128字节的数据,然后再把这个串口数据发往192.168.1.116:8888。
有时候测试1min就会出现,有时候要3h才会出现。

好的, 謝謝。我這裏會試著重現問題。有什麽進展會再通知您 :slight_smile:

您好,想請教一下,您是否有完整的 log 能讓我參考? 您的程式碼是否有參考哪些 Ameba 的範例嗎?