// WICED simple WiFi Speed test /** (c)2016 Forward Computing and Control Pty. Ltd. www.forward.com.au This code may be freely used for both private and commercial use. Provide this copyright is maintained. */ // Using Adafruit Feather WICED board #include // You need to modify the WLAN_SSID, WLAN_PASS settings below // to match your network settings #define WLAN_SSID "networkSSID" // cannot be longer than 32 characters! #define WLAN_PASS "password" // also modify the IP address to suit IPAddress ip(10, 1, 1, 100); int ADC_pin = PC3; // WICED, Adafruit WICED use PC3, WICED has odd pin names const unsigned long baudRate = 115200; // note this is an unsigned long value unsigned long uS = 0; long loopCounter = 0; long lastMillis = 0; long dataCounter = 0; long loop1000time = 0; int sampledData = 0; float dataOut = 0.0; int testCounter = 0; const int portNo = 23; // What TCP port to listen on for connections. AdafruitTCPServer server(portNo); AdafruitTCP client; void setup() { Serial.begin(baudRate); for (int i = 10; i > 0; i--) { // add a little delay, to give you time to open the serial monitor delay(1000); Serial.print(" "); Serial.print(i); } Serial.println(); pinMode(PC3, INPUT_ANALOG); // special pinMode for WICED /* Initialise wifi module */ IPAddress gateway(ip[0], ip[1], ip[2], 1); // set gatway to ... 1 Serial.print(F("Setting ip to: ")); Serial.println(ip); Serial.print(F("Setting gateway to: ")); Serial.println(gateway); IPAddress subnet(255, 255, 255, 0); Feather.config(ip, gateway, subnet); while ( !Feather.connected() ) { delay(500); // delay between each attempt if ( Feather.connect(WLAN_SSID, WLAN_PASS) ) { Serial.println("Wifi connected"); } else { Serial.printf("Failed! %s (%d)", Feather.errstr(), Feather.errno()); Serial.println(); } } Feather.printNetwork(); server.err_actions(true, true); // Tell the TCP Server to auto print error codes and halt on errors server.begin(); Serial.println("Server started"); // initialize client client = server.available(); // evaluates to false if no connection } void loop(void) { while ((!client) || (!client.connected())) { client = server.available(); if (client.connected()) { Serial.println("Got connection"); lastMillis = millis(); } else { client.stop(); Serial.println("Waiting for connection"); delay(1000); } } loopCounter++; if ((loopCounter % 1000) == 0) { long ms = millis(); Serial.print("Using Adafruit WICED"); Serial.print(" 1000 loops in:"); loop1000time = ms - lastMillis; Serial.print(loop1000time); Serial.print("mS"); Serial.print(" -> Sample rate:"); Serial.print((1000.0 / loop1000time)); Serial.println("k samples/sec"); Serial.println("Example data record:"); // print a sample of the data record sendData(&Serial); lastMillis = millis(); // restart time after printing testCounter++; if (testCounter > 5) { // stop here to view results while (1) {}; } } // get the data and the time // replace these lines with your own measurement code sampledData = analogRead(ADC_pin); uS = micros(); // prepare and print the data record time , data // do any data scaling and timestamp preperation here dataOut = ((float) sampledData) / 1024.0; sendData(&client); } //end main loop // change this method to send your data void sendData(Print * output) { output->print(uS); output->print(','); output->print(dataOut); output->println(); }