Skip to content

Instantly share code, notes, and snippets.

@arunoda
Created November 16, 2017 11:47
Show Gist options
  • Save arunoda/7c977b5b722ffc4b83ea780d97d21219 to your computer and use it in GitHub Desktop.
Save arunoda/7c977b5b722ffc4b83ea780d97d21219 to your computer and use it in GitHub Desktop.
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
Copy link

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