diff --git a/code/server/ipSender/index.js b/code/server/ipSender/index.js new file mode 100644 index 0000000..dc68c2d --- /dev/null +++ b/code/server/ipSender/index.js @@ -0,0 +1,22 @@ +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'); +}); \ No newline at end of file