alvarolorentedev / tellojs

a package to be able to control and recieve information from the dji tello
MIT License
40 stars 12 forks source link

Can't listen the message when Receive Tello Video Stream #2

Closed akoharu closed 5 years ago

akoharu commented 5 years ago

You have to send "streamon" command before bind data stream if data stream not available

alvarolorentedev commented 5 years ago

completly true :). Sorry I forgot that one. I will add it tomorrow morning. Thanks a lot for reporting.

alvarolorentedev commented 5 years ago

latest version has the message sent si video stream should work. You can retry again.

I actually noticed that i left it undocumented because wanted to understand better how to pipe the video stream. Any idea is welcome :)

arthursp commented 5 years ago
const {spawn} = require('child_process');

function startStream() {
        return new Promise(resolve => {
            this.sendCmd('streamon').then(() => {
                this.tello_video = dgram.createSocket('udp4');
                this.h264encoder_spawn = {
                    "command": 'mplayer',
                    "args": ['-gui', '-nolirc', '-fps', '35', '-really-quiet', '-']
                };    
                this.h264encoder = spawn(this.h264encoder_spawn.command, this.h264encoder_spawn.args);
                this.h264encoder.on('close', (code) => {
                    console.log(`child process exited with code ${code}`);
                });
                this.h264encoder.stderr.on('data', data => {
                    console.log("mplayer error", data.toString());
                });
                this.tello_video.on('message', msg => this.h264encoder.stdin.write(msg));
                this.tello_video.on('listening', () => {
                    console.log(`tello_video listening ${this.tello_video.address().address}:${this.tello_video.address().port}`);
                    resolve(this)
                });
                this.tello_video.bind(11111, '0.0.0.0');
            });
        });
    }
alvarolorentedev commented 5 years ago

thanks for the example code. I need to do a small fix that I just noticed, but i think the translation to the library will be:

const {spawn} = require('child_process')
const sdk = require('tellojs')

const bindVideo = async () => {
    const h264encoder_spawn = {
                    "command": 'mplayer',
                    "args": ['-gui', '-nolirc', '-fps', '35', '-really-quiet', '-']
                }
    const h264encoder = spawn(this.h264encoder_spawn.command, this.h264encoder_spawn.args)
    const videoEmitter = await sdk.receiver.video.bind() 
    videoEmitter.on('message', msg => h264encoder.stdin.write(msg))
}

bindVideo().then(console.log).catch(console.error)

Small advantages is at the await of the command streamon has been accepted by the tello drone.

alvarolorentedev commented 5 years ago

done. it works :). Tested today.

Added an example based on yours @arthursp.

const {spawn} = require('child_process')
const sdk = require('tellojs')

const bindVideo = async () => {
    const h264encoder_spawn = {
                    "command": 'mplayer',
                    "args": ['-gui', '-nolirc', '-fps', '35', '-really-quiet', '-']
                }
    const h264encoder = spawn(h264encoder_spawn.command, h264encoder_spawn.args)
    const videoEmitter = await sdk.receiver.video.bind() 
    videoEmitter.on('message', msg => h264encoder.stdin.write(msg))
}

sdk.control.connect()
.then(bindVideo)
.then(console.log)
.catch( console.error)