-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTemperaturemonitoring.js
More file actions
167 lines (147 loc) · 5.11 KB
/
Temperaturemonitoring.js
File metadata and controls
167 lines (147 loc) · 5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import SimulatorPlugins from "./reusable/SimulatorPlugins.js"
import { PLUGINS_APIKEY } from "./reusable/apikey.js";
import MobileNotifications from "./reusable/MobileNotifications.js"
import GoogleMapsFromSignal from "./reusable/GoogleMapsFromSignal.js"
import LineChart from "./reusable/LineChart.js"
async function fetchRowsFromSpreadsheet(spreadsheetId, apiKey) {
// Set the range to A1:Z1000
const range = "A1:Z1000";
// Fetch the rows from the Google Spreadsheet API
const response = await fetch(
`https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}?key=${encodeURIComponent(apiKey)}`
);
const json = await response.json();
// Get the headers from the first row
const headers = json.values[0];
// Convert the remaining rows to an array of objects
const rows = json.values.slice(1).map(row => {
const rowObject = {};
for (let i = 0; i < row.length; i++) {
rowObject[headers[i]] = row[i];
}
return rowObject;
});
return rows;
}
const plugin = ({widgets, simulator, vehicle}) => {
fetchRowsFromSpreadsheet("1vcrl5yRyMiAdsH1eIakfuHxocnYu6rgs5O-QHxnznj4", PLUGINS_APIKEY)
.then((rows) => {
SimulatorPlugins(rows, simulator)
console.log(rows)
})
widgets.register(
"GoogleMapDirections",
GoogleMapsFromSignal(
[
{
"lat": 48.149497,
"lng": 11.523194
},
{
"lat": 50.445168,
"lng": 11.020569
},
],
vehicle,
{ iterate: false }
)
)
widgets.register("TemperatureMonitoringRow1", LineChart([
{
signal: "Vehicle.Trailer.Chassis.Axle.Row1.Temperature",
suffix: " C",
color: "yellow"
},
{
signal: "Vehicle.Trailer.Chassis.Axle.Row1.Wheel.Left.Brake.Temperature",
suffix: " C",
color: "#a21caf"
},
{
signal: "Vehicle.Trailer.Chassis.Axle.Row1.Wheel.Right.Brake.Temperature",
suffix: " C",
color: "#14b8a6"
}
], vehicle))
widgets.register("TemperatureMonitoringRow2", LineChart([
{
signal: "Vehicle.Trailer.Chassis.Axle.Row2.Temperature",
suffix: " C",
color: "yellow"
},
{
signal: "Vehicle.Trailer.Chassis.Axle.Row2.Wheel.Left.Brake.Temperature",
suffix: " C",
color: "#a21caf"
},
{
signal: "Vehicle.Trailer.Chassis.Axle.Row2.Wheel.Right.Brake.Temperature",
suffix: " C",
color: "#14b8a6"
}
], vehicle))
// let message = "", mobileMessage = "";
let sim_intervalId = null;
// const start_sim = (time) => {
// sim_intervalId = setInterval(async () => {
// // let Row1 = await vehicle.Trailer.Chassis.Axle.Row1.Temperature.get();
// // let Row2 = await vehicle.Trailer.Chassis.Axle.Row2.Temperature.get();
// // if(Row1 > 10) {
// // message = "Temperature of front brake exceeding threshold 10C!";
// // mobileMessage = message;
// // }
// // else if (Row2 >10){
// // message = "Temperature of rear brake exceeding threshold 10C!";
// // mobileMessage = message;
// // }
// // else {
// // message = "";
// // mobileMessage = message;
// // }
// // mobileNotifications(mobileMessage);
// await vehicle.Next.get()
// sim_function()
// }, time)
// }
// start_sim(3000)
let sim_function;
simulator("Vehicle.Trailer.Chassis.Axle.Row1.Temperature", "subscribe", async ({func, args}) => {
sim_function = args[0]
console.log("print func", args[0])
})
simulator("Vehicle.Trailer.Chassis.Axle.Row2.Temperature", "subscribe", async ({func, args}) => {
sim_function = args[0]
console.log("print func", args[0])
})
let mobileNotifications = null;
widgets.register("Mobile", (box) => {
const {printNotification} = MobileNotifications({
apis : null,
vehicle: null,
box: box,
refresh: null,
paddingTop: 70,
paddingHorizontal: 25
})
mobileNotifications = printNotification;
return () => {
if (sim_intervalId !== null) {
clearInterval(sim_intervalId)
}
}
})
return {
start_simulation : (time) => {
sim_intervalId = setInterval(async () => {
await vehicle.Next.get()
sim_function()
}, time)
},
notifyPhone : (message) => {
if (mobileNotifications !== null) {
mobileNotifications(message)
}
},
}
}
export default plugin