iotsensor fixed but session valid broken

This commit is contained in:
newtbot
2024-01-25 03:26:56 +08:00
parent 7403f66c8a
commit 057fbe2afb
19 changed files with 173 additions and 237 deletions

View File

@ -1,9 +1,10 @@
const { run } = require("./modules/IoT-sensor");
const { IoTdataGenerator } = require("./modules/IoT-sensor");
const client = require("./modules/mqtt");
async function publishData() {
try {
const data = await run();
let iothub = new IoTdataGenerator();
let data = await iothub.generateData();
console.log(data);
client.publish("iot-data", JSON.stringify(data));
} catch (err) {

View File

@ -18,19 +18,19 @@ class IoTdataGenerator {
async generateData() {
try {
const { loc, sen } = await this.getLocationAndSensorId();
const dataAray = []; // create a new array for each call
for (let i = 0; i < sen.length; i++) {
//console.log(sen[i].id);
//console.log(loc[i].id);
//console.log("you should appear 6 times only")
dataAray.push(firstDataRow(sen[i].id, loc[i].id));
}
}
return dataAray;
} catch (err) {
console.error(err);
}
return dataAray;
}
}
//helper function to generate random data
function firstDataRow(sensorId, locationId) {
@ -57,15 +57,7 @@ function firstDataRow(sensorId, locationId) {
2) loop through each sensor id and location id and generate random data and pass to mqtt
*/
async function run() {
let iotData = new IoTdataGenerator();
const result = await iotData.generateData();
console.log(result);
return result;
}
module.exports = { run };
module.exports = { IoTdataGenerator };