0

I have above average html experience, and have also dabbled with a bit of PHP as well.

I am now getting into Arduino and have connected it to the internet via an Ethernet module.

The issue is the Arduino doesn't have much memory (30KB !!) so having PHP to handle server-side code is out of the question and multiple pages might also be difficult (maybe not possible even).

Obviously this will get into C++ territory which is even further down the rabbit hole, but i would appreciate if anybody could give me some pointers as to which way to dig down instead of having to cover the full basics of C++ (using Arduino has "spoiled" me, i guess).

There are various libraries which help with doing the grunt work as far as coding goes, but i'm having trouble trying to figure out which parts of a library does what, as well as trying to translate between the different methods of each particular library - one certainly needs to know C++ to be able to read the different libraries.

One tutorial showed the possibility for a button to be placed on the page like so;

<form METHOD=get action=" (*(baseurl)*) ">
<input type=hidden name=**cmd** value=1>
<input type=submit value="LED Off">
</form>

<form METHOD=get action=" (*(baseurl)*) ">
<input type=hidden name=**cmd** value=2>
<input type=submit value="LED On">
</form>

but the library itself is now defunct, and i can't figure out where the value of 'cmd' would be used within the newer library that i now use.

Here is some code remnants that was still on the tutorial page;

if ((cmd==1)||(cmd==2)){ 
         if (cmd==1)
           {LEDOnOff(0);delay(100);}
           else
           {LEDOnOff(1);delay(100);};
         plen=print_webpage(buf);
    }

es.ES_make_tcp_ack_from_any(buf); // send ack for http get
es.ES_make_tcp_ack_with_data(buf,plen); // send data

In PHP it would be easy to handle it with the GET method, but now i'm baffled how to "catch" that 'cmd' value with just C++.

If anyone is aware of the EtherCard library, that's what i'm using - and i could post the relevant .cpp file or functions therein if i knew what sort of keywords i should be looking for.

Could anybody give hints as to what sort of methods could be employed to make a sparse interactive webpage ? There are examples with 'refresh' as well as displaying information about sensors connected to the Arduino - but none that seem to show how a user/client could interact, aside from that old library with the example mentioned above.

  • In my case, I would write a pretty simple HTTP server. Requests index.html, send it the buffer which contains that single button. When the user presses the button, the browser would do a POST to leds.html with the data. The simple HTTP server will be able to parse that with simple C/C++ string manipulation and there is your stuff. You can make it if the button ON was pressed, let it return a cmd value of 1 and that signals the LedOnOff() to turn on the LED. (HTTP servers aren't that hard to write. They are usually a few hundred lines for a very simple one) – Levente Kurusa Mar 02 '14 at 07:13
  • woah - "HTTP servers aren't that hard to write. They are usually a few hundred lines for a very simple one" i guess i have a LONG way to go; thanks for the response, it helped me to better search what i need to be looking for and have now found the many threads on SO re: "webservers using C++" will have to wade through all the suggestions like libcurl, netlib, or boost-asio(?) which seems quite extensive but more advanced than i probably am able to handle in the near future. thanks again for your repsonse. – Bouncing_Back Mar 03 '14 at 04:11

1 Answers1

0

This question was apparently an 'alias' for "How to write a webserver or do HTTP programming in C++" of which there are many threads on SO with the various suggestions on libraries one can use such as libcurl, netlib and boost-asio.

The learning experience continues, and this question is now answered as a stepping stone to "where to go next to reply the question".

i don't know if we're allowed to cross-link to other questions but here are the links that helped me to get closer to the answer to my question;

Build a simple HTTP server in C

Simple webserver in C++?

Community
  • 1
  • 1