How to use Ethermega to read params sent by client

Combining the power of the ATmega2560 MCU with onboard Ethernet, a microSD card slot, an efficient switchmode power supply, and a small prototyping area. [Product page]
Post Reply
Johnvan
Posts: 4
Joined: Sat Jul 06, 2013 3:52 am

How to use Ethermega to read params sent by client

Post by Johnvan » Sat Jul 06, 2013 4:16 am

Is there a language like PHP that can be used by the Ethermega so that Client data can be sent and understood by the Ethernet server. Is the client data read by cgi, is there a Web page I can go to to learn how.

Johnvan
Posts: 4
Joined: Sat Jul 06, 2013 3:52 am

Re: How to use Ethermega to read params sent by client

Post by Johnvan » Tue Jul 09, 2013 1:23 am

Say I have a Form Text Box that the client inputs data and presses Submit. How do I read what is in the box at the server. client.read maybe but how.

regards Johnvvan

angusgr
Freetronics Staff
Freetronics Staff
Posts: 853
Joined: Tue Apr 09, 2013 11:19 pm
Location: Melbourne, Australia
Contact:

Re: How to use Ethermega to read params sent by client

Post by angusgr » Tue Jul 16, 2013 10:56 pm

Hi John,

You can't exactly use PHP with the EtherMega, but there are ways to write sketches on the EtherMega to interpret information from the HTTP request (like form fields, etc.) and then react accordingly. This is the equivalent to what a CGI application or PHP script would do on a full-size web server.

The easiest way to do this is to use one of the pre-existing HTTP server libraries. Webduino is one of the best ones I know of, you can get it here:
https://github.com/sirleech/Webduino

Or there's also TinyWebServer as an alternative:
https://github.com/ovidiucp/TinyWebServer

(Take a look at some of the example sketches in either library to see how to make interactive behaviours via HTTP.)

- Angus

(Fun fact: Chris Lee aka "sirleech" who now maintains the open source Webduino project also co-runs Australian Robotics in Canberra, who are a Freetronics reseller! Although that's not why I recommended Webduino. :).)

Johnvan
Posts: 4
Joined: Sat Jul 06, 2013 3:52 am

Re: How to use Ethermega to read params sent by client

Post by Johnvan » Thu Jul 18, 2013 9:28 am

Thankyou very much for your response, it is just what I was looking for.

I did find a way to transfer client information to the server through cient.read as follows

Code: Select all

    while (client.connected()) 
    {
      if (client.available()) 
      {
        char c = client.read();
        x = x + c;
where x is a String object and will contain quite a bit of information on the client including GET information (parameters) and in fact does all I needed from the web server.

But, the webduino utility wiill make things a lot easier and more readable.

Thanks again.

Johnvan

Post Reply