MIDI over (WiFi) TCP

Posted on
Page
of 2
Prev
/ 2
  • Thr 2019.08.08

    I'm guessing here, so if this sounds far fetched, it's okay to blast me ;-)

    Could it be that the tcpClient instance creation L7 needs to be global, inserted between L1 and L2, rather than defined inside the udpClient bind object? e.g. msgs sent, but no object present to receive them?


    Did you catch this post?

    Out of office, 9th to 26th Aug

    Not sure which time zone you are in, but it's late in the day by Gordon, and I'm sure packing/getting ready is on the agenda. I'm in CST 6hrs behind GMT

  • https://www.espruino.com/Reference#l_net­_connect
    You must place the .on functions inside of the connect callback using the returned socket, e.g.:

    tcpClient.connect({port: 51325, host: "10.1.64.22"}, function(socket) {
        console.log("connected");
       socket.on("close", function() { 
          console.log("end");
       });
    });
    

    How and if your UDP code really works is also questionable, it should be similar:
    https://www.espruino.com/Reference#l_dgr­am_createSocket
    While the example on https://www.espruino.com/Internet is exactly as you did it just doesn't correspond to the documentation.

    And I'd change let tcpClient = require('net'); to const NET = require('net');. It's just a shortcut to the net library, not a tcpClient.

  • @Robin, I tried your suggestion...seems like a good idea. No difference in results though.

    I missed the post about time off, I guess I'll work on other things for a couple weeks, I have plenty of other things to do on this project.

    Thanks for your ideas.

  • holy. freaking. crap. I didn't know there was an argument to the connect callback - the sample code I found didn't have an arg. And yes, putting them inside the callback and using 'socket' made it work. I am now seeing the 0xEF packets being sent. Solved all of the confusion.

    As for the UDP code, it does work, but I don't claim to have written it correctly, I'll change it to match the link you provided.

    So thanks a million for the corrections!

  • Thr 2019.08.08

    @indianajones I think there is a word missing from that first sentence. Shouldn't it have read

    " holy. freaking. crap. . . Batman! " ?

    at least that's how I thought I've heard that!!


    Nice observation maze1980 on the inclusion of the on() method inside the callback.

    As I had no experience with sockcts and Espruino, I could only guess, but I'm glad you now have a solution.




    I don't want to get into a discussion that hijacks this thread, but feel the following statement will cause confusion that are new to Espruino:


    While we are all learning the nuaunces of Espruino Javascript, @maze1980 what justification are you using to suggest changing the var declaration to "const NET = require('net');. It's just a shortcut to the net library"?



    A year ago, I was educated on the syntax to create a local constant copy of a module.

    How to define and reference an array of CONSTANTS in deployed module

    A special syntax for the exports statement inside the module is required. In the past, I have looked up each module to see if there are any comment tid-bits:

    http://www.espruino.com/modules/

    The 'net' module, sadly is not deployed in this manner, as it appears to be part of the build, but did find this one that is quite similar.

    http://www.espruino.com/modules/WebServe­r.js
    Note that syntax is not used as the last exports line here either.




    Additionally, looking over the examples show that each had a connection object assigned to a var declaration.

    https://www.espruino.com/Internet

    Assigning as a constant, although may work under some module designs, prevents making a modification to the underlying copy of that module. What if one would want to change the port designation or the baud rate or something of the sort?

    While I'm not an expert on all the nuances with Espruino, as there is a connection() and on() function along with a few other supporting module functions, I don't believe assigning this particular module to a constant assignment is a smart idea nor was it the authors intended design.

    https://developer.mozilla.org/en-US/docs­/Web/JavaScript/Reference/Statements/con­st
    Let for block scope - maybe depends
    https://developer.mozilla.org/en-US/docs­/Web/JavaScript/Reference/Statements/let­
    It should be var
    https://developer.mozilla.org/en-US/docs­/Web/JavaScript/Reference/Statements/var­

  • @Robin: You don't want to modify the library or module itself.

    const MODULE = require('module');
    MODULE.foo();
    //is the same as
    require('module').foo();
    

    You can use a variable if you want to code like this

    MODULE = require('module1');
    MODULE.foo();
    MODULE = require('module2');
    MODULE.foo();
    

    Happy debugging.

  • Final update on this issue. I have it all working now - I can control my Allen & Heath Qu series mixer via MIDI over TCP using the Espruino Wifi. My high-level understanding was accurate, but you guys helped me figure out how to use the dgram and net libraries properly to make it work. Thanks @Gordon for steering me in the right direction, and @Robin and especially @maze1980 for helping me see the errors in my code. Many thanks.

  • tcpClient.write() and tcpClient.send() throw 'undefined'

    Is it because of let tcpClient = require('net');? You'll have defined tcpClient as a local variable so it won't be available in the global scope

  • @Gordon yes I was completely forgetting some of the rules of scope in javascript.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

MIDI over (WiFi) TCP

Posted by Avatar for indianajones @indianajones

Actions