简体   繁体   中英

Send to Python script from PHP/JavaScript

I'm working on a project where I send data to an Arduino from an Apache running on a Raspberry Pi.

Sending data to the Arduino requires the Raspberry Pi to execute a Python script.

The controls are detected and acted upon in JavaScript.

I have found several ways to start the Python script from the JavaScript code. However, I can't find how I can then send data to the Python script from the JavaScript code so that the Python code can send data to the Arduino.

Any help is appreciated!

I solved it using Flask, a Python framework.

Instead of the console.log(), it is now an ajax-function that calls a method in the Python code, where the serial port can stay open.

$.ajax({
    url: "{{ url_for('move') }}", // This is Flask code that call a Python function
    method: "POST",
    data: {
        move: currentMove
    },
    success: function() {
        console.log('move: ' + currentMove);
    }
});

Maybe you can write something in a file in your Rasperry Pi.

I found this on the Web : interprocess python/java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM