• I was able to get this to work with both the power adaptor and also with a 9V battery as a separate test. I had to wrap the code in a setTimeout with a delay of 15 seconds to get the modem to initilize. I had performed this step initially; However, it seems wrapping Bluetooth.setConsole(1) inside of the setTimeout caused me problems.

    So, in the end wrapping the entire code(with the exception of the Bluetooth.setConsole(1) in a setTimeout for 15 seconds, in addition to the 'Direct to flash(Execute at boot)' was the needed fix to resolve this one. I hope others find this post useful should the encounter the same issues I did. Final code is posted below. On a side note and you will see the PIR block of code included below, this is also now stable and works as expected. Seems that the setTimeout is pretty crucial, and maybe in certain other cases could use a longer timeout than 15 seconds, to get this to work.

    Bluetooth.setConsole(1);
    setTimeout(function(){
    Serial1.setup(9600, { rx: D29, tx : D28 });
    var ATSMS = require("ATSMS");
    var sms = new ATSMS(Serial1);
    
    sms.init(function(err) {
      if (err) throw err;
      console.log("Initialised!");
    
      sms.list("ALL", function(err,list) {
        if (err) throw err;
        if (list.length)
          console.log(list);
        else
          console.log("No Messages");
      });
    
      // and to send a message:
      //sms.send('+441234567890','Hello world!', callback)
       setInterval(function readPIR(){
       PIR = digitalRead(D30);
       print(PIR);
         if(PIR == 1){
           digitalWrite(LED3,1);
           sms.send('+15555555555', 'Motion Detected!');
      }  else{
           digitalWrite(LED3,0);
      }
    }, 2500);
    });
    
    sms.on('message', function(msgIndex) {
      console.log("Got message #",msgIndex);
      sms.get(msgIndex, function(err, msg) {
        if (err) throw err;
        print("Read message", msg);
        var txt = msg.text.toLowerCase();
        if (txt=="on") LED1.set();
        if (txt=="off") LED1.reset();
        // delete all messages to stop us overflowing
        sms.delete("ALL");
      });
    });
    },15000);
    

    I would like to thank you again for all of your help and generous inputs! It has certainly helped me towards a resolution.

About

Avatar for ok2chatt @ok2chatt started