1

I have tried every method on here Execute script on start-up and I still cannot get a .js file to run on start up. The file is very simple:

var noble = require('noble'); 
var request = require('request');
var http = require('http');
var trim = require('trim');
var LocalmacAddress  
require('getmac').getMac(function(err,LocalMacAddress){
if (err)  throw err;
console.log(LocalMacAddress); 
LocalmacAddress = LocalMacAddress   
});
noble.on('stateChange', function(state) {
 if (state === 'poweredOn')
  noble.startScanning([], true);
else
  noble.stopScanning(); 
});
noble.on('discover', function(peripheral) { 
  var macAddress = peripheral.uuid;
  var rss = peripheral.rssi;
  var s = URL HERE
console.log("http://dev.tester.com" + s);
var options = {
    host: 'dev.tester.com',
    path: s
};

callback = function(response) {
    var str = '';
    response.on('end', function (chunk) {
        str += chunk;
    });

response.on('end', function() {
    console.log(str);
});
}
http.request(options, callback).end();

});

I have added the to the crontab,

@reboot sudo /user/local/bin/node /home/pi/Desktop/Scan.js

I have added it to the rc.local

sudo /user/local/bin/node home/pi/Desktop/Scan.js

I have created a script .superscript and added it to the init.d

  • Did you mean .superscript, ./superscript, or just superscript? I think it should be the latter, looking at the link you provided. – Greenonline Mar 04 '16 at 01:05
  • Ok I have figured out the problem ... the script was running before the wifi and Bluetooth was turned on so I added a wait timer that waited 30 seconds before the script runs. – Tim Morford Mar 04 '16 at 19:16

0 Answers0