Bad Wifi connection

Hello,
I just did a speed test with my Muse Luxe. I wrote a very simple Arduino sketch. It connects to my access point and sends 4MB of data by client TCP. On the other side, I have a TCP server (a simple node.js script)
I have very random results (between 10 and 200 kb/s) and very regularly quite long outages (several seconds).

I did the same test with a WROOM dev kit and with the Lyra-T board, I get stable speeds around 650 kb/s.

Do you observe the same behavior?

I tried on different channels, but I always observe the same thing.

Fred

please share your code so I can try it too

Arduino sketch

#include <WiFi.h>
#include "museWrover.h"

const char *ssid = "yourSSID";          // Change this to your WiFi SSID
const char *password = "yourPassword";  // Change this to your WiFi password

// Serveur TCP
const char* serverIP = "192.168.8.199";   // IP du serveur
const uint16_t serverPort = 8765;         // Port du serveur

WiFiClient client;
uint32_t timestamp = 0;
uint8_t buffer[1436];  
int counter  = 0;
int octet  = 0;

void setup() {
    Serial.begin(115200);
    delay(1000);

    gpio_reset_pin(GPIO_PA_EN);
    gpio_set_direction(GPIO_PA_EN, GPIO_MODE_OUTPUT);
    gpio_set_level(GPIO_PA_EN, LOW);

    // Connexion au WiFi
    Serial.print("Connexion à ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("\nWiFi connecté !");
    Serial.print("Adresse IP : ");
    Serial.println(WiFi.localIP());

    // Connexion au serveur TCP
    Serial.print("Connexion à ");
    Serial.print(serverIP);
    Serial.print(":");
    Serial.println(serverPort);

    if (client.connect(serverIP, serverPort)) {
        Serial.println("Connexion réussie !");
        
        // Envoyer un message au serveur
        client.println("Hello, serveur !");
    } else {
        Serial.println("Échec de connexion !");
    }

    timestamp = millis();
}


void loop() {

      client.write(buffer, sizeof(buffer));
      
      counter++;
      octet += sizeof(buffer);

      if (octet > (4 * 1024 * 1024))
      {
        Serial.println("STOP 4 MO");

       Serial.print("     DEBIT (ko/s): ");
       int nb_sec = (millis() - timestamp) / 1000;
       Serial.println((4 * 1024) / nb_sec);

        delay(1000000);
      }
}

TCP server (node.js)

import net from "net";

async function main(argv) {

    if (argv.length == 2) {
        console.error('Expected host');
        process.exit(1);
    }

    const host = argv[2];
    const PORT = 8765;
    
    console.log("Host: ", host);

    // Démarrage du serveur TCP
    const server = net.createServer( async (socket) => {
        console.log('Client connecté.');

        var counter = 0;
        var totalSize = 0;
        var counterTrame = 0;
        socket.on('data', async (data) => {
            console.log('Message received: size=', data.length, '     toalSize=', totalSize, '     toalSizeKo=', parseInt(totalSize/1024), '    PaketCounter=', counterTrame);
            totalSize += data.length;
            counterTrame++;
        });

        // Fermeture de la connexion
        socket.on('end', () => {
            console.log('Client déconnecté.');
        });

        // Fermeture de la connexion
        socket.on('error', (err) => {
            console.error("Erreur serveur :", err.message);
        });
    });

    server.listen(PORT, host, () => {
        console.log(`Serveur TCP en écoute sur ${host}:${PORT}`);
    });
    
    server.on("error", (err) => {
        console.error("Erreur serveur :", err.message);
    });
}

await main(process.argv);

So my intuition is that it is related to the Wi-Fi channel used by your Muse and the channel occupancy in your wireless environment. To compare apples to apples, you should try all different channels. I find very different data rates depending on the environment (many Wi-Fi APs around) and the channel, which is why it is hard to make a definitive measurement.

That being said, I do recognize that the WROVER kit generally has a better data rate. This is probably due to the fact that the board is exposed, far from speakers and the battery, unlike the Muse. That being said, I have ordered a bunch of antennas to check if there are better options, as it is possible to open the Luxe and change the IPEX antenna.

Here is the code by channel working with your server :slightly_smiling_face:


#include <WiFi.h>

// WiFi credentials and server info
const char *ssid     = "yourwifi";
const char *password = "yourpasswd";
const char* serverIP = "ip of the node js server";
const uint16_t serverPort = 8765;

WiFiClient client;
uint8_t buffer[1436];  // buffer to send
int counter = 0;
int octet   = 0;

// This function connects to the WiFi network on a specific channel,
// then sends 4 MB of data and prints the transfer rate.
void measureChannel(int channel) {
  // If connected, disconnect first.
  if (WiFi.status() == WL_CONNECTED) {
    WiFi.disconnect();
    delay(1000);
  }
  
  Serial.print("Connecting on channel ");
  Serial.println(channel);
  // Note: WiFi.begin(ssid, password, channel) forces connection on the given channel.
  WiFi.begin(ssid, password, channel);
  
  // Wait for connection (you might want to add a timeout in a real application)
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("WiFi connected!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  
  // Connect to the server.
  Serial.print("Connecting to server ");
  Serial.print(serverIP);
  Serial.print(":");
  Serial.println(serverPort);
  if (client.connect(serverIP, serverPort)) {
    Serial.println("Server connection successful!");
    client.println("Hello, serveur !");
  } else {
    Serial.println("Failed to connect to server!");
    return;
  }
  
  // Reset counters and record the start time.
  uint32_t timestamp = millis();
  counter = 0;
  octet   = 0;
  
  // Send data until 4 MB have been transferred.
  while (octet < (4 * 1024 * 1024)) {
    client.write(buffer, sizeof(buffer));
    counter++;
    octet += sizeof(buffer);
  }
  
  // Calculate elapsed time (in seconds) and the transfer rate (in kilobytes per second).
  int nb_sec = (millis() - timestamp) / 1000;
  if (nb_sec == 0) nb_sec = 1;  // avoid division by zero
  Serial.print("Channel ");
  Serial.print(channel);
  Serial.print(" Transfer Rate (ko/s): ");
  Serial.println((4 * 1024) / nb_sec);
  
  // Close the connection and disconnect from WiFi.
  client.stop();
  WiFi.disconnect();
  delay(2000); // small pause before trying the next channel
}

void setup() {
  Serial.begin(115200);
  delay(1000);


  
  // For each channel (here, 1 to 11), measure the transfer rate.
  // Adjust the range as needed (e.g. channels 1-14 in some regions).
  for (int ch = 1; ch <= 11; ch++) {
    Serial.println("========================================");
    measureChannel(ch);
  }
  
  // Optionally, you can restart the measurement cycle or do nothing in loop().
}

void loop() {
  // Do nothing; all work is done in setup().
}

just found something interesting, lowering the transmission power seems to help with better datarate and realiability :

#include “esp_wifi.h” // Include ESP-IDF WiFi control functions

Serial.println(“WiFi connected!”); //add this after connected
esp_wifi_set_max_tx_power(15); // Reduce emission power to 15 dBm

12:10:26.714 → Connecting on channel 1
12:10:27.324 → .
12:10:27.324 → WiFi connected!
12:10:27.324 → IP address: 192.168.10.110
12:10:27.324 → Connecting to server 192.168.10.158:8765
12:10:27.324 → Server connection successful!
12:10:34.843 → Channel 1 Transfer Rate (ko/s): 585
12:10:36.829 → ========================================
12:10:36.829 → Connecting on channel 2
12:10:37.344 → .
12:10:37.344 → WiFi connected!
12:10:37.344 → IP address: 192.168.10.110
12:10:37.344 → Connecting to server 192.168.10.158:8765
12:10:37.344 → Server connection successful!
12:10:45.718 → Channel 2 Transfer Rate (ko/s): 512
12:10:47.737 → ========================================
12:10:47.737 → Connecting on channel 3
12:10:48.214 → .
12:10:48.214 → WiFi connected!
12:10:48.214 → IP address: 192.168.10.110
12:10:48.214 → Connecting to server 192.168.10.158:8765
12:10:48.248 → Server connection successful!
12:10:56.488 → Channel 3 Transfer Rate (ko/s): 512
12:10:58.507 → ========================================
12:10:58.507 → Connecting on channel 4
12:10:58.987 → .
12:10:58.987 → WiFi connected!
12:10:58.987 → IP address: 192.168.10.110
12:10:58.987 → Connecting to server 192.168.10.158:8765
12:10:59.021 → Server connection successful!
12:11:07.088 → Channel 4 Transfer Rate (ko/s): 512
12:11:09.103 → ========================================
12:11:09.103 → Connecting on channel 5
12:11:09.618 → .
12:11:09.618 → WiFi connected!
12:11:09.618 → IP address: 192.168.10.110
12:11:09.618 → Connecting to server 192.168.10.158:8765
12:11:09.618 → Server connection successful!
12:11:17.931 → Channel 5 Transfer Rate (ko/s): 512
12:11:19.953 → ========================================
12:11:19.953 → Connecting on channel 6
12:11:20.431 → .
12:11:20.431 → WiFi connected!
12:11:20.431 → IP address: 192.168.10.110
12:11:20.431 → Connecting to server 192.168.10.158:8765
12:11:20.465 → Server connection successful!
12:11:28.271 → Channel 6 Transfer Rate (ko/s): 585
12:11:30.290 → ========================================
12:11:30.290 → Connecting on channel 7
12:11:30.803 → .
12:11:30.803 → WiFi connected!
12:11:30.803 → IP address: 192.168.10.110
12:11:30.803 → Connecting to server 192.168.10.158:8765
12:11:30.803 → Server connection successful!
12:11:38.660 → Channel 7 Transfer Rate (ko/s): 585
12:11:40.683 → ========================================
12:11:40.683 → Connecting on channel 8
12:11:41.161 → .
12:11:41.161 → WiFi connected!
12:11:41.161 → IP address: 192.168.10.110
12:11:41.161 → Connecting to server 192.168.10.158:8765
12:11:41.195 → Server connection successful!
12:11:48.797 → Channel 8 Transfer Rate (ko/s): 585
12:11:50.814 → ========================================
12:11:50.814 → Connecting on channel 9
12:11:51.326 → .
12:11:51.326 → WiFi connected!
12:11:51.326 → IP address: 192.168.10.110
12:11:51.326 → Connecting to server 192.168.10.158:8765
12:11:51.361 → Server connection successful!
12:11:59.141 → Channel 9 Transfer Rate (ko/s): 585
12:12:01.164 → ========================================
12:12:01.164 → Connecting on channel 10
12:12:01.645 → .
12:12:01.645 → WiFi connected!
12:12:01.645 → IP address: 192.168.10.110
12:12:01.645 → Connecting to server 192.168.10.158:8765
12:12:01.680 → Server connection successful!
12:12:09.550 → Channel 10 Transfer Rate (ko/s): 585
12:12:11.579 → ========================================
12:12:11.579 → Connecting on channel 11
12:12:12.064 → .
12:12:12.064 → WiFi connected!
12:12:12.064 → IP address: 192.168.10.110
12:12:12.064 → Connecting to server 192.168.10.158:8765
12:12:12.064 → Server connection successful!
12:12:19.995 → Channel 11 Transfer Rate (ko/s): 585

Thanks for your feedback.

Great, it works well by reducing the transmission power.

The channel is define by AP not by station. I think, the channel parameter, it’s only to increase wifi connection speed

thanks for pointing that!