johnny-five icon indicating copy to clipboard operation
johnny-five copied to clipboard

Error : "1653325998050 Board No connected device found "

Open sanyam1999 opened this issue 2 years ago • 1 comments

I am trying to implement a very basic functionality in my Ecommerce WebApp which I am creating in MERN stack. What I'm trying to do is, turn on an LED Light when an order is received and turn the LED off when Admin processes the order (i.e. when order is shipped and out for delivery). P.S. I am using an Arduino Nano

What I'm doing is at the backend when a new order is created, I call a function "Hardware" through a "createProduct" controller which turns LED on. This step works fine and the led turns on as desired but when order is processed, and "Hardware" is called again by "ProcessOrder" controller, nothing happens and the debugger says " No connected device found" and led stays on. But if I restart my server then LED turns off.

What can I do so that led turns off without restarting server

const jf = require("johnny-five");

exports.newOrder = catchAsyncErrors(async (req, res, next) => { work in controller Hardware(0); //called the function More Work });

exports.processOrder = catchAsyncErrors(async (req, res, next) => { work in controller Hardware(1); //called the function More Work });

function Hardware(status) { const board = new jf.Board({ repl: false ,debug:true}); board.on("ready", function () { const led = new jf.Led("A4"); if(!status) led.on(); else led.off(); }); }

sanyam1999 avatar May 23 '22 17:05 sanyam1999

Hi @sanyam1999

You should only instantiate the board and led one time.

This code is not tested, and if you call newOrder or processOrder too soon it will crash.

const jf = require("johnny-five");

let board, led;

board = new jf.Board({ repl: false ,debug:true});
  board.on("ready", function () {
  led = new jf.Led("A4");
});

exports.newOrder = catchAsyncErrors(async (req, res, next) => {
  work in controller
  Hardware(0); //called the function
  More Work
});

exports.processOrder = catchAsyncErrors(async (req, res, next) => {
  work in controller
  Hardware(1); //called the function
  More Work
});

function Hardware(status) {
  if(!status)
    led.on();
  else
    led.off();
}

dtex avatar May 27 '22 03:05 dtex