Skip to content

Commit

Permalink
add received data logging to console
Browse files Browse the repository at this point in the history
  • Loading branch information
sams258 committed Aug 19, 2024
1 parent 01f3f23 commit 40dbb83
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ app.use(cors());
app.post("/api/sensor-data", async (req, res) => {
try {
const { temperature, humidity } = req.body;
console.log(
`Received data - Temperature: ${temperature}°C, Humidity: ${humidity}%`
); // Logs temperature and humidity to the console

const newSensorData = new SensorData({ temperature, humidity });
await newSensorData.save();

res.status(201).send("Data logged successfully");
} catch (err) {
console.error("Error logging data:", err); // Logs detailed error to the console
Expand Down

0 comments on commit 40dbb83

Please sign in to comment.