Script to pass ip adres from pepper to esp

This commit is contained in:
2024-05-31 16:35:41 +02:00
parent 61dde95684
commit a080b6c737

View File

@@ -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');
});