22 lines
597 B
JavaScript
22 lines
597 B
JavaScript
const express = require('express');
|
|
const app = express();
|
|
|
|
app.use(express.json()); // for parsing application/json
|
|
|
|
let ipAddress = ''; // to store the received IP address
|
|
|
|
// endpoint to receive an IP address from an external source
|
|
app.post('/set-ip', (req, res) => {
|
|
ipAddress = req.body.ip;
|
|
console.log('IP address received:', ipAddress);
|
|
});
|
|
|
|
// endpoint for the ESP32 to fetch the IP address
|
|
app.get('/get-ip', (req, res) => {
|
|
res.json({ ip: ipAddress });
|
|
console.log('IP address sent to ESP32');
|
|
});
|
|
|
|
app.listen(42069, () => {
|
|
console.log('Server is running on port 42069');
|
|
}); |