Skip to content

Commit 2f1e370

Browse files
committed
Move Weather check
1 parent 1cc1802 commit 2f1e370

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

app/controllers/iot/command-listener.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ function fireAnimalCollars() {
187187
});
188188
}
189189

190+
function fireOverallFarmStatus() {
191+
return fetch(`${devices}/status`, {
192+
method: 'GET'
193+
}).catch((e) => {
194+
debug(e);
195+
});
196+
}
197+
190198
function fireTractors() {
191199
return fetch(`${devices}/devices/tractors`, {
192200
method: 'PUT'
@@ -197,6 +205,7 @@ function fireTractors() {
197205

198206
setInterval(fireAnimalCollars, 5000);
199207
setInterval(fireDevices, 3000);
208+
setInterval(fireOverallFarmStatus, 10000);
200209

201210
if (autoMoveTractors > 0) {
202211
setInterval(fireTractors, autoMoveTractors);

iot-devices/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ if (DEVICE_TRANSPORT === 'HTTP') {
4343
}
4444

4545
iotRouter.get('/status', (req, res) => {
46+
IoTDevices.emitOverallFarmStatus();
4647
res.status(200).send();
4748
});
4849

iot-devices/models/devices.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ function stopDevices() {
169169
Emitter.emit('barn', 'door-locked');
170170
}
171171

172-
// Broadcast weather conditions
173-
setInterval(emitWeatherConditions, 10000);
174-
175172
myCache.init().then(() => {
176173
for (let i = 1; i <= numberOfPigs; i++) {
177174
const lng = addAndTrim(13.356 + 0.0004 * getRandom(-10), true);
@@ -228,7 +225,7 @@ myCache.init().then(() => {
228225
myCache.set('weather', 'cloudy');
229226
});
230227

231-
function emitWeatherConditions() {
228+
function fireOverallFarmStatus() {
232229
if (Emitter) {
233230
myCache.get('weather').then((state) => {
234231
Emitter.emit('weather', state);
@@ -658,5 +655,6 @@ module.exports = {
658655
fireDevices,
659656
fireAnimalCollars,
660657
fireTractorStatus,
658+
fireAppStatus,
661659
initDevices,
662660
};

0 commit comments

Comments
 (0)