Probably simple, but I have just started dabbling in Perl. Working on a personal project for the home, I am trying to find a simple, quick, and lightweight method of integrating HTTP input into one of my projects. Most of my similar efforts have utilized NodeMCU’s. Years of using these seem to be clouding my judgement for an effective solution in Perl, a language I am learning.

My existing host’s core code is essentially an endless loop managing a series of host events. The client should be able to send occasional requests to either ‘set something’ or ‘inquire about something.’ The host responses in simple text, either 'ERR', 'OK' or with a short string. The reply to the client will be almost immediate, as the requests just set or return variables. Growing up with dial-up modems, my commands are AT-styled.

For example, to start execution, the follow client request results in $runflag=1
http://host:8080/CMD=ATES

I’ve looked at a few packages, such as HTTP::Server::Simple::CGI. While trying to incorporate the associated examples into my code, all block my main program while waiting for a client. The solution I need, is one where I can frequently poll for a client request. My main loop fire about 5 times a second.

Other notes:
- Single client, via HTTP (no SSL), on local network, no authentication
- Client send a command and wait for a response. E.g. http://ava/cmd=ATEP# (0=pause,1=un-pause)
- Host returns a simple text reply “OK”, “ERR”, or a short line of text
- Once reply sent, communication is done; until if/when client send another request
- Response timing is not critical (as in seconds, not milliseconds)

# DEVICE (HOST) – PSEUDO-CODE httpd_init(8081); while (1) { # Manage a request if ($client.request) { # Parse and validate, if invalid client.send('ERR'); # If 'set something': set variables; client.send('OK'); # Elsif a ‘request something': return client(short_string); # clear/cleanup//connection done } # Main program – do things … # Be nice my_sleep(250); }
Any suggestions? Thanks in advance.

In reply to Adding simple HTTP controls to existing code by brachism

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.