@@ -9,6 +9,7 @@ const _ = require('lodash');
99const debug = require ( 'debug' ) ( 'devices:devices' ) ;
1010const Northbound = require ( '../controllers/iot/northbound' ) ;
1111const Emitter = require ( '../lib/emitter' ) ;
12+ const Writer = require ( '../lib/writer' ) ;
1213
1314// A series of constants used by our set of devices
1415
@@ -18,8 +19,8 @@ const WATER_ON = 's|ON';
1819const HUMIDITY_WET = 'h|80' ;
1920const TRACTOR_IDLE = 'd|IDLE' ;
2021
21- const PIG_IDLE = 'd|AT_REST' ;
22- const COW_IDLE = 'd|AT_REST' ;
22+ const PIG_IDLE = 'o|0|hide|o,x| d|AT_REST' ;
23+ const COW_IDLE = 'o|0|hide|o,x| d|AT_REST' ;
2324const PIG_STATE = [
2425 'AT_REST' ,
2526 'FORAGING' ,
@@ -319,7 +320,6 @@ function fireAnimalCollars() {
319320
320321function sendAnimalCollarReadings ( ) {
321322 const deviceIds = myCache . keys ( ) ;
322-
323323 _ . forEach ( deviceIds , ( deviceId ) => {
324324 getDeviceState ( deviceId ) . then ( ( state ) => {
325325 const isSensor = true ;
@@ -347,6 +347,9 @@ function sendAnimalCollarReadings() {
347347 }
348348 }
349349 state . s = getStatusCode ( state . d ) ;
350+ if ( state . o ) {
351+ state . o ++ ;
352+ }
350353 setDeviceState ( deviceId , toUltraLight ( state ) , isSensor ) ;
351354 break ;
352355 case 'cow' :
@@ -375,6 +378,9 @@ function sendAnimalCollarReadings() {
375378 }
376379 }
377380 state . s = getStatusCode ( state . d ) ;
381+ if ( state . o ) {
382+ state . o ++ ;
383+ }
378384 setDeviceState ( deviceId , toUltraLight ( state ) , isSensor ) ;
379385 break ;
380386 default :
@@ -542,7 +548,7 @@ function setDeviceState(deviceId, state, isSensor = true, force = false) {
542548 if ( isSensor && ( state !== previousState || force ) ) {
543549 Northbound . sendMeasure ( deviceId , payload ) ;
544550 }
545-
551+ Writer . write ( deviceId , state ) ;
546552 Emitter . emit ( deviceId , payload ) ;
547553}
548554
0 commit comments