Shop OBEX P1 Docs P2 Docs Learn Events
Soft Serve: A simple-to-use HTML server — Parallax Forums

Soft Serve: A simple-to-use HTML server

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2011-02-11 22:07 in Accessories
This is still a work-in-progress, but I thought a brief introduction might be of interest to some. I'm not going to post the object yet, since there's still some cleanup to do, but here's a brief feature set:
  • Provides a (mostly) transparent wrapper for Roy Eltham's DHCP object (as modified by Beau Schwab).
  • Uses abbreviated HTML constructs for small page footprints.
  • Automatically inserts linefeeds, indenting, and end tags for proper nesting and nice visual source presentation.
  • Permits the embedding of string variables anywhere in the output. As the output is being generated, data are fetched from the strings, fill-in-the-blanks style.
  • Has methods for request-string and HTML-source echoing for ease of debugging.
  • Automatically parses GET requests into action string and key/value parameter pairs.
Here's a sample top-level program:
[font=Parallax][size=2]
CON

  _clkmode      = xtal1 + pll16x
  _xinfreq      = 5_000_000

  #$00, EOF,LEFT,CENTER,CHECKED,TEXT,SUBMIT,RESET,RADIO,BUTTON,HIDDEN,EOL,EOP,HR,SP,LI,SIZE, {
      } FIL,CHKBOX,POST,ALIGN,NAME,VALUE,CLASS,ID,STYLE_,TYPE,WIDTH,HEIGHT,COLOR,FONT,FSIZE,BKGND

  #$80, B_,I_,U_,S_,SUP_,SUB_,SPAN_,TABLE_,TR_,TD_,DIV_,FORM_,INPUT_,IMG_,URL_,LIST_, {
      } CODE_,PRE_,OLIST_,INDENT_,RESERVED2,VAR_,ATTR_,HTML_,MARK_,VAL_,_STYLE,_ATTR,_HTML,_MARK,_TAG,_ALL

  QU            = $22

  VISITOR       = 1
  TITLE_COLOR   = 2  
  
OBJ

  server        : "soft_serve"
  num           : "simple_numbers_plus"

VAR

  word  request, variables[32], visitor_no

PUB main

  server.start(string("192.168.0.50:3456"), string("192.168.0.4"), 0, string("00 08 DC 16 F0 13"))
  server.setvars(@variables)
   
  variables[TITLE_COLOR] := string("blue")
 
  repeat
    if (strcomp(request := server.request, string("/change")))
      variables[TITLE_COLOR] := server.param(string("color"))
    else
      variables[TITLE_COLOR] := string("blue")
    variables[VISITOR] := num.dec(++visitor_no)
    server.html_page(string("Color Change Test"), 0, string("#fffff0"))
    server.html_content(@change)
    server.end_html_page
       
DAT

change  byte  IMG_,"http://forums.parallax.com/image.php?u=45432",_ATTR
        byte  HR,DIV_,ALIGN,CENTER,COLOR,VAR_,TITLE_COLOR,FSIZE,"20pt",FONT,"sans-serif",_ATTR,B_
        byte  "This title is colored ",VAR_,TITLE_COLOR,".",_ALL,HR
        byte  DIV_,CENTER,WIDTH,"400",BKGND,"#e0e0d0;margin:auto auto;padding:12pt;border:solid ",VAR_,TITLE_COLOR," 1px",_ATTR
        byte  FORM_,"/change",_ATTR,"Enter a new color here: "
        byte  INPUT_,TEXT,NAME,"color",VALUE,VAR_,TITLE_COLOR,SIZE,"10",_ATTR,"    "
        byte  INPUT_,SUBMIT,_ATTR,EOP
        byte  "You are visitor number ",VAR_,VISITOR,".",EOF 
[/size][/font]
You can give this program a try here (for awhile):
[url]phipi.homelinux.org:3456[/url]
I think I've got my firewall set right, but let me know if you can't reach it; and be sure to view the source to compare with the above DAT section.

More later...

-Phil

