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

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.