mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	node-red-node-physical-web: Added msg.advertising = true/false to enable/disable advertising (#204)
* Added msg.advertising = true/false to enable/disable advertising * Fixed comparison with bool
This commit is contained in:
		
				
					committed by
					
						
						Dave Conway-Jones
					
				
			
			
				
	
			
			
			
						parent
						
							32282ec528
						
					
				
				
					commit
					b0c5c8c8f4
				
			@@ -136,6 +136,9 @@
 | 
				
			|||||||
    For example, to set a 20ms interval, you would need to type <code>sudo BLENO_ADVERTISING_INTERVAL=20 node-red</code></p>
 | 
					    For example, to set a 20ms interval, you would need to type <code>sudo BLENO_ADVERTISING_INTERVAL=20 node-red</code></p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <p>Linux users should <a href="https://github.com/sandeepmistry/bleno#running-on-linux" target="_new">READ THIS</a>.</p>
 | 
					    <p>Linux users should <a href="https://github.com/sandeepmistry/bleno#running-on-linux" target="_new">READ THIS</a>.</p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <p>Sending <code>msg.advestising = false</code> will stop advertisement, sending <code>msg.advestising = true</code> will
 | 
				
			||||||
 | 
					    resume it.</p>
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script type="text/javascript">
 | 
					<script type="text/javascript">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,11 +106,44 @@ module.exports = function(RED) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        node.on('input', function(msg) {
 | 
					        node.on('input', function(msg) {
 | 
				
			||||||
 | 
					            if (msg.advertising === false) {
 | 
				
			||||||
 | 
					                if (eddyBeacon) {
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
 | 
					                        eddystoneBeacon.stop();
 | 
				
			||||||
 | 
					                        node.status({fill:"red",shape:"dot",text:"Stopped"});
 | 
				
			||||||
 | 
					                    } catch(e) {
 | 
				
			||||||
 | 
					                        node.error('error shutting down beacon', e);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (msg.advertising === true) {
 | 
				
			||||||
 | 
					                if (node.mode === "url") {
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
 | 
					                        eddystoneBeacon.advertiseUrl(node.url, node.options);
 | 
				
			||||||
 | 
					                        node.status({fill:"green",shape:"dot",text:node.url});
 | 
				
			||||||
 | 
					                    } catch(e) {
 | 
				
			||||||
 | 
					                        node.error('Error setting beacon URL', e);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                if (node.mode === "uid") {
 | 
				
			||||||
 | 
					                    try {
 | 
				
			||||||
 | 
					                        eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
 | 
				
			||||||
 | 
					                        node.status({fill:"green",shape:"dot",text:node.namespace});
 | 
				
			||||||
 | 
					                    } catch(e) {
 | 
				
			||||||
 | 
					                        node.error('Error setting beacon information', e);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            // url mode
 | 
				
			||||||
            if (node.mode === "url") {
 | 
					            if (node.mode === "url") {
 | 
				
			||||||
              if (checkLength(msg.payload) <= 18) {
 | 
					              if (checkLength(msg.payload) <= 18) {
 | 
				
			||||||
                  try {
 | 
					                  try {
 | 
				
			||||||
                      eddystoneBeacon.advertiseUrl(msg.payload, node.options);
 | 
					                      node.url = msg.payload;
 | 
				
			||||||
                      node.status({fill:"green",shape:"dot",text:msg.payload});
 | 
					                      eddystoneBeacon.advertiseUrl(node.url, node.options);
 | 
				
			||||||
 | 
					                      node.status({fill:"green",shape:"dot",text:node.url});
 | 
				
			||||||
                  } catch(e) {
 | 
					                  } catch(e) {
 | 
				
			||||||
                      node.status({fill:"red",shape:"dot",text:"Error setting URL"});
 | 
					                      node.status({fill:"red",shape:"dot",text:"Error setting URL"});
 | 
				
			||||||
                      node.error('error updating beacon URL', e);
 | 
					                      node.error('error updating beacon URL', e);
 | 
				
			||||||
@@ -122,7 +155,9 @@ module.exports = function(RED) {
 | 
				
			|||||||
            // uid mode
 | 
					            // uid mode
 | 
				
			||||||
            else {
 | 
					            else {
 | 
				
			||||||
              try {
 | 
					              try {
 | 
				
			||||||
                  eddystoneBeacon.advertiseUid(msg.payload, msg.topic, node.options);
 | 
					                  node.namespace = msg.payload;
 | 
				
			||||||
 | 
					                  node.instance = msg.topic;
 | 
				
			||||||
 | 
					                  eddystoneBeacon.advertiseUid(node.namespace, node.instance, node.options);
 | 
				
			||||||
                  node.status({fill:"green",shape:"dot",text:msg.payload});
 | 
					                  node.status({fill:"green",shape:"dot",text:msg.payload});
 | 
				
			||||||
              } catch(e) {
 | 
					              } catch(e) {
 | 
				
			||||||
                  node.status({fill:"red",shape:"dot",text:"Error setting beacon information"});
 | 
					                  node.status({fill:"red",shape:"dot",text:"Error setting beacon information"});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user