![]() |
Forum Index : Microcontroller and PC projects : Newie got a few questions
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Be wary that if you don't call the GMT sub when time = 02:00:00 then you will miss 'adjusting' the Time. I had a similar issue on a Home Automation sub I was calling for switching lights on and off. I resolved it with flags AND checking hours and minutes only. This gave me a whole minute for the 'other stuff' to finish and call the 'time check' sub - never missed a thing this way. ![]() WW |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
For once I actually thought of that :) I'm calling the sub every second when the hands of the clock are changing I really can't figure out how to stop it running every time the clock reads 2am though, because IF at 2am I set the clock back to 1AM then it will just keep looping |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
You need to make sure that you only do the time change once by setting a flag the first time it's called. Somewhere else in you program, you need to reset the flag, probably when Daylight saving ends. I haven't tested the code but it should trgger once after 02:00 and put the time back exactly one hour. Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
"Should" this work if I did this? [code] Program code .... GMTStart GMTEND program code END SUB GMTSTART IF GMTdone = 0 THEN IF DATE$ = "30-10-2016" AND TIME$ > "02:00:00" THEN newTime$ = "01"+MID$(TIME$,3) TIME$ = newTime$ GMTdone = 1 ' set a flag to indicate "been there done that" ENDIF ENDIF END SUB SUB GMTEND IF GMTdone = 1 THEN IF DATE$ = "30-10-2016" AND TIME$ > "02:01:00" THEN GMTdone = 0 ' Reset flag ready for next GMT changeover" ENDIF ENDIF END SUB [/code] |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
It would be better to not change the TIME$ as that will change you internal clock. If the program is stopped and run again the flag will be cleared and another hour will be subtracted. To be save, never touch the internal clock, with the exception of updating it with data from GPS or RTC. The internal clock would best run on UTC time. You can then add hours depending on your timezone and daylight saving. [code] DisplayDateTime$ = GetLocalTime(TimeZone$, DATE$, TIME$) [/code] The function would then accept a UTC timstamp and your TimeZone. You call this function each time (every second is not a problem) you need to display a local time. The function is not implemented yet as it is not that easy. :) I am having a bit of a time shortage so i can not do it now. I just realized that the 'Super Clock' should contain the code to do just that. Maybe have a look at that code first and see if you can reuse something. Microblocks. Build with logic. |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
That won't quite work (meaning your last past Lewis) as come 02:01 the GMTEND sub will reset the flag back to zero (no problem here). But then at your next call to GMTSTART you will set the flag again as you are checking TIME>02:00. Change the test in START to TIME$=... rather than 'greater than'. Another thing is that you are doing lots of checking every time you call your sub (i.e. every second). I would change slightly to: . . program code GMT programcode . . . . SUB GMT IF DATE$="30-10-2016" THEN 'only check things if on this date IF GMTdone=0 THEN 'see if time already adjusted IF LEFT$(TIME$,5)="02:00" THEN 'if time not already adjusted then check for the 2:00 AM minute TIME$="01:00" + RIGHT$(TIME$,2) 'put back an hour, and add on the seconds GMTdone=1 'set flag to say time adjusted ELSE 'if time already adjusted then look for the 02:01 minute to reset flag (ok to keep resetting) IF LEFT$(TIME$,5) = "02:01" THEN GMTdone=0 'reset flag if in 02:01 minute END IF END SUB |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
I agree with Jean, as this code will only work for this year. Look at Geoff's original clock code and he has a great way of changing the daylight saving. He 'updated' this when I enquired about UK daylight saving. The SuperClock has a great routine but you may find it a little confusing at first. As Jean suggests, take a look and see how you get on . . . . WW |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks everyone Yes I knew it would only work for this year, I was just seeing if I could get it to work before I went any further with following years. I knew about the DST code, I have it in my GPS code Thanks everyone |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
RTC SETTIME Does the month setting have to be 2 digits? for example would today be RTC SETTIME 2016,9,22,15,50,55 or RTC SETTIME 2016,09,22,15,50,55 |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
No. The values passed are integers, so leading zeros mean nothing. Try it at the command prompt, all the below work. > rtc settime 2016,9,23,06,03,55 > rtc settime 2016,09,23,06,03,55 > rtc settime 2016,00009,23,06,03,55 > rtc settime 2016,09,23,06,03,055 > rtc settime 2016,0000009,23,00006,000003,0000055 > |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks Phil |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
A hard one now (I think) How could I get the Micromite to do certain things between certain times? For example If Time$ = OR > 06:05 AND = OR < 22:00 THEN DO something ELSE DO something else |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
[code] IF Time$ >= "06:05:00" AND Time$ <= "22:00:00" THEN 'Do something ELSE 'Do something else ENDIF [/code] Microblocks. Build with logic. |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks ![]() |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I'm now going to seem such an idiot I'm getting confused with strings and integers again (I think) What I have is an ESP outputting a string and I'm receiving the string on the Micromite The string being received is this [code]TIME,Fri Sep 23 21:11:47 2016[/code] The code I am using is this [quote]IF FieldArray$(0) = "TIME" THEN time1 'If the 1st array is "Time then GOSUB time1 SUB time1 day0$ = Val(left$(FieldArray$(1), 3)) END SUB[/quote] The result I am getting is this [code][216] day0$ = Val(Left$(FieldArray$(1), 3)) Error: Expected a string[/code] Anyone able to help and tell me what I should have put? I also want to use the time received to update the RTC in the Micromite using the same idea to extract the time from the received data |
||||
jman![]() Guru ![]() Joined: 12/06/2011 Location: New ZealandPosts: 711 |
[216] day0$ = Val(Left$(FieldArray$(1), 3)) Error: Expected a string Try the line below [216] day0$ = Left$(FieldArray$(1), 3)
Regards Jman |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks |
||||
Phil23 Guru ![]() Joined: 27/03/2016 Location: AustraliaPosts: 1667 |
I didn't really expect the operators to work with strings. It seemed to work at first, but a bit of testing makes me think otherwise. Might be ok with given values; not sure. Just played a little at the prompt:- Might not give reliable results. [Code]print Time$ >= "07:00:00" 1 > print Time$ >= "08:00:00" 0 > print Time$ >= "7:00:00" 0 > print Time$ >= "8:00:00" 0 > print time$ 07:16:59 > print Time$ >= "7:30:00" 0 > print Time$ >= "7:15:00" 0 > print Time$ >= "7:18:00" 0 > print time$ 07:20:27 > print Time$ >= "7:22:00" 0 > [/code] Seems as though it would only do the logical compare on the first numeric in the string. [Code]> print val("7:00:00") 7 > print val("07:00:00") 7 > print val("07:11:00") 7 >[/code] Phil. |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6269 |
It is comparing strings as strings. The code works as long as you remember that the time$ returns leading zeros. What the VAL() is has no meaning in this case. Strings also are case sensitive so unless you are prepared, you will get some strange results. > print "B" > "a"
0 > print "B" > "A" 1 > Jim VK7JH MMedit |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Back to GPS again The GPRMC string has the following data $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A Where: RMC Recommended Minimum sentence C 123519 Fix taken at 12:35:19 UTC A Status A=active or V=Void. 4807.038,N Latitude 48 deg 07.038' N 01131.000,E Longitude 11 deg 31.000' E 022.4 Speed over the ground in knots 084.4 Track angle in degrees True 230394 Date - 23rd of March 1994 003.1,W Magnetic Variation *6A The checksum data, always begins with * IF I have it correct arg$(8) is the date What I want to do is something like this arg$(8) = (something like L$ I need to tell the micromite to store arg(8) as something like L$ so I can then do something with it later At the moment the GPS code is [code] If secs < 4 Then 'IF Seconds is less than 4 then restart the GPS KeepSearching: Do Pin(23) = 0 'TURN GPS Power ON GetGPSRecord ' get a GPS record Loop Until arg$(0) = "GPRMC" ' we only want the RMC record If arg$(2) <> "A" Then ' "A" means valid record Pin(16) = 0 ' Turn HC-12 ON Print "Searching For GPS signal" Print #2, "START" , "Searching" GoTo KeepSearching ' go back and keep looking EndIf[/code] I need to insert a line to pull out arg$(8) and put it "somewhere" to deal with it later any suggestions? |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |