Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node.js HTTP client for ESP8266 Load Test
const http = require('http');
const printHeaders = (() => {
let printed = false
return () => {
if (printed) return
console.log('timestamp, kbps')
printed = true;
}
})();
function start() {
const req = http.get('http://esp-load-test.local/', (res) => {
printHeaders();
let dataSize = 0
res.on('data', (data) => {
dataSize += data.length
})
res.on('error', handleError)
const intervalHandler = setInterval(() => {
if (dataSize === 0) {
req.abort()
clearInterval(intervalHandler)
start()
}
const speed = dataSize/1024/10
dataSize = 0
console.log(`${Date.now()}, ${speed}`)
}, 1000 * 10)
})
.on('error', handleError)
function handleError(err) {
console.error(err.message)
start()
}
}
start();
@stephenlai2018

This comment has been minimized.

stephenlai2018 commented Nov 21, 2018

Excuse me, Sir, I want to make an APP that user press button on web page that created with node.js cloud server to turn on/off bulb controlled by ESP8266, how to write server side codes? I will be very appreciated if you can help... My Email: stephenlai2015@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment