Control MPD on RPI by MPC console commands that sends from Blynk

Hello Blynk World.
Let me tell to everyone- Now I have a
Local Blynk Server on RPI , that works more stable and quick.

Many of my problems and questions was solved by installing this awesome decision.

Now I have an idea to control music based on MPD player daemon and MPC client. Both installed into One RPI hardware.

MPC client have some commands (for example “mpc pause”, “mpc next” etc. ) that typing exactly in RPI`s console to control player

It will be very great sending this commands from Blynk, I mean write it to the code, that can send command automatically by event.

But don`t know what I have to do with…

Any ideas about this, guys?

Thanx in advance.

In future this decision make a big breakthrough to me in creating a convenient multiroom system.

Hello. That could be easily done. Here was code somewhere for that - regarding how to call bash scripts from NodeJs Blynk script.

1 Like

ok. Thanks. Try to learn it)

One more question: can I send bash commands to RPI using C++ code in D1 mini locally?
If yes, how can I do this?

@Dmitriy as far as I know the D1 Mini doesn’t have a NodeJS implementation.

Set the Pi up as a client in addition to it being a server. Your D1 can use the Bridge widget to interface with the client on the Pi. The client can then call any child_process on the Pi that you can call as if you were issuing the commands via the console.

You could also look at shelljs as an alternative to child_process.

1 Like

@Costas I mean you could send any command from hardware to local server on rasp pi or to client on rasp pi…

@Dmitriy how would the D1 send anything meaningful to the local Pi server other than the normal Blynk stuff?

@Costas my bad, you’re right, removed my answer.

1 Like

so I`ll do something like this

from d1 mini to RPI client- bridge.virtualWrtie(v2, 1);

When RPI client received this value it open nodeJS code that sends himself (exactly this RPI I mean)
bash commands. Right?

@Pacer spot on.

" from d1 mini to RPI "-this event is clear for me.
but NodeJS… …like cloudy puddle…

I peeped here Execute external bash script on server with blynk))

I understand that after installing Blynk library and Node JS to RPI, I need the file blynkclient.sh with this content:

#!  /usr/bin/env node

var Blynk=require('/usr/lib/node_modules/blynk-library/');

const spawn=require('child_process').spawn;

var AUTH= 'my token';

var blynk= new Blynk.Blynk (AUTH, options={

connector : new.Blynk.TcpClient (options={ addr: "my server IP", port : "my server's port"})
});
var v1= new blynk.Virtual pin (1);

v1.on ('write', function (param) {
const sh=spawn('/bin/sh', ['/home/pi/player.sh']);
}); 

And in file Player.sh I need this:

#! /bin/bash
mpc next

(for example to turn next trak on the player).

RIght or not?

Looks about right except blynkclient is not a bash script.

Rename as .js

Hello ALL.
Now I realising this music project and have one question:

Music player client have bash command “mpc current” to show currently playing song info.

Is it possible to transmit this song info to Blynk Virtual LCD Display Widget?
If so, how I can do that?
Thanks for help in advance.

If you can get the data in text/string form, then you should be able to send it to the Widget with the normal lcd.print(x, y, "Your Message"); command. Note, that the LCD does not support scrolling or linefeed, so perhaps sending to the terminal instead.

That’s clear.
And what about “lcd. print” in Node JS? Is the code look different?
Obviously I can’t get what I want simply insert bash command in code.
Guess I need to take this song info into separate text file and then "lcd.print (x,y, “/home/pi/file with text.h”);
…or something else…

Am I right?

Hello ALL.

Guys, who can help me with Node JS? (See previous post).

I know enough basic to build a semi decent project with a bit of interfacing to the underlying OS but really the coding is down to you from the examples available.

Ok.

When in examples I can see the code of LCD Widget for Node JS version?

They are in the GitHub but if you Google “Blynk nodejs” you should find some interesting stuff.