120 lines
2.0 KiB
JavaScript
120 lines
2.0 KiB
JavaScript
/*
|
|
* ESP8266 RGBW controller
|
|
* Copyright 2020 (c) Mark van Renswoude
|
|
*
|
|
* https://git.x2software.net/pub/RGBWifi
|
|
*/
|
|
const express = require('express');
|
|
const bodyParser = require('body-parser');
|
|
|
|
const app = express();
|
|
|
|
app.use(bodyParser.json());
|
|
app.use(express.static('web'));
|
|
app.use(express.static('web/dist'));
|
|
|
|
app.get('/api/status', (req, res) =>
|
|
{
|
|
res.send({
|
|
systemID: 'dev-server',
|
|
version: 'dev-server',
|
|
resetReason: 2,
|
|
stackTrace: true
|
|
});
|
|
});
|
|
|
|
app.get('/api/connection', (req, res) =>
|
|
{
|
|
res.send({
|
|
hostname: 'dev-server',
|
|
accesspoint: true,
|
|
station: true,
|
|
ssid: 'MyWiFiSSID',
|
|
password: 'supersecret',
|
|
dhcp: true,
|
|
ip: '192.168.1.234',
|
|
subnetmask: '255.255.255.0',
|
|
gateway: '192.168.1.0'
|
|
});
|
|
});
|
|
|
|
app.get('/api/connection/status', (req, res) =>
|
|
{
|
|
res.send({
|
|
"ap": {
|
|
"enabled": true,
|
|
"ip": "192.168.4.1"
|
|
},
|
|
"station": {
|
|
"enabled": true,
|
|
"status": 1,
|
|
"ip": "0.0.0.0"
|
|
}
|
|
});
|
|
});
|
|
|
|
app.post('/api/connection', (req, res) =>
|
|
{
|
|
res.sendStatus(200);
|
|
});
|
|
|
|
app.post('/api/firmware', (req, res) =>
|
|
{
|
|
res.sendStatus(200);
|
|
});
|
|
|
|
|
|
var system = {
|
|
pins: {
|
|
ledAP: 4,
|
|
ledSTA: 5,
|
|
apButton: 2,
|
|
},
|
|
ledCount: 60
|
|
};
|
|
|
|
app.get('/api/system', (req, res) =>
|
|
{
|
|
res.send(system);
|
|
});
|
|
|
|
app.post('/api/system', (req, res) =>
|
|
{
|
|
var body = req.body;
|
|
if (body)
|
|
{
|
|
system.pins.ledAP = body.pins.ledAP || system.pins.ledAP;
|
|
system.pins.ledSTA = body.pins.ledSTA || system.pins.ledSTA;
|
|
system.pins.apButton = body.pins.apButton || system.pins.apButton;
|
|
system.ledCount = body.ledCount || system.ledCount;
|
|
|
|
res.sendStatus(200);
|
|
}
|
|
else
|
|
res.sendStatus(400);
|
|
});
|
|
|
|
|
|
|
|
app.get('/api/stacktrace/get', (req, res) =>
|
|
{
|
|
res.send("Nothing to see here, move along!");
|
|
});
|
|
|
|
app.get('/api/stacktrace/delete', (req, res) =>
|
|
{
|
|
res.sendStatus(200);
|
|
});
|
|
|
|
|
|
app.get('/api/set/static', (req, res) =>
|
|
{
|
|
res.sendStatus(200);
|
|
});
|
|
|
|
|
|
app.listen(3000, function()
|
|
{
|
|
console.log('Development server listening on port 3000')
|
|
console.log('Press Ctrl-C to stop')
|
|
}); |