Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiFiClient not working as expected #279

Open
1 task done
trevorwslee opened this issue Nov 8, 2024 · 4 comments
Open
1 task done

WiFiClient not working as expected #279

trevorwslee opened this issue Nov 8, 2024 · 4 comments
Labels
no-issue-activity pending It is a feature/bug-fix request, currently on hold

Comments

@trevorwslee
Copy link

Boards

AMB82-mini

External Hardware

no`

Hardware Configuration

no

Version

other

IDE Name

Arduino IDE 2.3.3

Operating System

Windows

Auto Flash Mode

Disable

Erase All Flash Memory (16MB)

Disable

Standard Lib

Arduino_STD_PRINTF

Upload Speed

2000000

Description

The sample SimpleTCPServer.ino (https://github.com/Ameba-AIoT/ameba-arduino-pro2/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/SimpleTCPServer/SimpleTCPServer.ino) works fine.

However, if the loop() is changed to be like

void loop()
{
    WiFiClient client = server.available();
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.print(c);
      }
    }
    client.stop();
}

it doesn't seem to work as expected,

Note that I tried the same modified sketch with UNO R4 and it works fine with UNO R4

Thanks for looking into the issue.

Sketch

#include <WiFi.h>

char ssid[] = "xxx";    // your network SSID (name)
char pass[] = "xxx";        // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;                // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;     // Indicator of Wifi status

WiFiServer server(5000);

void setup()
{
    Serial.begin(115200);    // initialize serial communication

    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
        Serial.print("Attempting to connect to Network named: ");
        Serial.println(ssid);    // print the network name (SSID);

        // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
        status = WiFi.begin(ssid, pass);
        // wait 10 seconds for connection:
        delay(10000);
    }
    //server.setNonBlockingMode();
    server.begin();       // start the tcp server on port 5000
    printWifiStatus();    // you're connected now, so print out the status
}

const size_t bufferLen = 1;
char buffer[bufferLen];
void loop()
{
    WiFiClient client = server.available();
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.print(c);
      }
    }
    client.stop();
}

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

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

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

Error/Debug Message

none

Reproduce remarks

No response

I have checked online documentation, FAQ, GitHub Wiki and existing/closed issues.

  • I confirm I have checked online documentation, FAQ, GitHub Wiki and existing/closed issues.
@trevorwslee trevorwslee added the pending It is a feature/bug-fix request, currently on hold label Nov 8, 2024
Copy link

github-actions bot commented Nov 8, 2024

Hello, hope this message finds you well. Congrats to your first Issue! We will review it as soon as possiable. Feel free to have a look at https://www.amebaiot.com/en/ameba-arduino-summary/ for more information

@Kyderio
Copy link
Contributor

Kyderio commented Nov 22, 2024

Hi, have you tried setting non blocking mode for your server? Uncomment this line: //server.setNonBlockingMode(); in your set up loop. Thank you.

@trevorwslee
Copy link
Author

trevorwslee commented Nov 23, 2024 via email

Copy link

github-actions bot commented Dec 7, 2024

This issue is stale because it has been open for 14 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-issue-activity pending It is a feature/bug-fix request, currently on hold
Projects
None yet
Development

No branches or pull requests

2 participants