0

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!

2 Answers 2

1

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);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

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

I found this on the Web : interprocess python/java

2 Comments

Would writing to and reading from a file not slow down the communication compared to maybe other solutions? It should react immediatly when there is a change.
Have you checked the linked about sockets ? It looks like that it works. I don't know your answer but I would be interested in your solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.