Flic Home

    Community

    • Login
    • Search
    • Popular
    • Users

    Flic Hub SDK errors when setting UDP setMulticastTTL and setTTL

    Developers
    3
    8
    1414
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jitmo
      jitmo last edited by jitmo

      SUMMARY: When I receive a button event I want to sent a UDP multicast message to several Raspberry Pi's on my network (as they all handle different parts of my home control/automation). When using setMulticastTTL or setTTL I get the error:

      ReferenceError: identifier 'checekType' undefined
      

      ASIDE: this topic is mostly to log the possible typo in duktape or dgram. It is also possible/probable that I am using multicast in the wrong way, so any help with using multicast would be great too 🙂

      CODE: Here is the relevant code snippet (buttons.js) showing just the UDP parts; you can swap out setMulticastTTL for setTTL to get the same error:

      const dgram = require('dgram');
      const server = dgram.createSocket('udp4');
      
      const PORT = 31091;
      const MCAST_ADDR = '234.0.0.0'; // use a class D (multicast) IP address https://en.wikipedia.org/wiki/Classful_network
      
      server.bind({
        port: PORT
      },function(){
        server.setBroadcast(true);
        server.setMulticastTTL(128);
        server.addMembership(MCAST_ADDR);
        console.log('# server.address: ', JSON.stringify(server.address(),null,2));
      });
      

      ERROR: Here is the error message in the console (line numbers will not match above snippet):

      ReferenceError: identifier 'checekType' undefined
          at [anon] (duktape.c:81026) internal
          at setMulticastTTL (dgram.js:248)
          at [anon] (root/Test/buttons.js:21)
          at [anon] (events.js:27)
          at emit (events.js:59)
          at [anon] (dgram.js:117) preventsyield
          at runInit () native strict preventsyield
          at handlePacket (pipe_communication.js:48)
          at readCallback (pipe_communication.js:93) preventsyield
      

      EARLY ANALYSIS: It looks like there is a typo of checekType (should this be checkType?) in duktape.c or possibly dgram.js

      Emil 1 Reply Last reply Reply Quote 0
      • ksportz
        ksportz @Emil last edited by

        @Emil
        Hi, Any news on the FW update. It is getting very frustrating to tell my users to reset all the time. Is there a workaround to restart a module on an error?

        Extra info from Console output "FATAL ERROR:
        uncaught: 'cannot push beyond allocated stack'

        Thanks

        1 Reply Last reply Reply Quote 0
        • Emil
          Emil FlicTeam @ksportz last edited by

          @ksportz the ttl thing has been fixed and will be rolled out in the next firmware of the hub. The thing that only 36 packets could be sent should also be fixed and included in the next fw.

          ksportz 1 Reply Last reply Reply Quote 0
          • ksportz
            ksportz last edited by

            Is there any update here ?

            A reply that it is being looked at would be helpful. As a SW developer it would seem and easy bug to find... exactly 36 messages each time before lockup.

            Would be a great help as at the moment, my client is losing patience .

            Mike

            Emil 1 Reply Last reply Reply Quote 0
            • Emil
              Emil FlicTeam @jitmo last edited by

              @jitmo I'm not a multicast expert, but I would suggest you to use any example code you can find on the web for Node.js for server and client, make that work, and then just put it on the Flic hub.

              1 Reply Last reply Reply Quote 0
              • jitmo
                jitmo @Emil last edited by jitmo

                Hey @Emil, thanks for the quick response!

                Any tips for sending a broadcast UDP packet to multiple Raspberry Pi's (also using Node). Do I need to set the MCAST_ADDR when calling server.bind on the Flic Hub SDK? (I have tried many combinations of ports and addresses on the Flic Hub SDK and Pi's).

                To send a broadcast message from the Flic Hub SDK I use the following:

                const buttonManager = require('buttons');
                const dgram = require('dgram');
                const server = dgram.createSocket('udp4');
                
                const PORT = 31091;             // TCP/UDP port
                const MCAST_ADDR = '234.0.0.0'; // use a class D (multicast) IP address https://en.wikipedia.org/wiki/Classful_network
                
                server.on('message', function(msg, rinfo) {
                  console.log('@ sever.on.message');
                  console.log('# msg: ', msg);
                  console.log('# rinfo: ', JSON.stringify(rinfo,null,2));
                });
                
                server.bind({
                  port: PORT
                },function(){
                  server.setBroadcast(true);
                  server.addMembership(MCAST_ADDR);
                  console.log('# server.address: ', JSON.stringify(server.address(),null,2));
                });
                
                buttonManager.on('buttonSingleOrDoubleClickOrHold', function(obj) {
                
                  var button = buttonManager.getButton(obj.bdaddr);
                  var clickType = obj.isSingleClick ? 'click' : obj.isDoubleClick ? 'double_click' : 'hold';
                
                  var message = button.name+' '+clickType+' '+button.batteryStatus;
                  console.log(message);
                
                  server.send(message, 0, message.length, PORT, MCAST_ADDR, function(err){
                    console.log('@ server.send callback');
                    console.log('# err: ', err);
                    console.log('# server.address: ', JSON.stringify(server.address(),null,2));
                  });
                
                });
                

                Here is a relevant code snippet on the Pi (for brevity I am not showing the error, connect or listening event handlers) :

                const dgram = require('dgram');
                const client = dgram.createSocket('udp4');
                
                client.on('message', (msg, rinfo) => {
                  console.log('@ client.on.message');
                  console.log(`'${msg}' from ${rinfo.address}:${rinfo.port}`);
                });
                
                client.bind({
                  address: '234.0.0.0',
                  port: 31091,
                  exclusive: false
                });
                

                When the Flic Hub SDK sends the UDP message I can see the UDP on.message event on the Flic SDK console, although the on.message event is not triggered on the Pi.

                On the Pi's I have tried address 0.0.0.0 as well as 255.255.255.255, I have tried omitting port. None of these combinations work.

                Could this be due to the TTL issue or am I simply doing something silly like wrong port/address combinations?

                UPDATE: I can get the Flic Hub to send UDP to just one Pi by sending server.send(message, 0, message.length, PORT, <RaspPi_IP>) from the Flic Hub SDK and omitting the address param of client.bind on the Pi (which defaults to 0.0.0.0)... although I'm looking for a broadcast to multiple Pi's.

                Emil 1 Reply Last reply Reply Quote 0
                • jitmo
                  jitmo last edited by jitmo

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • Emil
                    Emil FlicTeam @jitmo last edited by

                    @alastairjamieson seems like a bug. Will fix later in August.

                    jitmo 1 Reply Last reply Reply Quote 0
                    • First post
                      Last post