-1

the question is pretty straight forward. I would like to control a drone (Bitcraze Crazyflie), using a Google Home. The Input is: "Drone fly to x3 y4", processed as usual by Firebase etc. Resulting in the Google Assistant Output: "Flying to x3 y4", but also an Ouput in e.g. JSON format, to navigate the drone. Because the drone works with Python, this is the preferable Output language.

EDIT Added more Context

Currently I'm using an node server running this code:

        'use strict';

    // Import the Dialogflow module from the Actions on Google client library.
    const {dialogflow} = require('actions-on-google');

    // Import the firebase-functions package for deployment.
    const functions = require('firebase-functions');

    // Instantiate the Dialogflow client.
    const app = dialogflow({debug: true});

    // Handle the Dialogflow intent named 'fly'.
    // The intent collects parameters named 'xaxis, yaxis'.
    app.intent('fly', (conv, {xaxis,yaxis}) => {
        const xAxis = xaxis;
        const yAxis = yaxis;
        // Respond with the user's coordinates and end the conversation.
        conv.close('Roger that, flying to ' + xAxis + ", " + yAxis);

    });

    // Set the DialogflowApp object to handle the HTTPS POST request.
    exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

Now I would like to get the const xAxis and yAxis and use them in a Python program. I've tried using

process.stdout.write(xAxis + yAxis);

Listening in Python with something like

out = sensor.stdout.read(1)

but the code will be run on the Google Server, so local port listening does not work.

Thanks for your help.

Thomay
  • 1
  • 2
  • Welcome. Can you, please, elaborate on the execution, input and output? Also, add a little more information about the stack used and [MRE](https://stackoverflow.com/help/mcve)? – edd Apr 14 '20 at 14:29
  • Added more context – Thomay Apr 14 '20 at 16:50
  • You will probably need some kind of message broken to allow communication between the drone and the datacenter. – Tom Apr 14 '20 at 19:22
  • Currently I’m trying to simply send a HTTP POST request with Node and then GET the request from Python. I just don’t know where to send the requests. – Thomay Apr 14 '20 at 20:41

1 Answers1

0

The best approach is having another machine on GCP rather than communicate with your home PC. You'll learn more and have an easier time, in the long run, building solutions. As I'm more familiar with AWS rather than GCP, I can't cite the network/security components you need to configure but the docs say you don't have to. So, in theory, it should be just about spinning up another compute machine with your Python code running on it.

Were you to decide on speaking to your home PC, you'll need to forward ports on your router. It is, currently, acting as a firewall for your LAN devices and doesn't permit outside machines initiating connections to your internal addresses. e.g. your GCP machine initiating a connection to your home PC. The other way around is permitted, by default. If you think about it, your router has one WAN IP address but your LAN can have multiple devices (multiple LAN IPs). If your GCP machine connects to your router WAN IP at port 8080, to which LAN IP should it connect? You have to help your router and explicitly tell it.

Once you have a networking solution in place, you can debug the connectivity itself (server can talk to client) by using netcat (nc/ncat, depending on Linux distro). Netcat is a versatile networking tool with which you can purely open connections (before you add in your program to the debugging stack) and assure the networking part of your solution is working as intended.

nc -v <destination_ip> <port>

Simple.

This should get you to where you want to be. A working connection between your GCP drone controller and the Python processor machine.

Bonus - If you want a quick way to have your machine (PC or otherwise) listen on a port, you can use Python's built-in HTTP file server module with

python -m http.server 8080

This will serve files from the directory you ran this command. So, keep that in mind if you're open to the world.
Or, a simple "echo server", using netcat.

nc -v -l 8080

Lastly, for a solid Python HTTP API framework, I highly recommend FastAPI. It allows quickly writing a HTTP API server with, for example, a POST method that your GCP drone controller can call. It has the great bonus of generating both interactive OpenAPI docs, example, for your code and, using 3rd party tools from Swagger (that you can see in the example linked), generate server/client/testing "boiler plate" code. Did I also mention their docs are great?

edd
  • 1,307
  • 10
  • 10