Last active
September 6, 2017 22:38
-
-
Save ciniml/96611bdf75d7e830492d3b12129b1804 to your computer and use it in GitHub Desktop.
ESP32 HTTPS communication test server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https'); | |
const fs = require('fs'); | |
const util = require('util'); | |
const debuglog = util.debuglog('SERVER') | |
const options = { | |
key: fs.readFileSync('test_server.key'), | |
cert: fs.readFileSync('test_server.crt') | |
}; | |
https.createServer(options, (req, res) => { | |
var url = require('url').parse(req.url, true) | |
var name = url.query.name; | |
var temperature = url.query.tmp; | |
var humidity = url.query.hum; | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
var body = util.format('Name: %s\nTemperature: %d\nHumidity: %d', name, temperature, humidity); | |
res.end(body); | |
now = new Date(); | |
debuglog('time: %s, name: %s, tmp: %d, hum:%d', now.toISOString(), name, temperature, humidity); | |
}).listen(443); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment