Arduino SDK version: 3.1.6
Build Environment: Arduino 1.8.19 / macOS Big Sur
Board: BW16
Prerequisites: Update binary to postbuild for BigSur
Reproduce steps:
Open Arduino
Open SimpleServerWiFi
Update ssid/password
Build and Upload
Restart BW16 and wait for wifi connection
Use ping to check TCP connection and it works
test command for webserver: curl -v http://bw16ip:5000/
Expect: curl returns the http connect logs
Actual: curl returns error Received HTTP/0.9 when not allowed
I also tried to use curl --http0.9 -v http://bw16ip:5000/ and I got
* Trying 192.168.1.151:5000...
* Connected to 192.168.1.151 (192.168.1.151) port 5000 (#0)
> GET /d HTTP/1.1
> Host: 192.168.1.151:5000
> User-Agent: curl/7.87.0
> Accept: */*
>
GET /d HTTP/1.1
Host: 192.168.1.151:5000
User-Agent: curl/7.87.0
Accept: */*
then it was blocked and did not return
I have my code for the same board works totally fine in 3.1.2
“curl” command is used to transfer data to or from a server using protocols such as HTTP. However, the example “SimpleServerWiFi” that you are currently running is establishing a TCP transmission for handshake.
The point is not about curl or using 0.9 should still work
Please check the source code below:
When the client is connected
Then it will enter the while loop
But the break was set when there’s anything can be read and it can be written out. That makes the loop never break.
I assumed the solution is to break as soon as nothing to read as the loop function will be called after it’s finished.
The WebServer one may not have this issue as it will check if it’s still available before read to ensure the loop will be exited properly.
while (client.connected()) {
memset(buffer, 0, 256);
int n = client.read((uint8_t*)(&buffer[0]), sizeof(buffer));
if (n > 0) {
for (int i = 0; i < n; i++) {
Serial.print(buffer[i]);
}
n = client.write(buffer, n);
} else break;
}