Hello ![]()
I am looking for a way to have a code on a computer written in java run procedures "certain pieces of code" on an arduino something like remote procedure call between arduino and java.
I wanted to use the java RMI but the thing is I don't think the JDK can be installed on arduino.
I also do not want them to be connected serially.(through the internet)
Does anyone have an idea of how this can be done?
Thank you.
Play frequency modulated tones through the computer's audio output.
Thank you but the PC and the arduino do not have to be at the same place.
nadakh:
Thank you but the PC and the arduino do not have to be at the same place.
Play the frequency modulated tone into a FM or AM radio and use another radio to receive the tone.
You can create a simple webserver with Java and you can write an Arduino program that acts as a client and accesses the server to get data.
If your Arduino I/O requirements are limited you could probably use an ESP8266 in place of the Arduino. Alternatively you could use an ESP8266 as a WiFi module in conjunction with an Arduino.
It would also be possible to have the server on the Arduino end and the client on the PC end.
...R
mikb55:
Play the frequency modulated tone into a FM or AM radio and use another radio to receive the tone.
Thank you.
Robin2:
You can create a simple webserver with Java and you can write an Arduino program that acts as a client and accesses the server to get data.If your Arduino I/O requirements are limited you could probably use an ESP8266 in place of the Arduino. Alternatively you could use an ESP8266 as a WiFi module in conjunction with an Arduino.
It would also be possible to have the server on the Arduino end and the client on the PC end.
...R
I was able to connect Arduino(using an ethernet shield )and a PC using java socket programming and they were able to communicate the problem lies in sending methods / pieces of code(RPC) and not strings. So how can I invoke methods on arduino from a PC using java code?
If you can communicate from Arduino to Java over TCP socket, what more do you need?
If you send an 'X' or a 'B' you can have Arduino code like this
if (receivedChar == 'X') {
 myFunctionX();
}
if (receivedChar == 'B') {
 myFunctionB();
}
If you know how to program Java then an Arduino should be a walk-in-the-park ![]()
...R
nadakh:
I was able to connect Arduino(using an ethernet shield )and a PC using java socket programming and they were able to communicate the problem lies in sending methods / pieces of code(RPC) and not strings. So how can I invoke methods on arduino from a PC using java code?
Search for "Java firmata".
Robin2:
If you send an 'X' or a 'B' you can have Arduino code like thisif (receivedChar == 'X') {
myFunctionX();
}
if (receivedChar == 'B') {
myFunctionB();
}
If you know how to program Java then an Arduino should be a walk-in-the-park :) ...R
That sounds good but the thing is these functions aren't written in the arduino file they are written in the java file on the PC , and they are not always the same they are changing.So choosing the function according to a letter wouldn't be a general solution. I want the java file to send a Procedure to run on the arduino and the arduino then replies back with the value.
mikb55:
Search for "Java firmata".
I will look into it. Thank you.
Juraj:
If you can communicate from Arduino to Java over TCP socket, what more do you need?
I want the server to be able to send procedures to run on its clients what I have now is a server sending and receiving strings with its clients.
nadakh:
That sounds good but the thing is these functions aren't written in the arduino file they are written in the java file on the PC , and they are not always the same they are changing.So choosing the function according to a letter wouldn't be a general solution. I want the java file to send a Procedure to run on the arduino and the arduino then replies back with the value.
That simply won't work. An Arduino program is compiled before being uploaded to the Arduino. So everything the Arduino is required to do must be decided before the program is uploaded. After that the program on the PC can instruct the Arduino to run any one or more of the functions that are part of the uploaded program.
Of course the process can also work the other way - the Arduino could send a command to the PC to select a Java function to run.
This has all the signs of an XY Problem. If you tell us what your project is then it will be much easier to give useful advice.
...R
Robin2:
That simply won't work. An Arduino program is compiled before being uploaded to the Arduino. So everything the Arduino is required to do must be decided before the program is uploaded. After that the program on the PC can instruct the Arduino to run any one or more of the functions that are part of the uploaded program.Of course the process can also work the other way - the Arduino could send a command to the PC to select a Java function to run.
This has all the signs of an XY Problem. If you tell us what your project is then it will be much easier to give useful advice.
...R
Ok so an overview of the project. There is a single server and multiple clients (Let the server be a PC and the clients be an arduino-PC -RaspberryPi). The code is on the single server/PC. Now this server wants to execute a big task that consumes time and processing power.So,we distribute this task to run on multiple clients simultaneously (the clients don't what the task is ).The clients then send the results back to the server.
nadakh:
Ok so an overview of the project. There is a single server and multiple clients (Let the server be a PC and the clients be an arduino-PC -RaspberryPi). The code is on the single server/PC. Now this server wants to execute a big task that consumes time and processing power.So,we distribute this task to run on multiple clients simultaneously (the clients don't what the task is ).The clients then send the results back to the server.
Build a tool chain that looks something like:
Java source code -> C source code translation -> AVR compiler -> network connection to another computer -> upload to Arduino via ISP programmer (to avoid using the serial interface as per your project constraint).
If this sounds like lots of work, you would be correct.
mikb55:
Build a tool chain that looks something like:
Java source code -> C source code translation -> AVR compiler -> network connection to another computer -> upload to Arduino via ISP programmer (to avoid using the serial interface as per your project constraint).If this sounds like lots of work, you would be correct.
I can connect the arduino serially to the PC to upload the code initially . Afterwards ,the PC and arduino communicate through the internet.
nadakh:
So,we distribute this task to run on multiple clients simultaneously (the clients don't what the task is ).
Let's try to deal with this in very simple terms.
Imagine that you have an Arduino program that only knows how to multiply 2 numbers and how to add 2 numbers.
The PC could send a message to the Arduino with two numbers and an instruction to multiply them or to add them. Before it gets the message the Arduino would know HOW to do the tasks but it would not know WHICH task it will be asked to perform.
The PC could NOT send a message to the Arduino expecting it to subtract one of the numbers from the other because the Arduino program would not know how to do that. (Well the PC could send the message, but it would get no response)
I suspect you fondly imagine that the Arduino will be able to do something it had not been programmed to do - it won't.
And all the work that your PC would need to do to create and send a new program to the Arduino (for example how to subtract) would completely negate any performance improvements you were hoping to achieve by farming out some of the computations.
Something like what you have in mind MIGHT be possible with an RPi running Python which is an interpreted language. I have no idea if there would be any net performance benefit.
...R
Robin2:
Let's try to deal with this in very simple terms.Imagine that you have an Arduino program that only knows how to multiply 2 numbers and how to add 2 numbers.
The PC could send a message to the Arduino with two numbers and an instruction to multiply them or to add them. Before it gets the message the Arduino would know HOW to do the tasks but it would not know WHICH task it will be asked to perform.
The PC could NOT send a message to the Arduino expecting it to subtract one of the numbers from the other because the Arduino program would not know how to do that. (Well the PC could send the message, but it would get no response)
I suspect you fondly imagine that the Arduino will be able to do something it had not been programmed to do - it won't.
And all the work that your PC would need to do to create and send a new program to the Arduino (for example how to subtract) would completely negate any performance improvements you were hoping to achieve by farming out some of the computations.
Something like what you have in mind MIGHT be possible with an RPi running Python which is an interpreted language. I have no idea if there would be any net performance benefit.
...R
Thank you very much for your reply. Is it possible to have the server(PC) compile the code as a an arduino virtual machine then the server sends the code to be executed on the arduino ?
nadakh:
Thank you very much for your reply. Is it possible to have the server(PC) compile the code as a an arduino virtual machine then the server sends the code to be executed on the arduino ?
The simple way to do that would be with the server connected to the Arduino with a USB cable so it could upload a program in the same way that the Arduino IDE uploads programs.
The regular bootloader on an Arduino is a program that monitors the serial connection at startup and if it recognizes the programming commands from the Arduino IDE it accepts the bytes of data that come to it and it saves them as program code. I guess, in theory, you could write a completely different bootloader that expects to get code from another source. But you will probably have to figure that out yourself.
Another option, that may be simpler, might be to have two Arduinos at a location that are connected to each other. One of them would permanently have a program that could accept code from the server and upload it to the other Arduino.
However before you start thinking about any of that you need to consider the cost, in terms of additional PC computing time, of creating and compiling and uploading an Arduino program when what you seem to be trying to do is reduce the computing load on the PC.
I can't understand why you are even considering the use of an Arduino for this type of project. By the way, what is the project? Something useful like mining Bitcoins?
...R