Go Down

Topic: Data from Internet to Arduino (Read 2879 times) previous topic - next topic

phinsil6

Hi, I am trying to think of some ways to get data from the internet (say a php page) to the arduino for parsing.  The only current way I can think of is to setup a telnet server on the arduino with a public ip and then use php to send telnet commands to that arduino.  but surely there must be some better way to send some data from the internet to the arduino.  data from arduino to php is quite easy but it doesn't seem to be so easy going the other way.  does anyone have any great ideas or experience towards this problem?

zoomkat

Quote
data from arduino to php is quite easy but it doesn't seem to be so easy going the other way.


Sounds like you want to set the arduino up as a server. There are arduino web server examples available.
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

phinsil6

yes but there isn't a whole lot of good info for getting data submitted on a form or a button being clicked...has anything been done with SSH or any other similar protocols?

Si

You don't need a form. In your PHP you just do a request to the Arduino, like this:

$result = file_get_contents("http://myarduinoURI/page?param1=value1");

So your PHP recieves a request, and in turn sends a request to the Arduino.

and on the Arduino you get the data out of the request parameters.

Its all a little confusing, do you see what I mean?
--
My New Arduino Book: http://www.arduinobook.com

zoomkat

Quote
yes but there isn't a whole lot of good info for getting data submitted on a form or a button being clicked...has anything been done with SSH or any other similar protocols?


The below simple html sends a get request that contains what is typed in the text box to the arduino. The bottom arduino server code receives the get request and displays what was sent in the serial monitor.

Code: [Select]
<form action="http://192.168.1.102:84/"
enctype="multipart/form-data" method="get">
<p>
Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>


Code: [Select]
//zoomkat 12-18-10
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives
//

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString;

//////////////////////

void setup(){

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();

//enable serial data print
Serial.begin(9600);
Serial.println("servertest1"); // so I can keep track of what is loaded
}

void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;
Serial.print(c);
}

//if HTTP request has ended
if (c == '\n') {

///////////////
Serial.println(readString);

  //now output HTML data header
  client.println("HTTP/1.1 204 Zoomkat");
  client.println();
  client.println();
  delay(1);
  //stopping client
client.stop();

/////////////////////
//clearing string for next read
readString="";
 
}}}}}
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

phinsil6

cool, i will try the suggested methods out when i get home...also, instead of reading the received data into a string, what about reading it into a buffer so i can parse each individual byte and do switch case statements accordingly?

Go Up