# Creating a node for sending / receiving data via sound card!

**URL:** <https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399>\
**Category:** General\
**Created:** [16 June 2020 11:44 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399 "2020-06-16T11:44:36Z")\
**Posts on this page:** 12\
**Page:** 3

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [23 June 2020 19:58 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/41 "2020-06-23T19:58:32Z")

</div>

thats why in my version i only ever call the repeat function in the return of the exec. So it doesnt do anything like that. Did you look at the code i send you in the pm

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [26 June 2020 12:20 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/42 "2020-06-26T12:20:48Z")

</div>

So i started working on the listen node , and i have a problem with spawning the `minimodem --rx + options + baudmode `  
I am using `child_process`-s `spawn` and i cant configure it to run as it should  
After reading the [documentation](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) and copying the sample code to mine project i always get an error from minimodem `stderr: usage: minimodem [--tx|--rx] [options] {baudmode} `

Here is my code:

```
  function getlisten(options){
        const ls = spawn("minimodem" ,[options + " 300"]);
        node.status({fill:"blue", shape:"dot", text:"Listening!"})
        ls.stdout.on("data", data => {
            console.log(`stdout: ${data}`);
        });
        
        ls.stderr.on("data", data => {
            console.log(`stderr: ${data}`);
        });
        
        ls.on('error', (error) => {
            console.log(`error: ${error.message}`);
        });
        
        ls.on("close", code => {
            console.log(`child process exited with code ${code}`);
        });
        
    }

```

options is a string (eg: --auto-carrier --confidence 2.5 )  
300 should be replaced with baudmode variable.

I tried several different orders but none is working as it should!

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [26 June 2020 12:35 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/43 "2020-06-26T12:35:37Z")

</div>

So aperantly there was a really simple sollution for this 😃  
Just by adding the ' before and after options string it got working!  
`const ls = spawn("minimodem" ,[+ "'" + options +"'" + " 300"]);`

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [26 June 2020 12:40 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/44 "2020-06-26T12:40:39Z")

</div>

Normally this shouldn’t be necessary and its not really the recommended way. What is true is that the child\_process.spawn() exepects an array of arguments with one argument per array element and not one string of options. So it should be something like really to use it correctly : `spawn("minimode",["--auto-carrier","--confidence","2.5","300"]);`

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [26 June 2020 12:49 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/45 "2020-06-26T12:49:41Z")

</div>

Okay i will convert the options string to an array and will try again , so far the minimodem executes successfully , but i do not get any data from it ☹

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [27 June 2020 21:12 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/46 "2020-06-27T21:12:42Z")

</div>

Can anyone help? Decided to ask a question after being stuck for a whole day...  
[Stackoverflow Question.](https://stackoverflow.com/questions/62615404/joining-a-sequence-of-string-nodejs)

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [27 June 2020 21:34 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/47 "2020-06-27T21:34:22Z")

</div>

Maybe try a function something like this:

```auto
let timeout = false;
let outputBufferArr = [];

function timeoutConcat(data){
    
    if(timeout) {
        clearTimeout(timeout);
        timeout = false;
    }
    
    outputBufferArr.push(data);
    
    timeout = setTimeout(()=>{
        let message = Buffer.concat(outputBufferArr);
        console.log(message.toString());
        outputBufferArr = [];
    }, 500);
    
}

```

which you call from the stdout on data part:

```auto
minimodem.stdout.on('data', (data)=>{
    timeoutConcat(data);
});

```

Not tested at all just wrote down what i think might work logically.  
It should in theory log the output of all data received so far as soon as no new data arrives for 500 ms.

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [27 June 2020 21:36 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/48 "2020-06-27T21:36:13Z")

</div>

Thank you for your quick answer once again sir 🙂 Will test it right now

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [27 June 2020 21:38 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/49 "2020-06-27T21:38:03Z")

</div>

i edited the code above, of course the variables need to be declared as let or var and not const 🙈 and it was logging the wrong var too. That happens when you write code free form late at night 😂

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [27 June 2020 21:38 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/50 "2020-06-27T21:38:27Z")

</div>

Yes i just saw that error

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [27 June 2020 21:43 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/51 "2020-06-27T21:43:04Z")

</div>

Well its working great i think i would experiment with the 500ms delay (probably add a setting for it) so user can edit it.  
I took a brake from 7pm to 10pm so i am ready to roll the entire night 😂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 July 2020 21:54 UTC](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399/52 "2020-07-11T21:54:42Z")

</div>

Closed on 11 July 2020 21:54 UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/creating-a-node-for-sending-receiving-data-via-sound-card/28399.md?page=2)
