Reputation: 460
I'm starting a new project where I need to send data from an Arduino to a Java Server. I would like to use the Arduino Wifi shield. Afterwards the java server will send the received data to a web service trough a 3G Router.
Is this setup possible? Does there exist an API to set up a socket connection between an Arduino and a Java Server?
If not which possibilities do i have? Thank in advanced
Upvotes: 0
Views: 6069
Reputation: 1655
Similar to the answer by @gray which is a "push" solution, is to have the java server query the Arduino at some interval ("pull" model). To do this, just see the Web hosting example in Arduino's ethernet samnple library. You can modify it, to have the arduino return the value of its sensors as part of its http response.
Upvotes: 1
Reputation: 116918
There is certainly a number of ways you can do this. You can use the Arduino Ethernet library to make connections to your Java server. Here's a nice little program called ClientConnect which uses the ethernet device to make a connection to a server. This little program sends a web request to the server with the following lines:
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
On the server side it would be easiest to use some sort of simple servlet and utilize a Java web framework such as Tomcat.
Your Arduino transactions would then just look like simple web transactions:
GET /your-path-to-your-servley?field1=value1&field2=value2 HTTP/1.0
[[ empty line here ]]
This will send a set of field/value pairs to your Java webserver which will call your servlet. In the example at the top, "q"
is the field name and "arduino"
is the value.
Hope this helps.
Upvotes: 2