iot sensor without validation

This commit is contained in:
newtbot 2023-12-17 03:18:30 +08:00
parent 9809841af2
commit 40bf18bdf7
6 changed files with 718 additions and 292 deletions

View File

@ -0,0 +1 @@

55
IoT-sensor/IoT-sensor.js Normal file
View File

@ -0,0 +1,55 @@
/*
1) PSI metric data
2) Humidity
3) Gases (O3,NO2,SO2)
4) temperature
5) Air pressure?
6) windspeed?
8) time when data was collected / generated
*/
/*
1) generate random data for each sensor
2) validate the data
*/
function generateRandomData() {
const psiData = getRandomValue(0, 500);
const humidityData = getRandomValue(0, 100);
const o3Data = getRandomValue(0, 600); //max 600
const no2Data = getRandomValue(0, 1000); //max 1000
const so2Data = getRandomValue(0, 1000); //max 1000
const temperatureData = getRandomValue(24, 40);
const windspeedData = getRandomValue(0, 35);
const currentTime = new Date(Date.now() + 28800000)
.toISOString()
.slice(0, 19)
.replace("T", " ");
var json = {
psi: psiData.toFixed(0),
humidity: humidityData.toFixed(0) + "%",
o3: o3Data.toFixed(0) + "ppm",
no2: no2Data.toFixed(0) + "ppm",
so2: so2Data.toFixed(0) + "ppm",
temperature: temperatureData.toFixed(0) + "°C",
windspeed: windspeedData.toFixed(0) + "km/h",
time: currentTime,
};
console.log(json.psi);
console.log(json.humidity);
console.log(json.o3);
console.log(json.no2);
console.log(json.so2);
console.log(json.temperature);
console.log(json.windspeed);
console.log(json.time);
}
function getRandomValue(min, max) {
return Math.random() * (max - min) + min;
}
//every 5 minutes
setInterval(generateRandomData, 300000);

View File

@ -0,0 +1,8 @@
var validator = require('validator');
function isNumber(data) {
return !is
}
module.exports = { isNumber}

View File

943
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,7 @@
"dotenv": "^16.3.1",
"express": "^4.18.2",
"mysql2": "^3.6.5",
"sequelize": "^6.35.2"
"sequelize": "^6.35.2",
"validator": "^13.11.0"
}
}