File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
190198function fireTractors ( ) {
191199 return fetch ( `${ devices } /devices/tractors` , {
192200 method : 'PUT'
@@ -197,6 +205,7 @@ function fireTractors() {
197205
198206setInterval ( fireAnimalCollars , 5000 ) ;
199207setInterval ( fireDevices , 3000 ) ;
208+ setInterval ( fireOverallFarmStatus , 10000 ) ;
200209
201210if ( autoMoveTractors > 0 ) {
202211 setInterval ( fireTractors , autoMoveTractors ) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ if (DEVICE_TRANSPORT === 'HTTP') {
4343}
4444
4545iotRouter . get ( '/status' , ( req , res ) => {
46+ IoTDevices . emitOverallFarmStatus ( ) ;
4647 res . status ( 200 ) . send ( ) ;
4748} ) ;
4849
Original file line number Diff line number Diff 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-
175172myCache . 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} ;
You can’t perform that action at this time.
0 commit comments