Node-osc sometimes sends OSC too often: related to IP address?

81 Views Asked by At

I have a local Node.js app on port localhost:3000. I'm using node-osc to message to MaxMSP. My code checks every 2 seconds if there is a reason to send the message (this is related to machine learning and webcam). 95 % of the time this works fine; OSC message might be sent now, then after 2 minutes, then after 10 seconds etc.

However, sometimes the OSC messaging goes crazy by sending a message every two seconds, despite my webcam and machine learning classifications staying the same. If there are no triggering changes, no messages should be sent. I have been thinking if this could be related to the fact that I sometimes change the location and respective IP address where my app functions. Could the system become unstable when switching between two IP addresses? I don't (yet at least) have proof that the "overheating" would come straight after changing the IP address.

Combining OSC with Node.js is new to me so I'm happy for any insights regarding the problem.

Some snippets:

server.js

const express = require("express");
var cors = require('cors');
const app = express();

let broadcaster;
const port = process.env.PORT || 3000;


const http = require("http");
const server = http.createServer(app);

const io = require("socket.io")(server);

const { Client, Message } = require('node-osc');
const client = new Client('xxx.xxx.x.x', 5000); // this IP I keep changing

socket.on("param", function(data) {
  console.log(data);
  let address = data.address;
   client.send(address, data.val);
});

broadcast.js

if (newLabel== "a human" && newLabel !==oldLabel){ // checks this + other changes every 2 seconds
      socket.emit("human");
      sendParam ("/sound", 4);

}

function sendParam(adr, val) {
  let data = {
    address: adr,
    val: val
  };
  socket.emit('param', data)
}

0

There are 0 best solutions below