Shop OBEX P1 Docs P2 Docs Learn Events
PropTCP Beta - Now fully MIT Licensed (w/ AJAX Enabled HTTP Server Example!) - Page 2 — Parallax Forums

PropTCP Beta - Now fully MIT Licensed (w/ AJAX Enabled HTTP Server Example!)

2»

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2010-01-23 05:38
    I recommend that you take a look at the Ybox2 at

    www.ladyada.net/make/ybox2/

    I've built two, and they are a great way of getting starterd with PropTCP!
    Anding said...
    Dear Harrison and other friends,

    This will be my first project with the Propeller and PropTCP is the reason I am taking the plunge (from the trusty ATMega168).

    Is there a link to a circuit diagram showing the Propeller chip (40pin DIP standalone) and the ENC28J60 together to the Network jack? I'd like to assemble all the parts I'll be needing together and make a start.

    Many thanks,

    Anding
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com E-mail: mikronauts _at_ gmail _dot_ com 5.0" VGA LCD in stock!
    Morpheus dual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory/IO kit $89.95, both kits $189.95 SerPlug $9.95
    Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
    Las - Large model assembler Largos - upcoming nano operating system
  • AndingAnding Posts: 5
    edited 2010-01-23 06:09
    Thanks Bill. The Ybox2 looks like a fine idea. I will order a kit and a programming cable from the same supplier.

    - Any other (inexpensive) parts / accessories handy for small Propeller projects while I am at it with Adafruit?

    - I guess PropTCP is not the default software on the PropTCP? Would it be better if I am to switch over to PropTCP once I've built the kit and have it working?
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2010-01-23 09:42
    @ Anding

    A year ago I was cursing all my efforts on a ATMEGA168, 32, 644 using "Bens" Bascom code and spotted the YBOX2. My homemade attempt worked first time. I should get around to writing/modding some more useful "Widgets".

    I think the software is all down to Darko

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Style and grace : Nil point
  • SzabiSzabi Posts: 58
    edited 2010-01-28 22:32
    Harrison,



    you did a really nice job! Thanks for that!

    I just started to learn the propeller and spin language...I just simply love it!·Now that I start understanding things I decided to play with your driver :-) Since I'm just a beginner and·not really familiar with html code an java script I would need your help. Could you or anybody else post some sample spin codes, for example how I could read returned values from a webppage into variables? For example let's create kind of textbox on a page along with a button·and by clicking the button·the string·should be placed into a variable (that later I can display on the tv for ex.)

    Another sample I would need is for·example how I couls send and receive some strings through TCP on any port (or better on a different port but running·paralelly the webserver)·For example I would send a string on port 23 with telnet and that soould be displayed on the tv and echoed back to the telnet client ...or something like this.

    Simply any examples would be welcome I could play with :-)



    Many thanks in advance!
  • Tired2Tired2 Posts: 29
    edited 2010-02-11 00:21
    Szabi,

    I am basically attempting the same thing as you, and also pretty new to the propeller.

    From what have found, PropTCP by Harrison is utilized by the ybox2, so a 'quick and easy' way to get started is by purchasing a ybox2 kit and getting it going.

    I am pretty poor currently, so I am bread boarding out my own ybox2 using an ENC28J60 breakout board I found at sparkfun for $35. Granted, this is almost half the price of the $75 ybox2 kit, but I already had the propeller, propplug, etc needed to get it going, and I plan to reuse the board in my actual project down the road a bit.

    From what I can tell, a good starting place for being able to control things like LEDs through web addresses is to start with wwwexample.spin in the ybox2 svn repository.

    Once you get it flashing an LED, you can break down how it achieves it, and go from there. The example seems to have it all, though unfortunately I have to go now prior to setting up my network to test with [noparse]:([/noparse]
  • Tired2Tired2 Posts: 29
    edited 2010-02-24 21:59
    Harrison,

    I have put many hours into playing with "example_httpserver.spin" included in your proptcp 5.0-7beta, and I have had some mixed results.

    I want to use this for a project that I clearly do not have the skillset for yet, so I am basically hoping to get a few more bits of info from you that might help me pull everything together.

    I am having three main problems...

    First,

    I am unable to find a way to pull arguments from cgi calls. I see that the 'args' are parsed out of @reqstr, but I'm not sure how to get those into a string I can process for myself.

    I am hoping to build an internet enabled hot tub controller, but the framework for it should be like most any other web-based control apps. I'd like to be able to host a simple page of links to something like http://<prop ip>/tempset.cgi?temp=100. I also would like to display current variables similar to what is done with the random number, which should be easy if I can get the ajax figured out.

    That brings me to my second problem. I am able to use your if/elseif structure to run my own function based on my own custom cgi scripts, I.E.: http://<prop ip>/ledblue.cgi

    ........
      elseif str.indexOf(@reqstr, string("ledblue.cgi")) <> -1        ' if GET contains "ledblue.cgi"
        Sound(1, 200, 25_000_000, 50_000)                              ' sound from piezo speaker
        GlobalVar := 100                                                           ' set a global variable to value 100
        sock[noparse][[/noparse]sockidx].str(string("<html><body><B>Sound Played</B><BR><BR></body></html>"))   ' output confirmation page
    ....... etc
    
    



    My problem is that the "Sound" Function works, and I can then use that to set global variables, but I I cannot for instance turn on an LED with: outa[noparse][[/noparse]ledpin]:=1 (where ledpin is a CON, or even a set pin number) Any other functions with pin I/O seem to fail also... Ideas on why? Does it have to do with it being PRI vs. PUB? I'm lost.

    I can also work around that problem by flagging global variables and having my main functions watch those instead, but that is not how I'd like it to work, and I fear that my workaround will cause a future problem.

    Okay, if you are still with me at this point, my third problem is with AJAX...

    Do you have a less "trimmed" down version of "ajax.js" you could post? Maybe with comments? I have tried everything I can think of to have an additional variable (temperature) updated alongside the random number, but it always propagates the tags with whichever value I feed it first in the HTML file. They both update dynamically, but they are the same value for some reason. I think it is the way ajax() handles inputs, but it is hard to tell for sure, being completely new to the concept.

    I think with just a slight extension of example_httpserver.spin, many people of my skillset could make some really cool network appliances with control options of computer, iphone, android phone, and anything in between.

    Thanks for all your hard work on proptcp, the example is just so good that I want to push the limits of my project to what I know proptcp can do for me, it is just hard for newbies to jump in.

    Harrison, let me know if you can help out, or anyone else who might know what I'm doing wrong.

    Thanks.

    Post Edited (Tired2) : 2/24/2010 10:08:51 PM GMT
  • Harrison.Harrison. Posts: 484
    edited 2010-02-25 06:57
    Your pin output problem is likely caused by incorrect I/O direction settings for the webserver cog. Each cog has its own I/O direction registers so you will have to make sure you set dira correctly for each cog.

    An easy way to 'fix' this problem would be to set dira at the same time you set the pin state to high or low. The issue with doing this is that you will have pin output conflicts between the separate webserver cogs. Once an output pin is set to high, no other cog can set it to low. Information on how the I/O pins are shared between cogs can be found in the Propeller Manual.

    You will have to manually process the GET parameters for now. The example_httpserver.spin object is extremely simple and was provided to show how to write a super simple webserver for the Propeller. The AJAX javascript provided with it is also super simple and only supports a single request at a time (it has an internal 'lock' to prevent multiple requests at the same time). Below is the source code for the AJAX stuff, which should be pretty easy to modify to support multiple requests (although that could overload the Propeller).

    // ref: http://andreaslagerkvist.com/archives/2009/06/12/super-simple-ajax/
    // orig src: http://aframework.googlecode.com/svn/trunk/__v3/aFramework/Modules/Base/superSimpleAjax.js
    // compress: http://dean.edwards.name/packer/
    
    var ajaxBusy = false;
    
    function ajax(url, updateID, repeatDelay) {
    
        if (ajaxBusy) {
            // busy with previous request, don't do anything!
            return;
        }
        
        ajaxBusy = true;
    
        // Create ajax request object
        var requestObject;
    
        try {
            requestObject = new XMLHttpRequest();
        }
        catch (e) {
            requestObject = new ActiveXObject('Microsoft.XMLHTTP');
        }
    
        // This runs when request is complete
        var onReadyStateChange = function () {
            if (requestObject.readyState == 4) {
                if (updateID) {
                    document.getElementById(updateID).innerHTML = requestObject.responseText;
                }
                ajaxBusy = false;
                if (repeatDelay > 0) {
                    setTimeout('ajax(\'' + url + '\',\'' + updateID + '\',' + repeatDelay + ')', repeatDelay);
                }
            }
        };
    
        requestObject.open('GET', url + '?' + (new Date()).getTime(), true);
        requestObject.onreadystatechange = onReadyStateChange;
        requestObject.send(null);
    }
    
    
  • Tired2Tired2 Posts: 29
    edited 2010-02-25 15:18
    Harrison,

    Thank you very much for the full ajax script. As for the pins, I knew there was something I was missing, I knew all cogs had access to I/O, but I did not realize they had different direction registers.

    I'll see what I can put together.

    Thinking about it... I doubt multiple sockets will have to modify the same I/O at the same time.. I mostly want extra sockets in case I leave a connection open on one device (computer), and want to access it from elsewhere with iphone. Luckily for this project, the time aspect is way slowed down compared to my last one... responses in 5 seconds should be about as fast as I need [noparse]:)[/noparse] That is a welcome change. I think I'll go for the global variable route at first. I'm excited.

    Post Edited (Tired2) : 2/25/2010 4:47:07 PM GMT
  • Tired2Tired2 Posts: 29
    edited 2010-02-26 16:39
    Okay,

    After a few hours of playing around, I am pretty happy with the results so far.

    I have the example_httpserver.spin set up with a /led.cgi page that allows for on/off control of the three colors of an RGB led.

    I also chopped up the DAT entries to make the HTML code that is reused often only take a single DAT entry. There is an iphone specific piece of code in there as well that allows for custom scale on iphone... I'm no web developer, but I'm planning to hack away at this until I get something I like.

    Here is a video:
    www.youtube.com/watch?v=XNUQYdgvyI0

    Attached is my code if anyone cares to take a look, as well as the object info screenshot. It should run on stock ybox2 hardware, as the example_http.spin does in proptcp.

    Of course, all of the work was pretty much done by Harrison, I just expanded the example to prove to myself I could make it control things from the web. Next on my list is to get argument parsing worked out so I can set values like on the ybox2 web example, i.e. /ledcolor.cgi?=FF0462.

    After that, its on to ajax to see if I can get it to send requests and display multiple variables without refreshing the page.

    Thanks Harrison!! My hot tub will be remote controlled in no time [noparse]:)[/noparse] (or about 3 months)
  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-03-20 16:10
    Harrison:
    Thank you. This will serve as the best documentation reference for TCP, IP, UDP I can find (as a refresher) anywhere on the net. I will be using it as a reference in my own Propeller assembly socket library.

    There is an interesting bug in the module util_strings in the procedure toLower, this procedure assumes that all characters in the string are letters (upper or lower case), If you OR another character with hex $20 you will quite often get unwanted results. As a quick fix just do a quick bounds check on each character. Sorry can not give an example as I do not use SPIN enough to know how to construct a conditional statement off the top of my head.
  • malmeidapmalmeidap Posts: 11
    edited 2011-11-20 13:03
    Hi Harrison:

    Last week I bought the smallest ENC28J60's package from Hong Kong (http://www.ebay.com/itm/ws/eBayISAPI.dll?ViewItem&item=260747627291) to install it on the propeller demo board and test ur http web server example, but it didnt function. Can u help me pls ? i need the pin connection diagram for this package and the changes on the driver (if they exists) to test ur Web demo. The pin diagram of the element is published on the URL. Its very important help me pls :smile:

    Diagrama ENC28J60.png
    776 x 485 - 524K
  • RaymanRayman Posts: 14,851
    edited 2011-11-20 14:04
    Make sure you pull the CS and Reset pins high with a 10k resistor or so.
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-11-20 15:54
    Nice cheap module. Did you notice the logo on the pcb - Zero Research.
  • malmeidapmalmeidap Posts: 11
    edited 2011-11-20 16:21
    Make sure you pull the CS and Reset pins high with a 10k resistor or so.

    I connected it like ur diagram on these url http://code.google.com/p/proptcp/downloads/list.

    * I dont know if the DIP´s 40 package r the same as the Q44 package.
    * I read the driver, I saw that u generate an internal 25 MHz with the propeller systems clock, but these chip has his own 25 MHz clock. It can be a problem or not ?
    * I found these on google http://ucontroller.com/documentation/PropNICDoc.html, r u agree with these information ?
    Nice cheap module. Did you notice the logo on the pcb

    No, I didnt see what do it have ?
  • RaymanRayman Posts: 14,851
    edited 2011-11-20 16:37
    I think it should just work... It's just a simple SPI connection...
    Make sure you don't have the SPI SO and SI reversed...

    BTW: I'm not Harrison, but I'm trying to help anyway...

    The external crystal is fine.

    I've made my own board for the DIP version of the ENC chip here:
    http://www.rayslogic.com/Propeller/Products/PropBox/PropBox.htm
    There's a schematic in case that helps.
    I used Harrison's code and it just worked...
  • malmeidapmalmeidap Posts: 11
    edited 2011-11-20 17:06
    BTW: I'm not Harrison, but I'm trying to help anyway...

    Ty Rayman, sorry i was confused. Ur schematic its very helpful. I will try to use the mini ENC28j60 with the DIP version, then I will try with the demo board I will publish the solution as soon as possible ;) !!!
  • Toby SeckshundToby Seckshund Posts: 2,027
    edited 2011-11-21 01:15
    Just a thought, the ENC28j60 chip is quite thirsty on current so it might be worth keeping an eye on the power rail stability.
  • RaymanRayman Posts: 14,851
    edited 2011-11-21 03:39
    Actually, I just looked up my code and I think I had to make changes in MAC and IP address parts of the first DAT block.
    Basically, give it an IP address that will work in your network.

    Also, I had to change this line to tell it which pins I'm using:
    ' Init the TCP/IP driver
    sock.start(0, 1, 2, 3, -1, 7, @mac_addr, @ip_addr)
  • yetiyeti Posts: 819
    edited 2011-11-21 06:34
    Rayman wrote: »
    sock.start(0, 1, 2, 3, -1, 7, @mac_addr, @ip_addr)
    A -1 instead of 7 as 6th parameter switches off generating 25MHz on P7.
    ...and pullups are not needed on /CS and /RESET cause the enc-chip has weak pullups inside (mentioned somewhere in the datasheet).
Sign In or Register to comment.