Combining Mike G's webserver objects and Beau Schwabes' SNTP Demo
Rforbes
Posts: 281
Hi all!
Earlier today, I found myself getting pretty overwhelmed trying to learn about the spinneret and the various objects that folks have written for it.
It brought a question to mind, and I just wanted to get some feedback and ideas from you all if you don't mind.
Here we have
DEMO: Using SNTP to sync the Spinneret's on-board RTC
This demo uses objects by Beau Scwabe, Timothy D. Swieter, Roy ELtham and performs an extremely useful task.
And here we have
http://spinneret.servebeer.com:5000/index.htm
This is Mike G's webserver tutorial and objects which are also extremely useful.
Here's the thing....
I'm still fairly new to Spin, and haven't even attempted to start tackling Pasm yet. I can only imagine I'm not the only one. My skill level with all things "Propeller" is equivalent to that of an EIT on day one: I can follow along (with lots of questions) and understand some basics and a little beyond, but I don't have what it takes to sign off on the spaceship bluepring (yet!) Sure their are more folks in similar situations here.
So, my question is pretty straight forward (although the answer may not be.)
Is there an object already written that uses Mike G's webserver objects AND integrates the same functionality (or perhaps the same object) that Beau's does with the SNTP rtc synchronization? If so, where can I find it? I've not had any luck in the OBEX.
If not, would you mind giving some input/advice/ideas on how to accomplish this? Some of you folks are real inspirations, and it amazes me how quickly I see you answer questions, making it seem almost effortless.
It seems each of these collections of objects are the standard de-facto and I know I don't have the ability to strip them apart and rewire them to work with one another. For all I know, it might only take 10 minutes to do or could take a year to make it happen with a skilled team. So, that's why I'm asking.... I don't want to start spending my effort in futility on this particular idea.
Don't get me wrong here- I'm all for doing the work if it's feasible, and have really enjoyed this learning experience... but sort of like the OBEX, I believe the purpose of the forum (and each of our brains) has a similar function- to make things easier by not re-inventing the wheel. Or more importantly, not inventing a square one.
Any guidance or thoughts you can offer would be GREATLY appreciated!
Thanks in advance,
Robert
Earlier today, I found myself getting pretty overwhelmed trying to learn about the spinneret and the various objects that folks have written for it.
It brought a question to mind, and I just wanted to get some feedback and ideas from you all if you don't mind.
Here we have
DEMO: Using SNTP to sync the Spinneret's on-board RTC
This demo uses objects by Beau Scwabe, Timothy D. Swieter, Roy ELtham and performs an extremely useful task.
And here we have
http://spinneret.servebeer.com:5000/index.htm
This is Mike G's webserver tutorial and objects which are also extremely useful.
Here's the thing....
I'm still fairly new to Spin, and haven't even attempted to start tackling Pasm yet. I can only imagine I'm not the only one. My skill level with all things "Propeller" is equivalent to that of an EIT on day one: I can follow along (with lots of questions) and understand some basics and a little beyond, but I don't have what it takes to sign off on the spaceship bluepring (yet!) Sure their are more folks in similar situations here.
So, my question is pretty straight forward (although the answer may not be.)
Is there an object already written that uses Mike G's webserver objects AND integrates the same functionality (or perhaps the same object) that Beau's does with the SNTP rtc synchronization? If so, where can I find it? I've not had any luck in the OBEX.
If not, would you mind giving some input/advice/ideas on how to accomplish this? Some of you folks are real inspirations, and it amazes me how quickly I see you answer questions, making it seem almost effortless.
It seems each of these collections of objects are the standard de-facto and I know I don't have the ability to strip them apart and rewire them to work with one another. For all I know, it might only take 10 minutes to do or could take a year to make it happen with a skilled team. So, that's why I'm asking.... I don't want to start spending my effort in futility on this particular idea.
Don't get me wrong here- I'm all for doing the work if it's feasible, and have really enjoyed this learning experience... but sort of like the OBEX, I believe the purpose of the forum (and each of our brains) has a similar function- to make things easier by not re-inventing the wheel. Or more importantly, not inventing a square one.
Any guidance or thoughts you can offer would be GREATLY appreciated!
Thanks in advance,
Robert
Comments
if you take a look at the changelog (httpserver file) you can see this;
Just download the files at the google code pages.
Uhhh... ok. So there we have it- I guess I need to figure out the google thing. I must be looking at earlier revisions of these files. See what I mean? You guys have ALL the answers!! Haha! (Slinking off to take an anti-dummy pill)
First, add the CON block items Add these items to the VAR block
Add these two methods to the HttpServer
Make a call to GetSntp by updating the main method.
The SNTP object formats UPD requests and decodes time server's responses.
The GetSntp method initializes socket 3 with the remote time server's IP and port. SNTP.CreateUDPtimeheader formats the time request and socket.txUDP sends the UPD packet. socket.rxUDP places the response a in the buffer, tempBuff
SNTP.GetTransmitTimestamp(Zone,@tempBuff,@LongHIGH,@LongLOW) decodes the received UPD packet and places the results in the VAR block items.
Finally, DisplayHumanTime displays the time on the Parallax Serial Terminal.
and gives me the error "Expected a variable"
Now I know I can add in tempBuff up in my dat block (yes?), but I'm not exactly sure how to specify it. How many bytes or longs, etc.... or even if that's what I should do...
For the sake of time, here's the full code of my HTTPServer.spin at the moment...
Thanks!
Dave
But... now it's telling me the same thing for this line:
It's looking for @sntpIp. Is this just another buffer, or should I have an IP address set in there somehow?
Did I forget to copy something from the post here? I can't figure out why I should be getting so many errors here, and I'm worried I'm missing something major somewhere (other than a complete understanding of how to specify all these "@" things... :-)
Here's a list from the FEDs.
http://tf.nist.gov/tf-cgi/servers.cgi
Object exceeds runtime memory limit by 429 longs.
Really???
It appears to be the CON "tempBuff" that is giving the problem. When I remove all the references to the SNTP 1.2 (all the PUBS, and comment out the lines under PUB main, and comment out everything else remaining, I'm back to my original 78 longs. When I just uncomment the CON tempBuff and F8, then I get the memory exceeded message of 327 longs. Am I somehow specifying the tempBuff wrong? Too much? ???
So I set my CON block's TEMP_BUFFER to $300 instead of $600, and left out the PUBs for SNTP, and I had most of my original space left.
Restoring the PUBs for SNTP and F8 now shows I'm over memory by 39 longs.
How far down can I reduce TEMP_BUFFER and still have everything run OK? If I reduce it to $200 it leaves me 99 longs with everything restored... is $200 enough/
Here's the total code of HTTPServer.spin again. No changes have been made to SNTP 1.2.spin, so it's just as it was downloaded from the forum.
Like I said earlier - it's like pulling teeth. Every step yields more problems..... very frustrating.
You could always create a new HttpServer file with only the stuff to get SNTP working.
This is the last thing I'm working on tonight. If I don't get some sleep tonight I'm going to start hallucinating.
SNTP *seems* to be working. When I run PST and load HTTPServer.spin via an F10, the SNTP Server reports the following to the PST window:
And my timestamped email is the correct time, which seems to indicate that the time is being corrected for EST and DST.
So only one question remains on this (after I check to be sure that the time in my RTC is really from SNTP and not from the last time I set it manually...) That question is How can determine the minimum safe value for TEMP_BUFFER?
Thanks ... and have a great night!
Dave
Then I F10 to reload HTTPServer.spin. I see the initial messages, and finally, SNTP runs and reports the proper GMT -1 time. And then I send an email - and it shows the time on the originally set schedule, updated to the time intervening since the last email (in other words, it's getting the new time from the buffer not just reporting the same time from previously).
So now... I get to delve into where the SNTP 1.2.spin program actually engages rtc.writeTime.
And I'm trying to figure out why the manual web-page time setting function hangs when I have SNTP enabled - if I have these three lines active in the PUB Initialize block:
Then when I use the web-page time setter, it just hangs the whole server. Comment out those three lines, all works fine. One thing I did notice, however, is that when I set the time manually using the post.htm time setting function - when the Spinneret sends it's every-10-minute email, I see this line where it is printing the conversation log from the Email Sending block:
It looks like the data string from the web page's form output is being retained in the rxbuffer (?) - which leads me to believe that I am still doing something wrong when it comes to sending data into the Spinneret.
Thoughts?
Current full code (with the three SNTP initialization lines commented out):
Pulling teeth...
Dave
The SNTP demo does not set the RCT time nor does it claim to set the RTC time. The code demonstrates how to call an SNTP server and display the results. How SNTP is invoked and used is up to you.
Correct the rxbuffer can contain stale data. It's a buffer - that's how they work! The rxbuffer is accurate after processing the request and before processing the response.
I realize you are under some stress to get this project done. Give me a call if you need guidance
What I think here is that the huge, cavernous void between how little I know and how much many others on here who are kind enough to help DO know is that to a novice like myself, I look at the code in SNTP 1.2, and realize that a) I do not see anything in it that I recognize as the part that sets the RTC, and b) see enough that I do not understand but that suggests to me that perhaps the setting is being done through a mechanism that is currently unknown to me. I honestly inferred from the title of this post that the code as presented would integrate with HTTPServer, and set the clock.
I know from experience in teaching in the areas that I do have knowledge that I take a lot of understandings for granted that my student is utterly clueless about. I now find myself formally in that position of utter cluelessness, not even knowing that there is something I don't know that I don't know! :-) Worse yet is when I know so little that I can't even tell that what I DO know is actually what's needed in a given instance...
So firstly, thank you - I didn't know that the setting of the RTC was up to me, and now that I do, surprisingly, it looks like I may be able to do that just fine! So I have learned something.
And yes, I am stressing and losing sleep about how long it's taking me to learn this and when I promised it to be ready. So I will take you up on your call offer soon. But first, as usual, I will try to get as far with what I now know on my own before then. And again, thank you very much for your help. I'm sewing those Spin Big Boy pants up a little more every day! :-)
I have one question now looking back at SNTP 1.2.
In the CON Block of HTTPServer.spin, we have this set up (among other things, eliminated for clarity):
The next time that MM_DD_YYYY and DW_HH_MM_SS shows up is in PUB DisplayHumanTime:
What I'm trying to figure out is HOW the time data gets into the DW_HH_MM_SS and MM_DD_YYYY locations. I can't determine if it's getting put in there by an offset, or by writing the strings received from the server to a base location that automatically fills the data into those locations by virtue of the start point and the length of the data received.
Again - it IS working, I'm just confused on this one issue. I've read in the Propeller manual for BYTE and DAT, and I am still not sure if my thinking is correct on this or if I am - as usual - completely off the mark.
Thanks!
Dave
Including SNTP 1.2.spin here for convenience:
Ok... I wrote that particular "HumanTime" method. I wrote it because at the time, there was a minor bug in Beau's original version. I needed a quick fix, so that's what I came up with. That code is NOT very well written, but it does work. Beau has since fixed the bug in his version, and it's better code. I strongly recommend using his. You'd have to go to the google repository for the spinneret and fetch it if you'd rather use it. If you insist on using my "Humantime" method instead of Beau's version, that's fine. It's just a little sloppy.
Here's how it does what you're asking about:
In your HTTPServer object, you called GetTransmitTimestamp(Zone,DLS,@rxdata,@LongHIGH,@LongLOW) from one of your methods. Your method probably does not include Zone or DLS, but I'm almost positive it includes @rxdata,@LongHIGH,@LongLOW as its parameters.
The GetTransmitTimeStamp method in your sntp 1.2 object calls HumanTime(Offset, Long2) at the very end.
Since you use @LongLOW in your parameters for the GetTransmitTimeStamp method, the ADDRESS of LongLOW is used in that method. It's renamed to Long2. It then passes Long2, which is the ADDRESS of LongLOW to HumanTime.
When HumanTime is called, it uses Long2, which is the ADDRESS of LongLow to do its magic. It renames Long2, which is the ADDRESS of LongLow to TimeStamp. When it's finished, at the very end, you'll see the following:
This bit of code is saying "put the month/day/year values on the right side of the := into the long which is 1 ADDRESS ahead of the ADDRESS of TimeStamp. Put the hours/minutes/seconds value on the right side of the := into the long which is 2 ahead of the ADDRESS of TimeStamp.
So. If you look in the VAR section of HTTPServer, you'll see it has a note by those 4 'contiguous' variables.... because if you moved them into a different order, the long variable that is 1 or 2 addresses ahead of the LongLOW variable would be different. And hence, the methods would not work as expected.
I recommend you study up the @ symbol, and the DAT section. They are quite critical to most of the spinneret code. And... don't feel bad- I was at least as confused as you are when I started trying to tackle all this stuff. You'll get there! Just keep at it.
Robert
Regarding newer versions of the SNTP Object, the version I have is SNTP 1.2.spin - but the one in the google code repository is v1.1. There are significant differences in how leap years are handled - SNTP 1.1 has IsDST and IsDSTEU, whereas v1.2 does not. I'm planting both in the following two code windows - can you verify that in fact v1.1 is the one that should be used and that v1.2 that I have been using is in fact, older?
And lastly, just to add more confusion, I just found this one - a Version 2.01, with an update date of 2/2/2013: http://forums.parallax.com/showthread.php/145697-SNTP-Simple-Network-Time-Protocol-BUG-fix-Update - but it does NOT seem to contain *anything* about DST. I'll add that code in below as well, so that all three versions can be compared in one spot! :-)
Version 1.1 as downloaded from the Google Repository:
Version 1.2 as downloaded from the links toward the top of this thread:
Version 2.01 as downloaded from http://forums.parallax.com/showthread.php/145697-SNTP-Simple-Network-Time-Protocol-BUG-fix-Update
There is no way I'm going to go through all three objects and tell you which one to use. I didn't write them, I don't track the revisions and I don't use them. I don't want to sound rude about that but these objects are all "open source" and can be modified by anyone, at any time, for any reason. They're not guaranteed to work correctly, and I don't have the skill or time to give them a "stamp of approval" that has any real meaning.
Having said that, my recommendation would be to use version 2.01 because I "think" Beau has fixed his code bug in that version. I haven't used it, and I haven't looked through it, so it's just a recommendation based on my knowledge that both Mike G and Beau Schwabe are top-notch, and they are on the ball.
Concerning leap years and DST, I can refer you to this post. You're welcome to use/modify/laugh at the code, but it's only posted as a conceptual piece. You may or may not be able to use it. It gives a good concept for implementing DST.
http://forums.parallax.com/showthread.php/146075-Spinneret-Web-Server-with-SNTP-RTC-Sync-and-DHCP-IP-Renewal?p=1176615#post1176615
I'd like to offer one small bit of advice at this point:
You seem to be trying to use the spinneret as something other than a server. That's great, and it's very doable. But Mike G's object is written so that it functions as a general server, not a client. It appears that you're trying to tailor it to do very specific things, and you might be better off by taking a step back, figuring out which objects you do/don't need and starting fresh. I've seen that you have hacked up a lot of the pre-written objects, and sometimes this gets so overwhelming that it's almost impossible to work out bugs that were either already present, or introduced with your own changes.
Not sounding rude at all, I completely understand and am grateful for whatever guidance I can get. It's better to ask and possibly get useful info than not ask and miss it altogether.
While it seems that I am trying to get the Spinneret to do a million different things, it's probably just the effect of my asking many questions on things I am trying to learn about that are related to what I am actually trying to do. In actuality, the only functions that the Spinneret is being called upon to do are:
1. Serve up a single web page that allows the "administrators" of the system to see the time to which the RTC is set, and to provide a manual method of changing that time should it ever become necessary, as well as a method for changing the IP Address of the reference SNTP TIme Server. (ALL FUNCTION WORKING)
2. To run some version of SNTP to accomplish the above automated time setting functions once each time the system is powered up (FUNCTIONS WORKING)
3. To automatically send an email every 10 minutes (hence the requirement for the RTC) containing up to 128 datalines with each line showing a one-byte sensor number, a reading consisting of 3 bytes each (XXX . XX, assuming the "." is a byte), and the time/date stamp (again, requiring the RTC). (BASE FUNCTION WORKING - haven't gotten to acquiring the data yet)
4. To collect the data from an outside hardware/microcontroller system (a BS2px driven system that runs all the 74HC4514 and 74138 data selectors, CD4066 analog switches and other acquisition circuitry - working perfectly and currently just storing the data in an EEPROM via I2C), which consists of a one-byte sensor number, one-byte "0-100" number, and one-byte ".00 to .99" number. (NEXT)
That's it. And the only reason I'm sending an email with the data and not GETting it, is because we are sending the data to a third-party company who is large and dictates to us how we will present our data to them... and they want it emailed. They have some sort of in-house system that has preassigned data fields and automatically parses the incoming email into the appropriate spots in their system.
So while it sounds like I'm asking the server to do something other than serve... in actuality, aside from the part where I have it grab the sensor numbers and level data from the BS2px side, I'm really ONLY asking it to be a server.
Again, thanks for your help. When I took on this project, it never occurred to me just how MUCH different the Spinneret would be from programming the other stuff I program (Stamps, server-side and client-side scripting for web, etc) and so I figured two months would be more than ample time. I was wrong. That date is looming FAST. And the largest physical piece, the data acquisition side of things, with the most circuitry, went together in about two weeks. The Spinneret side, the smallest bit but most important, since it's the transport mechanism of the data - has taken me a Month SO FAR.
I would have used the PINK Server, but that can only send emails of 64 bytes total... :-) On the bright side, I sure am learning a LOT, and hopefully I can continue that on after this project and start becoming as much of a fan of the Propeller as many people on these forums are.
Dave
Dave
Before I started with the SNTP part of this, I had only 74 longs free - I now have 262. I also understand an enormous amount more than when I started.
I can't imagine where people like me would be without the kind of knowledge and assistance that's on this board. And patience... :-)
Thanks again.
My question is with the line from 'GetsntpTime' from the Http Server. The Sntp v1.1 is working fine with MIke's Http Server
On the Sntp v1.1 this is a valid but when i run the Sntp v2.01 is only looking for the Buffer address and not the IP of the Time server
Where is v2.01 getting the IP address from? I cant seem to get it working.
I mentioned I had the sntp v1.1 working , well its always an hour behind the correct time. I assuming this has something got to do with DSTEU as my offset always needs to be (offset +1) to return me the correct time.
If i adjust this to HumanTime(Offset+1,Long1) like in the if statement below it its fine but should this not be the case only if I'm not in GMT
Uncomment the the lines of code below and update the method signature for use in the old deprecated code base.
Am I using an old HttpServer? is there a more recent one? This is the repo link i have
https://code.google.com/p/spinneret-web-server/source/browse/#svn%2Ftrunk%2FMultiSocketServer_MikeG
Thanks for the help
Hardly any tutorials or application notes for the new WebServer is there?