Shop OBEX P1 Docs P2 Docs Learn Events
Spinneret Web-Server .spin Code Hierarchy and Integration for Project — Parallax Forums

Spinneret Web-Server .spin Code Hierarchy and Integration for Project

lopezblopezb Posts: 3
edited 2013-02-19 19:10 in Accessories
Hi,
I am new to the Parallax Spinneret Web-Server Propeller Micro on board. I am working on a project that is supposed to have multiple modules. Here is some background on my project.

The first private method is to count the number of positive pulse edges on an
input pin to the Spinneret's Propeller Pin 24 (Pin 10 on the 12 pin header J1)
and stores the number of pulses in an accumulation register. If the user requests
to view energy usage data or the end of a billing cycle occurs based on a user
defined date, the decimal number of pulses is passed into a variable to be
manipulated by the next private method.


The second private method is invoked from the first private method to perform
a calculation on the decimal number of pulses and convert it into +kWh. The
variable storing the decimal number of pulses is reset to 0 and is ready to be
written to again. If the method was invoked due to the time being the end of
the billing cycle, the pulse accumulator register is reset to zero and is ready
for accumulation of the next billing cycle. The +kWh value is passed into a
variable to be maipulated by the next private method.


The third private method is invoked from the second private method to perform
calculations on the +kWh value, in order to calculate the projected bill based
on +kWh value and a flat rate billing scheme. The projected bill and total
amount of +kWh should be returned back to the user via the web interface.


The fourth private method is invoked from the third private method to save the
energy usage information to a text file on the Micro SD card with three columns,
one for end of the billing cycle date, another for the decimal +kWh value calculated,
and the last column should contain the projected bill for the corresponding billing cycle in
USD. The text file should be given a fixed generic name such as "Energy_Table".
At the end of each billing cycle, a new row of data should be appended to the
end of the table. Any entry older than two years old should be deleted from the
top of the text file. (Not yet created)


The fifth and final method should populate an HTML table to display the data from
the text file in a table for the user to easily view via the web interface.
(Not yet created)

I am trying to implement these modules as low level as possible, and it does not have to look elaborate or aesthetically pleasing. All I am looking for is all of this basic functionality. I am currently running an HTTP site using code provided by Mike G. I am very confused on where I should include these methods, where they would operate and return data properly to a web interface. I am looking for the easiest way to integrate these modules into the Webserver_W5100_RTC.spin Top Level code file. The file does not appear to have a main method and I do not know how I would integrate my code into this file and ensure that it is being executed. I have attached both my code, and the Webserver_W5100_RTC.spin code that Mike G gave me. I have not found a very good debugging IDDE for .spin code that tracks variables and shows propeller register states. Does anyone know of one out there or have any suggestions on a decent IDDE other than Propeller Tool?

Your help is very appreciated!