Comments

  • $WMc%$WMc% Posts: 1,884
    edited 2011-02-10 19:00
    Cool PhiPi:
    '
    I was vistor 101
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-11 08:16
    I got up this morning to find that the Spinneret had hung during the night, and I had to reset it. I haven't a clue what caused it to hang, since my program relies upon a peripheral chip and driver objects for it that I don't yet understand. Has anyone else experienced this with their Spinneret?

    Thanks,
    -Phil
  • John AbshierJohn Abshier Posts: 1,116
    edited 2011-02-11 08:31
    Sometimes it worked. Sometimes I get a Internet Explorer cannot display the webpage message. IE8 on Windows 7 64 bit

    John Abshier
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2011-02-11 09:29
    That's really cool. I am hoping that I can eventually use a Spinneret for a few projects but do not want to have to spend time on the basics of "getting it to work" so to speak. I want to be able to modify something like what you have done here for a simple interface so that I can quickly implement these. My thought is to make a web-based real time monitoring setup for a couple machines we have on our production floor. I can already tap into the machines' status through a serial port so I just need to grab that data and shove it to the Spinneret.

    ps. I tried to stump it with fuchsia for the color, but it got it! :tongue:
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-11 09:42
    Thanks, Andrew! Actually, it's your browser that understands color names. My program just plugs the color typed into the box into the locations indicated in the script by the TITLE_COLOR variable, viz:
    change  byte  IMG_,"http://forums.parallax.com/image.php?u=45432",_ATTR
            byte  HR,DIV_,ALIGN,CENTER,COLOR,[color=fuchsia]VAR_,TITLE_COLOR[/color],FSIZE,"20pt",FONT,"sans-serif",_ATTR,B_
            byte  "This title is colored ",[color=fuchsia]VAR_,TITLE_COLOR[/color],".",_ALL,HR
            byte  DIV_,CENTER,WIDTH,"400",BKGND,"#e0e0d0;margin:auto auto;padding:12pt;border:solid ",[color=fuchsia]VAR_,TITLE_COLOR[/color]," 1px",_ATTR
            byte  FORM_,"/change",_ATTR,"Enter a new color here: "
            byte  INPUT_,TEXT,NAME,"color",VALUE,[color=fuchsia]VAR_,TITLE_COLOR[/color],SIZE,"10",_ATTR,"    "
            byte  INPUT_,SUBMIT,_ATTR,EOP
            byte  "You are visitor number ",VAR_,VISITOR,".",EOF
    
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <title>Color Change Test</title>
      </head>
      <body style="background-color: #fffff0">
        <img src="http://forums.parallax.com/image.php?u=45432"><hr/>
        <div align="center" style="color:[color=fuchsia]fuchsia[/color];font-size:20pt;font-family:sans-serif">
          <b>This title is colored [color=fuchsia]fuchsia[/color].</b>
        </div>
        <hr/>
        <div align="center" style="width:400;background-color:#e0e0d0;margin:auto auto;padding:12pt;border:solid [color=fuchsia]fuchsia[/color] 1px">
          <form method="get" action="change">
            Enter a new color here: 
            <input type="text" name="color" value="[color=fuchsia]fuchsia[/color]" size="10"> &nbsp;&nbsp;&nbsp;
            <input type="submit"><p/>
            You are visitor number 94.
          </form>
        </div>
      <body>
    <html>
    

    You can also enter colors in their RGB hex format, #RRGGBB, e.g. #FFFF00 for yellow.

    -Phil
  • LeonLeon Posts: 7,620
    edited 2011-02-11 10:32
    FWIW, it works with my Dell Streak tablet (Android).
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2011-02-11 22:02
    Phil,

    If your really using the DHCP methods in Roy's code, that's fine. I might have overstepped my boundry by taking his code and wrapping it the way I did when really I was only using it for basic. HTML ... Sorry Roy.

    Attached is a bare bones 'Simple HTML.Spin' wrapper that should have been what I originally posted. this should work in place of the 'DHCP_GBSbuild_01_27_2001.spin'
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-11 22:07
    Seriously? That's all that's required? Thanks, Beau! That will simplify my job even further. BTW, for anyone trying the link, it's down for the next 24...

    -Phil
Sign In or Register to comment.