Advertisement
Guest User

Untitled

a guest
May 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // publish our nodes.
  2. function publish_nodes(){
  3.   var nodeCursor = nodeCollection.find( { _id: {$gt: 0}} );
  4.   nodeCursor.each(function (err, doc) {
  5.     if (err) {
  6.       console.log(err);
  7.     } else if ( doc!= null) {
  8.       //console.log('Fetched:', doc);
  9.       var node_to_publish = doc;
  10.      
  11.       // Get sensors for this node.
  12.       var sensor_cursor = sensorCollection.find( {node_id : node_to_publish['_id']} );
  13.       var sensor = sensor_cursor.each(function ( serr, sdoc ){
  14.         if (serr){
  15.           console.log(err);
  16.         } else if (sdoc!= null){
  17.           //console.log('fetched sensor for node: ', node_info_json['_id'] ,":", sdoc);
  18.           console.log( sdoc );
  19.         }
  20.       });
  21.      
  22.       //node_to_publish
  23.       console.log('published node.');
  24.       mqtt_client.publish("/zc/" + serial_number + "/node/", JSON.stringify(node_to_publish) );
  25.     }  
  26.   });
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement