Script to pass ip adres from pepper to esp
This commit is contained in:
22
code/server/ipSender/index.js
Normal file
22
code/server/ipSender/index.js
Normal 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');
|
||||
});
|
Reference in New Issue
Block a user