Shop OBEX P1 Docs P2 Docs Learn Events
HTTP and ENC28J60 Ethernet NIC / MAC Driver — Parallax Forums

HTTP and ENC28J60 Ethernet NIC / MAC Driver

mctriviamctrivia Posts: 3,772
edited 2009-01-30 07:18 in Propeller 1
I have downloaded the IRC client athttp://forums.parallax.com/showthread.php?p=716355 but am over my head. I have the SpinStudio Nic addapter which uses the ENC28J60 Ethernet NIC / MAC Driver but I am not sure how to get it to download from my server. I am trying to download a small page from a get address. It is my own server so I can set how big the page responses will be.

Can anyone help me?

Comments

  • Harrison.Harrison. Posts: 484
    edited 2009-01-30 07:18
    Here's a quick snippet from one of my projects that performs HTTP GETs to a remote server:
    PRI doStuff | ret
    
      repeat
        ret := \checkServices    ' it's important to 'catch' exceptions from the underlying tcp stack with a \
        ... delays and other code go here ...
    
    PRI checkServices | ch
      sock.connect(constant((72 << 24) + (14 << 16) + (176 << 8) + 143), 80)
      sock.resetBuffers
      if sock.waitConnectTimeout(2000)
        ' connected
        sock.str(string("GET /sometestpage.php HTTP/1.0",13,10))
        sock.str(string("Host: propserve.fwdweb.com",13,10))
        sock.str(string("User-Agent: PropTCP",13,10))
        sock.str(string("Connection: close",13,10,13,10)) 
        
        repeat until sock.rx == "#"                  ' wait for start char
        
        ch := sock.rxtime(250)                       ' get response code
        
        if ch <> "0"
          ' some service failed
          sock.close
          return 1
        
        sock.close
        return 0
      else 
        sock.close
        return -1
    
    



    The code simply connects to a webserver and requests a page. The page contains a pound sign (#) followed by a single digit to represent the state of the service it is checking. You should be able to easily expand this to do whatever you wish since the API is almost identical to FullDuplexSerial's API.

    You'll also want to get the latest tcp/ip stack here: www.parallax.com/Portals/0/Downloads/docs/cusapps/PropellerContest08/PropIRC-Source.zip. I haven't gotten around to uploading the latest version which has various fixes yet. I hope to get around to it this weekend.
Sign In or Register to comment.