From a080b6c737e8a5de220f919ee7fa4bbe0913aee4 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Fri, 31 May 2024 16:35:41 +0200 Subject: [PATCH] Script to pass ip adres from pepper to esp --- code/server/ipSender/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 code/server/ipSender/index.js 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