Comments

  • Mike GMike G Posts: 2,702
    edited 2013-02-19 05:43
    The first module is to count the number of positive pulse edges on an input pin to the Spinneret's Propeller Pin 24 (Pin 10 on the 12 pin header J1) and stores the number of pulses in an accumulation register.
    The Propeller has 8 COGs to run processes. The Web server is running in the main COG process. Run the positive edge process in a new COG. Depending on the quality of the signal, you could use counter to accumulate a leading edge count. See an001 for information on counters.
    A second module is to perform a calculation on the number of pulses whenever a user tells the propeller to do so from a web interface, and the value should be returned back to the web interface. In the same module, the calculation should also occur automatically at 11:59PM on a user specified date, and when this event occurs, the resulting value should be written to a text file and stored on the Micro SD card.
    Again, you just have to write the logic. All the code for requirement two can be found in the code attached to post #1. In the new process, create a method that checks the current time. If the time is 23 hours and 59 minutes open a text file and write the calculated value. Otherwise, if the method was use invoked do the same.
    A third module should give the user the ability to view the text file directory of the Micro SD card and view the contents of a selected file from the micro SD card from the web interface.
    Simply enter the Spinneret's IP and file name in your browser. The Web Server know how to render static files from the SD card.
    I am trying to implement these modules as low level as possible, and it does not have to look elaborate or aesthetically pleasing. All I am looking for is all of this basic functionality. I am currently running an HTTP site using code provided by Mike G. I am very confused on where I should include these modules. I am looking for the easiest way to integrate these modules into the Webserver_W5100_RTC.spin Top Level code file. The file does not appear to have a main sub-routine and I do not know how I would integrate my code into this file and ensure that it is being executed. I have not found a very good debugging IDDE for .spin code that tracks variables and shows propeller register states. Does anyone know of one out there or have any suggestions on a decent IDDE other than Propeller Tool?
    The logic could be contained in an object file (library) or directly in the Web Server. To get the Web Server to execute logic, add a filter to the RenderDynamic(id) method. The filter looks for an HTTP request which allows the programmer to execute custom code before sending a response to the client. The HTTP request could contain parameters in the URL or body of the request. The HttpHeader library tokenized the HTTP request so it is easy to find the parameters.

    The snippet below updates and reports pin IO parameters to the caller.
    PRI RenderDynamic(id)
    
      'Process pinstate
      if(strcomp(req.GetFileName, string("pinstate.xml")))
        BuildPinStateXml( req.Get(string("led")), req.Get(string("value")) )
        BuildAndSendHeader(id, -1)
        sock[id].Send(@xmlPinState, strsize(@xmlPinState))
        return true
    

    The web Server does not have a debugger. Besides, IMO, debugger make you brain dead. However, you can send debug information like variable values to the Parallax Serial Terminal.

    There's a lot going on in the web server. It is helpful to understand the HTTP protocol.

    If I were you, I'd get requirement 1 working in a test bed. Then integrate requirement 1into the web server which would complete requirement 2. The time.htm example has a lot of what you are trying to do.
  • lopezblopezb Posts: 3
    edited 2013-02-19 09:31
    Mike,
    I updated my first post on here to reflect the software development progress that I made from ~2AM until ~8AM. Unfortunately, you already replied to my original post by 6 minutes!
    I have included an updated list of my methods (there are 5 now) and my code Energy_Info_Bill.spin. I need to get this code file integrated with the top level Webserver_W5100_RTC.spin. How would I modify PRI RenderDynamic(id) to do so?
    What variable is the RTC time value stored in so that I can compare it to say... 02/22/2013 23:59:00 for the sake of arbitration. In my code, I am calling it xtime from the Webserver_W5100_RTC.spin, but I'm not sure if that is correct.
    I am also not able to view a listing of files on the MicroSD card still. I made a folder named energy_data on the root of the SD card. I am entering 192.168.1.139:5000/energy_data and I would expect to see a list of files that is in that folder, which I'm not seeing.
    If you could review my code and reread my first post, since it had hanged completely, this should provide a more clear picture of what I am doing.


    Thank you so much Mike G your awesome!
  • Mike GMike G Posts: 2,702
    edited 2013-02-19 19:10
    I have included an updated list of my methods (there are 5 now) and my code Energy_Info_Bill.spin. I need to get this code file integrated with the top level Webserver_W5100_RTC.spin. How would I modify PRI RenderDynamic(id) to do so?
    Please take a look at the rtc.htm and time example. The time demo has contains all the components for requesting data and displaying the results in a using a web browser. When posting source code and asking for help integrating, at least make sure your source builds. There are errors in Energy_Info_Bill.spin.
    What variable is the RTC time value stored in so that I can compare it to say... 02/22/2013 23:59:00 for the sake of arbitration. In my code, I am calling it xtime from the Webserver_W5100_RTC.spin, but I'm not sure if that is correct.
    The time is cached in the RTC library. Each of the date parts are exposed through getter methods. Open the RTC library and read the code comments.
    I am also not able to view a listing of files on the MicroSD card still. I made a folder named energy_data on the root of the SD card. I am entering 192.168.1.139:5000/energy_data and I would expect to see a list of files that is in that folder, which I'm not seeing.
    Directory browsing is a web server feature not a standard. If you require directory browsing you'll have to write the feature yourself. It's not terribly difficult. Simply buffer and send the file names as an HTML or XML document to the client when an index.htm file does not exist in the current directory.
    If you could review my code and reread my first post, since it had hanged completely, this should provide a more clear picture of what I am doing.
    As far as I can tell, you have not modified WebServer_5100.spin and your source does not compile. I'm not sure how to help you.

    .
Sign In or Register to comment.