Driver for IP Cameras

I put together a driver that displays camera images. The images get refreshed when you open the recipe and displays the latest snapshot. Unfortunately it does not refresh dynamically but maybe you guys have an idea so any suggestions are welcome.

I'm not a dev so there are probably a lot of improvements that can be made :)

index.js:

'use strict';

const neeoapi = require('neeo-sdk');
const controller = require('./controller');

console.log('NEEO "Camera" adapter');
console.log('---------------------------------------------');

// first we set the device info, used to identify it on the Brain
const camera = neeoapi.buildDevice('Cameras')
  .setManufacturer('All')
  .addAdditionalSearchToken('IPCam')
  .addAdditionalSearchToken('Camera')
  .setType('ACCESSOIRE')

  .addTextLabel({ name: 'status-text', label: 'Camera: ' }, controller.getExampleText)
  .addImageUrl({ name: 'Frontdoor', label: 'Voordeur', size: 'large' }, controller.getImageUriNetatmo)
  .addTextLabel({ name: 'status-text2', label: 'Camera: ' }, controller.getExampleText2)
  .addImageUrl({ name: 'Garage', label: 'Garage', size: 'large' }, controller.getImageUriGarage)


// Starting of the SDK Server (Code provided from NEEO SDK)  

function startSdkExample(brain) {
  console.log('- Start server');
  neeoapi.startServer({
    brain,
    port: 6337,
    name: 'Camera',
    devices: [camera]
  })
  .then(() => {
    console.log('# READY! use the NEEO app to search for "Camera or IPCam".');
  })
  .catch((error) => {
    //if there was any error, print message out to console
    console.error('ERROR!', error.message);
    process.exit(1);
  });
}

const brainIp = process.env.BRAINIP;
if (brainIp) {
  console.log('- use NEEO Brain IP from env variable', brainIp);
  startSdkExample(brainIp);
} else {
  console.log('- discover one NEEO Brain...');
  neeoapi.discoverOneBrain()
    .then((brain) => {
      console.log('- Brain discovered:', brain.name);
      startSdkExample(brain);
    });
}
 

 

controller.js

'use strict';

const BluePromise = require('bluebird');
var request = require('request');
var http = require('http'),
fs = require('fs');
var date = '';

let textlabelValue = 'Netatmo Presence';
let textlabelValue2 = 'Dahua Garage';
let sendComponentUpdate;

module.exports.getExampleText = function() {
  console.log('Set Cam1: ' + textlabelValue);
  return textlabelValue;
};

module.exports.getExampleText2 = function() {
  console.log('Set Cam2: ' + textlabelValue2);
  return textlabelValue2;
};

module.exports.getImageUriNetatmo = function() {
var hours = (new Date()).getHours();
var minutes = (new Date()).getMinutes();
var seconds = (new Date()).getSeconds();
var day = (new Date()).getDay();
var month = (new Date()).getMonth();
var year = (new Date()).getYear();
var date = day + '-' + month + '-' + year + '_' + hours + '-' + minutes + '-' + seconds;
console.log('Downloading Netatmo image for ' + date);
  return 'http://ipaddress/84440abf1103f862c999a0d4e3/live/snapshot_720.jpg?' + date;
};

module.exports.getImageUriGarage = function() {  
var hours = (new Date()).getHours();
var minutes = (new Date()).getMinutes();
var seconds = (new Date()).getSeconds();
var day = (new Date()).getDay();
var month = (new Date()).getMonth();
var year = (new Date()).getYear();
var date = day + '-' + month + '-' + year + '_' + hours + '-' + minutes + '-' + seconds;
console.log('Downloading Garage image for ' + date);
  return 'http://user:password@ipaddress/cgi-bin/snapshot.cgi?loginuse=user&loginpas=password?' + date;
};

Reply
4replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • I'm currently working on the similar driver for something like 2N door stations and DoorBird, to make camera image dynamic the only way I can see so far (and will try) is to use setInterval to call sendComponentUpdate routine periodically.

    Like
  • Got the live image working and tested with DoorBird intercom, the code snippet in controller.js is as below:

    function genDynamicImageUri(){
        var tm = Math.round((new Date()).getTime() / 1000);
        var uri = BASE_IMAGE_URL +'&' + tm.toString();
        return uri;
     }
    
    module.exports.getImageUri = function(deviceid) {
      console.log(`[CONTROLLER] get image URI on ${deviceid}!`);
      var uri = genDynamicImageUri();
      return uri
    };
    
    
    module.exports.registerStateUpdateCallback = function(updateFunction) {
      console.log('[CONTROLLER] register update state');
      sendComponentUpdate = updateFunction;
    };
    
    function updateCameraImage(){
      if (sendComponentUpdate != null){
        var uri = genDynamicImageUri()
        console.log(`[CONTROLLER] Update camera image URI: `+ uri);
        sendComponentUpdate({ uniqueDeviceId: DEVICE_ID, component:'cameraimage',
          value:  uri})
      }
    }
    setInterval(updateCameraImage, 1000);
    

     

    NOTE

    • The live image only works properly on NEEO app and Embedded web view interface from NEEO brain
    • On NEEO remote, the image blinks with camera video but in most of time is blank, I'm wondering it is a limitation of NEEO remote (preventing too frequent state update?)
    Like
  • Hello Steven Y ,

    I've developped a Driver for Netatmo Presence (https://github.com/clegendre/Neeo-Netatmo-Presence-Adapter) and have encoutered the same issue of image refresh than you. 

    I don't think this is a limitation of the NEEO remote but instead the resize of a large image to fit in its container (720p for my case) that is not optimized at all.

    Maybe someone at NEEO could tell us more about that.

    Like
    • Cédric Legendre It's cool too see these awesome developments. I know the SDK itself will also see some nice new developments. Regarding the images I'm looping in Michael Vogt who I believe can best answer that question. Thanks!

      Like
Like3 Follow