Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:09 08 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Newie got a few questions

     Page 13 of 25    
Author Message
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 327
Posted: 10:45am 07 Dec 2016
Copy link to clipboard 
Print this post

Your list of RMC is missing a couple of parameters.

0 - Message ID ($GPRMC)
1 - UTC Time
2 - Status (A or V)
3 - Latitude
4 - N/S Indicator
5 - Longitude
6 - E/W Indicator
7 - Speed Over Ground in knots
8 - Course Over Ground
9 - Date
10 - Magnetic Variation
11 - Mode (A=Autonomous, D=DGPS, E=DR)
12 - Checksum

So, to get the date you will need arg$(9), and since you only want it when the data is valid, I would add the line directly after the valid record check.

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
L$ = arg$(9) ' copy the date to L$
Pin(16) = 0 ' Turn HC-12 ON
Print "Searching For GPS signal"
Print #2, "START" , "Searching"
GoTo KeepSearching ' go back and keep looking
EndIf


--CurtisEdited by Justplayin 2016-12-08
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:57am 07 Dec 2016
Copy link to clipboard 
Print this post

Thanks Curtis
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:23am 08 Dec 2016
Copy link to clipboard 
Print this post

I have a "weird" problem with a routine

Line2$ IS the current time in Hours Mins and Secs

If I PRINT LINE2$ I get 10:16:00 ***Which is correct***

I want to extract the hour, mins and sec from Line1$ so I used this

[code]
H1 = Val(Left$(LINE2$(1), 2)) ' extract the hour
M2 = Val(Mid$(LINE2$(1), 3, 2)) ' extract the min
S2 = Val(Mid$(LINE2$(1), 5, 2)) ' extract the sec
[/code]

However when I

Print H1 , "," , M2 , "," , S2 I get ***10,0,6*** Which IS INCORRECT

Anyone see why it's going wrong?
Edited by lew247 2016-12-09
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10222
Posted: 12:39am 08 Dec 2016
Copy link to clipboard 
Print this post

H1 = Val(Left$(LINE2$(1), 2)) ' extract the hour
M2 = Val(Mid$(LINE2$(1), 4, 2)) ' extract the min
S2 = Val(Mid$(LINE2$(1), 7, 2)) ' extract the sec
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 12:53am 08 Dec 2016
Copy link to clipboard 
Print this post

Ah I forgot about the :
Thanks
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 11:59pm 08 Dec 2016
Copy link to clipboard 
Print this post

