Welcome to Our Community

Some features disabled for guests. Register Today.

Socket.io connection to openbuilds control

Discussion in 'Control Software' started by bullbearpig, Feb 25, 2023.

  1. bullbearpig

    Builder

    Joined:
    Feb 1, 2023
    Messages:
    2
    Likes Received:
    0
    Hi all,

    I am trying to use the socket.io-client npm package to receive websocket events from the control software. I have seen a few other threads with some troubleshooting info but still can't get it to work.

    The code is simply:

    io = require('socket.io-client');
    var socket = io('http://127.0.0.1:3000/');

    socket.on('status', function(status) {
    console.log(status)
    });

    My understanding is this should print out a status every 400ms or so. However I am not receiving any events.

    I have tried listening to many other events that should be emitting according to the code on github, but nothing's coming through.

    I did notice that as soon as I run the script, the Log / Serial console of the control software goes nuts, similar to if I open http://127.0.0.1:3000 in a browser tab, so it seems like it is detecting a new connection. However it just keeps printing and doesn't stop, and the controller status keeps toggling from "Running" to "Idle" and back until I kill the script, then it stops.

    Any help appreciated,

    Nick
     
  2. sharmstr

    sharmstr OpenBuilds Team
    Staff Member Moderator Builder Resident Builder

    Joined:
    Mar 23, 2018
    Messages:
    2,059
    Likes Received:
    1,449
    Its 100ms : OpenBuilds-CONTROL/index.js at master ยท OpenBuilds/OpenBuilds-CONTROL

    Peter can answer this better than I, but is there a reason you can't run it from a javascript macro from within control? If you can, then you can use this

    Code:
    socket.on('status', function(status) {
    console.log(status)
    });
    And you can use this something like this (obviously swap out laststatus.comms with whatever you want to get)

    Code:
    setInterval(function() {
        console.log(laststatus.comms)
      }, 100);
    This will also give you the ability to control the polling interval.
     
  3. bullbearpig

    Builder

    Joined:
    Feb 1, 2023
    Messages:
    2
    Likes Received:
    0
    No, running from within control won't work for my application. I am looking to communicate with the blackbox from a separate application to do things like homing, getting positions, sending gcode commands. Is my approach of using sockets through control convoluted, maybe there is a more direct way?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice