Skip to content

Instantly share code, notes, and snippets.

@ciniml
Last active September 6, 2017 22:38
Show Gist options
  • Save ciniml/96611bdf75d7e830492d3b12129b1804 to your computer and use it in GitHub Desktop.
Save ciniml/96611bdf75d7e830492d3b12129b1804 to your computer and use it in GitHub Desktop.
ESP32 HTTPS communication test server
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