Any ideas why this isn't working?
[code] If Mid$(#1,11,4) = "Time" Then
T5 (T5 is a sub)
[219] If Mid$(#1,11,4) = "Time" Then
Error: Invalid syntax
>
[/code]

#1 is COM1 - I'm looking for "TIME" and then go to sub T5
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 12:13am 09 Dec 2016
Copy link to clipboard 
Print this post

Hi Lewis,

The first parameter within the brackets needs to be a string.

I guess you want to read from COM1 and look for the string 'Time'.

What you need to do (if this is the case) is first read COM1 into a string$ and then use the loaded string in your MID$ command.

Phil
PS: sorry for the silence recently - been extremely busy I will email you later today . . .
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:33am 09 Dec 2016
Copy link to clipboard 
Print this post

Thanks Phil

Another conundrum

D$ = FieldArray$(1)

Is there any way to have E$ = FieldArray$(1) +(2) +(3) or is there any way to have a E$ = the value of several field arrays?

**Fieldarray** is the comma seperated value of a sentence like "44,1,23,98" and similarEdited by lew247 2016-12-10
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2932
Posted: 02:44am 09 Dec 2016
Copy link to clipboard 
Print this post

In the above example, I assume FieldArray (lets call it FA for short!) is as follows:
FA$(1)="44"
FA$(2)="1"
FA$(3)="23"
FA$(4)="98"

And that you want E$ to equal "68" (i.e. 44+1+23).

Is this correct?

If so then you can use VAL and str$ as follows:

E$=str$( val( FA$(1) ) + val( FA$(2) ) + val( FA$(3) ) )

All we are doing is converting the strings into values, then adding the values, and finally converting the resultant value back into a string.

Hope this helps
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 02:50am 09 Dec 2016
Copy link to clipboard 
Print this post

Almost but not quite
I don't want to add them up I want them to be a string with the comma's in as well

What I am tryin gt do is this

[code]Print #2,"TIME" , "," , Y1 , "," , M1 , "," , D1 , "," , H1 , "," , M2 , "," , S2 ' Send correct date/time to Indoor unit to set RTC[/code]

This is what the com port sends

What I want to send to the RTC is this[code]RTC SETTIME E$[/code]

Where E$ = Y1 , "," , M1 , "," , D1 , "," , H1 , "," , M2 , "," , S2

extracted from the above string that starts with "TIME, "," ,



Thats' the string the indoor unit gets

D$ = FieldArray$(1) which is "START"

What I want is to set the RTC with Fieldarrays 3 - 11 which should be Year,Month,Day,Hour,Min,Sec



Edited by lew247 2016-12-10
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1000
Posted: 12:37pm 09 Dec 2016
Copy link to clipboard 
Print this post

Hi Lewis,
I don't think getting E$ in the format will help. The RTC SETTIME command will not be happy if you pass it a string, no matter what is in it. The syntax below must be satisfied first or it wont look at it further.

RTC SETTIME year, month,day, hour, minute, second

The first thing it will do is check you have passed it six parameters by breaking it up at the commas, then it will check you have actually given it numbers.
The parameters can be expressions but they must evaluate to numbers.

Something like

RTC SETTIME val(FA$(1)) , val(FA$(2)) , val(FA$(3)),val(FA$(4)) , val(FA$(5)) , val(FA$(6))

should work.

Regards
Gerry

Latest F4 Latest H7 FotS
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 01:03pm 09 Dec 2016
Copy link to clipboard 
Print this post

I tried this code
[code]IF LOC(#1) > 0 THEN SERIAL1 'If data in COM1 then GOSUB Serial1
END IF
IF LOC(#2) > 0 THEN SERIAL2 'If data in Com1 then GOSUB Serial1
END IF

SUB SERIAL1 'Com1 data
B$ = Input$(254, #1) 'Suck everything in buffer out
N = GetFieldArray(B$)
D$ = FieldArray$(1) 'Start or Time
E$ = FieldArray$(2) ', symbol
F$ = FieldArray$(3) 'Year
G$ = FieldArray$(5) 'Month
H$ = FieldArray$(7) 'Day
z$ = FieldArray$(9) 'Hour
J$ = FieldArray$(11) 'Min
K$ = FieldArray$(13) 'Sec
If Mid$(D$,11,4) = "Time" Then
RTC SETtime F$ , E$ , F$ , E$ , G$ , E$ , H$ , E$ , z$ , E$, J$ , E$ , K$ ; 'Set RTC to correct local time and date
RTC GETTIME
Text 90,215, DOW$(DayOfWeek(Year, Month, Day)), CM, 1, 2, RGB(BLACK), RGB(63, 133, 195) 'Print the Day of week Under Big Ben
Text 90,270, Date$, CM, 1, 2, RGB(BLACK), RGB(63, 133, 195) 'Date
secs=Val(Right$(Time$,2))
mins=Val(Mid$(Time$,4,2))
hours=Val(Left$(Time$,2))
print time$ , "RTC TIME" ;
ELSE T6
END SUB[/code]

but it doesn't work, the RTC does not set itself to the correct time

The string being received on COM1 is this
[code]Print #2,"TIME" , "," , Y1 , "," , M1 , "," , D1 , "," , H1 , "," , M2 , "," , S2 [/code]
Y1 = year (2016)
M1 = month (12)
D1 = day (9)
H1 = hour (22)
M2 = min (22)
S2 = sec (37)

date and time right this second*

Anyone see what I'm doing wrong, or any suggestions how to get it right?

Gerry I did try what you said but it wouldn't work as RTC SETTIME needs comma's between each section

Is it possible to have something like W = Y1,"."M1","D1","H1","M2","S2

then do this? RTC SETTIME W

EDIT: just tried it and it doesn't work
Edited by lew247 2016-12-10
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 02:18pm 09 Dec 2016
Copy link to clipboard 
Print this post

Lew
disco4now gave you the answer above. The format for settime is
RTC SETTIME year, month, day, hour, minute, second
The parameters are numeric and separated by commas.

Suppose the date was 10 December 2016 and the time was 11:12:30 the way ahead is
[code]
RTC SETTIME 16,12,10,11,12,30
[/code]

or you can do it as
[code]
yy=16
mm=12
dd=10
hh=11
min=12
ss=30

RTC SETTIME yy,mm,dd,hh,min,ss
[/code]
You can use any variable names that suit but they must be numeric not strings and forget about quote marks "".


 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 02:27pm 09 Dec 2016
Copy link to clipboard 
Print this post

Or to use your example of
Y1 = year (2016)
M1 = month (12)
D1 = day (9)
H1 = hour (22)
M2 = min (22)
S2 = sec (37)

you would have to do Y1=year(16)
because the required value for the year is only the last two digits.

and the command would be
RTC SETTIME Y1,M1,D1,H1,M2,S2

not sure why you are using arrays but you could also do

Y1=16
M1=12
D1=9
H1=22
M2=22
S2=37
RTC SETTIME Y1,M1,D1,H1,M2,S2



 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9590
Posted: 04:03pm 09 Dec 2016
Copy link to clipboard 
Print this post

Agreed.

[Quote=Lew]RTC SETtime F$ , E$ , F$ , E$ , G$ , E$ , H$ , E$ , z$ , E$, J$ , E$ , K$ ; 'Set RTC to correct local time and date[/Quote]

This will throw an error as soon as the command hits F$, and the code will break to the command prompt with an error.

RTC SETTIME MUST follow the correct syntax, and the numbers past to it must also be integer numbers - strings or floating-point will be instantly rejected.

Good luck - you almost have it, you just need to convert the strings to numbers with the VAL command as disco and Bob are saying.
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6269
Posted: 04:07pm 09 Dec 2016
Copy link to clipboard 
Print this post

Lew,
rather than do so many conversions from strings to numbers and back again,
I think the GPS data is fixed length so it would be easier to send the original fields "as is" and do the extraction in the indoor unit.

In your outdoor code:
In the KeepSearching: sub,
after you have extracted the other data

add two new lins
GPSdate$ = arg$(9)
GPStime$ = arg$(1)

To send the data to the indoor unit use:
Print #2,"TIME" +GPSdate$+GPStime$
instead of
Print #2,"TIME" , "," , Y1 , "," , M1 , "," , D1 , "," , H1 , "," , M2 , "," , S2

then

the line received by the indoor unit is one string "TIMEyyMMddhhmmss"
assuming you have is captured as E$

Y1 = val(mid$(E$,5,2)
M1 = val(mid$(E$,7,2)
D1 = val(mid$(E$,9,2)
H1 = val(mid$(E$,11,2)
M2 = val(mid$(E$,13,2)
S2 = val(mid$(E$,15,2)

you will need to convert from UTC to local time. I am not sure if you are changing the RTC for daylight saving. If not, there is no conversion needed.

to set the RTC

RTC SETTIME Y1,M1,D1,H1,M2,S2

Jim
VK7JH
MMedit
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 01:11am 10 Dec 2016
Copy link to clipboard 
Print this post

deleted* I made an errorEdited by lew247 2016-12-11
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 03:40am 10 Dec 2016
Copy link to clipboard 
Print this post


While the outdoor unit is searching for the GPS lock it sends this to the indoor unit
Then once it has a correct lock and converted the time to the CORRECT LOCAL TIME it then sends this where Y1 = year M1 = month D1 = day H1 - hour M2 = min S2 = sec

[code]
Searching For GPS signal
Searching For GPS signal
Searching For GPS signal
CHECK1 16 12 10 13 35 23
13:35:23
*********************************
13:36:09

Sat 10-Dec-2016
Battery Voltage 4.00 V
Direction: 94.6041 Degrees
WindSpeed: 0 MPH
Gust 0.42 MPH
Highest Gust 0.42 MPH
Rain Today 0.00 mm
Rain Yesterday 0.00 mm
Temperature 24.12 C
Highest Temp 24.12 C
Lowest Temp 24.12 C
Hi Temp Yesterday 0.00 C
LOW Temp Yesterday 0.00 C
Pressure 1008.55 mB
HUMIDITY 54.41%
UV Index: 0.02
*******************************
[/quote]

This is what the indoor unit sees

[quote]
START Searching
START Searching
START , 24.12, 0, 0, 94.6041, 0, 0.416667, 0.416667, 0, 0, 24.12, 0, 24.12, 0, 0.02, 4.0043[/quote]

Anyone see WHY NEITHER [quote]
PRINT #1,"START" Y1,M1,D1,H1,M2,S2
***OR***
Print #1,"TIME",",", Y1,",",M1,",",D1,",",H1,",",M2,",",S2 ' Send correct date/time to Indoor unit to set RTC[/quote]

are sending the the indoor unit?

I know it's not sending because the string starts with the word "START" which the indoor unit already recognises and prints whatever is after this



 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4036
Posted: 03:48am 10 Dec 2016
Copy link to clipboard 
Print this post

I'm struggling with the English a bit but...

The first PRINT won't output any commas (they're not in quotes so just act as punctuation).

The second does not have the word START in it, if you need that as I think you say.

So, let's suppose Y1 M1 D1 H1 M2 S2 are the numbers (for example 1 2 3 4 5 6,
the first would print something like START 1 2 3 4 5 6
the second something like TIME , 1 , 2 , 3, 4 , 5 , 6
(I think)

JohnEdited by JohnS 2016-12-11
 
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1702
Posted: 03:54am 10 Dec 2016
Copy link to clipboard 
Print this post

Sorry I should have explained a bit better

The indoor unit looks for EITHER the word START or TIME and does different things depending on which it receives

It's receiving and getting both the searching string from the outdoor unit, and also the string where it receives the actual weather data

It's NOT getting these strings from the outdoor unit

PRINT #1,"START" Y1,M1,D1,H1,M2,S2 ' this sends the correct local time and date

or

Print #1,"TIME",",", Y1,",",M1,",",D1,",",H1,",",M2,",",S2 ' Send correct date/time to Indoor unit to set RTC


EDIT: the example above that begins with [code] and ends in ]/code] is what I see on the CONSOLE output from the indoor unit so I know it's sending the correct info

The line CHECK1 16 12 10 13 35 23 is actually a check for myself to see that Y1,M1,D1,H1,M2,D2 are actually the time and date and are correct

Edited by lew247 2016-12-11
 
     Page 13 of 25    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025