Skip to content

Instantly share code, notes, and snippets.

@sterwill
Last active December 23, 2016 22:38
Show Gist options
  • Save sterwill/fe47c13e1a660b6df0d6cf3e850d560f to your computer and use it in GitHub Desktop.
Save sterwill/fe47c13e1a660b6df0d6cf3e850d560f to your computer and use it in GitHub Desktop.
Demonstrates a lock-up with the Feather M0 + ATWINC1500 at high read speeds
// Demonstrates a lock-up with the Feather M0 + ATWINC1500 while attemping
// to write a byte of data to a TCP connection during a sustained read at
// full speed.
//
// Run a program that generates an endless stream of bytes on a host
// you can reach from your network ("yes | nc -k -l -p 9999"), customize
// the code below to connect to it, then run the sketch and watch the output
// on a serial monitor.
//
// You can use "pv" on the server side to rate-limit the stream.
// "yes |pv -L 10000 | nc -k -l -p 9999" limits the stream to 10,000 bytes/s.
//
// The lock-up happens quicker at higher speeds. 153,276 bytes/s (full speed)
// triggers it in under 10 seconds, 140,000 bytes/s takes 30 seconds,
// but at 130,000 bytes/s it ran for over 10 minutes with no problems before I
// stopped it.
//
// License: CC0
// To the extent possible under law, Shaw Terwilliger has waived all copyright
// and related or neighboring rights to this program. This work is published
// from: United States.
#include <WiFi101.h>
#define WIFI_SSID "your ssid here"
#define WIFI_PASSPHRASE "your passphrase"
// Point at a host and port that will feed you endless bytes.
#define TCP_HOST "server.example.com"
#define TCP_PORT 9999
// Buffer > MTU (~1400) to allow for full packet reads
static uint8_t buf[2000];
static WiFiClient client;
static uint32_t last_write_at = 0;
static uint16_t writes = 0;
static uint32_t bytes_read_since_last_write = 0;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("started");
// Pins for Feather M0
WiFi.setPins(8, 7, 4, 2);
WiFi.begin(WIFI_SSID, WIFI_PASSPHRASE);
Serial.print("wifi... ");
while (WiFi.status() != WL_CONNECTED) {}
Serial.println(" connected");
}
void loop() {
// Get connected
if (!client.connected()) {
Serial.print("tcp... ");
if (!client.connect(TCP_HOST, TCP_PORT)) {
Serial.println(" failed");
return;
}
Serial.println(" connected");
}
uint32_t now = millis();
// Read as much as we can.
int bytes_read = client.read(buf, sizeof(buf));
if (bytes_read > 0) {
bytes_read_since_last_write += bytes_read;
}
// Print status and send a byte each second.
if (now - last_write_at > 1000) {
Serial.print(++writes, DEC);
Serial.print(": read ");
Serial.print(bytes_read_since_last_write, DEC);
Serial.print(" bytes/s, writing 1 byte... ");
client.write('x');
Serial.println(" done.");
last_write_at = now;
bytes_read_since_last_write = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment