Skip to content

Instantly share code, notes, and snippets.

@arunoda arunoda/esp-load-test.ino Secret
Created Nov 16, 2017

Embed
What would you like to do?
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
const char* ssid = "SSID";
const char* password = "pass";
WiFiServer server(80);
void setup() {
Serial.begin(9600);
// Connecting to WiFi as an station
Serial.print("[WiFi] Connecting.");
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print('.');
}
Serial.println(' ');
Serial.println("[WiFi] Connected to ssid: " + String(ssid));
Serial.print("[WiFi] IP: ");
Serial.println(WiFi.localIP());
// Start the MDNS server
if (MDNS.begin("esp-load-test")) {
Serial.println("[MDNS] Serving: esp-load-test.local");
}
server.begin();
server.setNoDelay(true);
}
String getHTMLHead(){
String htmlPage =
String("HTTP/1.1 200 OK\r\n") +
"Content-Type: application/octet-stream\r\n" +
"Content-Length: 999999999999\r\n" +
"Connection: close\r\n" +
"\r\n";
return htmlPage;
}
void loop() {
WiFiClient client = server.available();
if (client && client.connected()) {
Serial.println("A client found.");
String line = client.readStringUntil('\n');
Serial.println(line);
client.println(getHTMLHead());
while(client.status()) {
const int bufSize = 1460;
// Initialize a random set of bytes
byte clientBuf[bufSize];
client.write((const uint8_t *)clientBuf, bufSize);
}
Serial.println("Client stopped.");
}
}
@Bladetuab

This comment has been minimized.

Copy link

Bladetuab commented Apr 26, 2018

How can I run your code with my devices,
I don't know how to run your NodeJS file

@vulcan25

This comment has been minimized.

Copy link

vulcan25 commented May 16, 2019

@Bladetuab incase you never worked this out, or for others finding themselves here:

The node.js code appears to make a request to the / URL on the webserver.

So to do this without node, something like:

curl -vo /dev/null  http://192.168.2.109/

...changing the IP to match what is displayed in the serial console. You could also hit that URL in a web-browser.

-o /dev/null ensures the file doesn't save locally, which is the purpose of the Node test client as per the tutorial.

I tested this code deployed to my NodeMCU w/ ESP8266 and it worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.