Reputation: 113
I am completely new to web development, so please forgive me in case this question is superfluous. Here is what I am trying to do: I have multiple Arduinos (equipped w/ EthernetShields) that are collecting and displaying data (using sensors and LCD screens). All Arduinos communicate with a webserver hosting a MySQL database and a webpage visualizing the data. The Arduinos are themselves capable of hosting minimalistic webservers that can run some simple html/php/etc...
My question is: What is the most straightforward way to implement the communication between the Arduinos and the main server, so that I can send data back and forth between them, without any user interaction? The data consists of relatively few integer values and short strings of text. Security is not an issue.
Edit for clarity: How to continuously send data back and forth between two web-servers? Assuming that I use PHP, what is a simple way to do this? All tutorials for the GET and POST methods included the use of 'form action', which to my understanding requires user interaction.
Upvotes: 1
Views: 2037
Reputation: 108786
If I understand you right, you have a central web server that needs to communicate with a whole bunch of arduinos. You need to send information in both directions between the arduinos and the central server. And, you want to use web (http / tcp / ip ) protocol to do this.
You face a choice:
Do you want to have the central server initiate the communication? Or do you want to have each arduino initiate the communication?
I think the second choice is pretty good. It means that you can add new arduinos to your system without somehow reconfiguring the central server. But, I don't know much about your application so there might be some reason this is a bad idea.
So, what you do is implement a simple web CLIENT (not a browser) on each arduino. Then, on a regular schedule you have the each arduino do a web request to the main server. Depending on the amount of data you need to send from the arduino to the server, you can use a GET or a POST. If the data is small, you can use a GET request. For example if it's temp and humidity you can send the request like this once a second.
http://server/upload.php?temp=65&humidity=78
In response to this, the central server can handle this data correctly. You'll be able to tell which arduino it's from by the client internet address REMOTE_ADDR
.
Then, the server sends a response that contains whatever data the server needs to send to the arduino.
See how this goes? each second each arduino hits the web server saying "here's what I have for you. What have you got for me?"
Upvotes: 1