Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

NetworkTimeProtocol to synchronize datalogger


Benjamin.vial Jan 20, 2021 05:13 PM

Hello,

I have a CR800 plugged on a 3G router, on line.

I'm trying to use the NTP function in a CR800 program to get the datalogger synchronize with real time (UTC).

I don't need a lot of accuracy, something about 1 secondes is enough. I'm scanning every 10 secs and record every 10 minutes. But it will be a permanent observation station, so it must be synchronize.

Here is my prog :

 

'CR800 Series
'Created by Short Cut (4.3)

'Declare Variables and Units
Public rTime(9)

Public BattV
Public PTemp_C
Public T107_C
Public SR50A(2)
Public TCDT
Public SlrW
Public SlrkJ
Public WS_ms
Public WindDir

Alias SR50A(1)=DT
Alias SR50A(2)=Q

Units BattV=Volts
Units PTemp_C=Deg C
Units T107_C=Deg C
Units SlrW=W/m^2
Units SlrkJ=kJ/m^2
Units WS_ms=meters/second
Units WindDir=degrees

'Define Data Tables
DataTable(environnement,True,-1)
	DataInterval(0,1,Min,10)
	Average(1,T107_C,FP2,False)
	Average(1,DT,FP2,False)
	Average(1,Q,FP2,False)
	Average(1,TCDT,FP2,False)
	Average(1,SlrW,FP2,False)
	Totalize(1,SlrkJ,IEEE4,False)
	Average(1,WS_ms,FP2,False)
	WindVector(1,WS_ms,WindDir,FP2,False,0,0,2)
	FieldNames("WS_ms_S_WVT,WS_ms_U_WVT,WindDir_DU_WVT,WindDir_SDU_WVT")
EndTable

DataTable(soh,True,-1)
	DataInterval(0,1,Min,10)
	Minimum(1,BattV,FP2,False,False)
	Minimum(1,PTemp_C,FP2,False,False)
EndTable

'Main Program
BeginProg
	'Main Scan
	Scan(5,Sec,1,0)
		'Default CR800 Datalogger Battery Voltage measurement 'BattV'
		Battery(BattV)
		'Default CR800 Datalogger Wiring Panel Temperature measurement 'PTemp_C'
		PanelTemp(PTemp_C,_50Hz)
		'107 Temperature Probe (CSL) measurement 'T107_C'
		Therm107(T107_C,1,1,1,0,_50Hz,1,0)
		'SR50A/SR50A-EE Sonic Ranging Sensor (SDI-12 Output) measurements 'DT' and 'Q' and calculations 'TCDT' and 'DBTCDT'
		SDI12Recorder(SR50A(),1,"0","M1!",1,0,-1)
		TCDT=DT*SQR((T107_C+273.15)/273.15)
		'CMP3/CMP6/CMP11 Pyranometer measurements 'SlrkJ' and 'SlrW'
		VoltDiff(SlrW,1,mV25,2,True,0,_50Hz,1,0)
		If SlrW<0 Then SlrW=0
		'Calculate total flux
		'The multiplier to calculate total flux was calculated by Short Cut
		'and based on a program execution rate (scan rate) of 5 Seconds.
		'If you change the program execution rate outside of Short Cut with the CRBasic Editor
		'you will need to recalculate this multiplier. See the sensor manual for more details.
		SlrkJ=SlrW*0.348432
		'Calculate flux density
		SlrW=SlrW*69.68641
		'03002-5 Wind Speed & Direction Sensor (CSL) measurements 'WS_ms' and 'WindDir'
		PulseCount(WS_ms,1,1,0,0,0.75,0.2)
		If WS_ms<0.21 Then WS_ms=0
		BrHalf(WindDir,1,mV2500,2,1,1,2500,True,20000,_50Hz,352,0)
		If WindDir>=352 Or WindDir<0 Then WindDir=0
		'Call Data Tables and Store Data
		CallTable environnement
		CallTable soh
	NextScan
	SlowSequence
		Scan (10,Sec,3,0)
		NetworkTimeProtocol ("fr.pool.ntp.org",0,100)
		RealTime(rTime)
	EndSequence
NextScan EndProg

 Compilation works, but time doesn't want to synchronize.


GaryTRoberts Jan 20, 2021 06:24 PM

Benjamin, Are you using a NL201 with the 3G router or a serial connection?


Benjamin.vial Jan 21, 2021 05:55 AM

Hi,

In this case I'm using serial to USB converter plugged to the router. But in other cases I use NL120 with ethernet directly.


GaryTRoberts Jan 21, 2021 01:53 PM

The logger requires an Ethernet interface with a TCP/IP connection to the internet in order for NTP to work. Your loggers attached to NL201s will be able to use NTP, but not this one with just an USB to RS-232 serial connection.


Benjamin.vial Jan 21, 2021 02:56 PM

Hello,

you didn't mentionned the NL120, but I think it's working as NL201 ?

So, for the serial connexion, I will use a specific external linux code, for sending a "time set", more complex but it should works ... For my case at least, with an accuracy of 1 seconde.

Thanks for your answers.

Bye


Benjamin.vial Jan 22, 2021 09:18 AM

In addition : can you confirm that with a CR1000 and a NL120, in ethernet, this part of the program is OK to synchronize the datalogger to UTC time ?

(between the last "NextScan" and the "EndProg")

 

 

        SlowSequence
		Scan (10,Sec,3,0)
		NetworkTimeProtocol ("fr.pool.ntp.org",0,100)
		RealTime(rTime)
	EndSequence
        NextScan

 

thanks


GaryTRoberts Jan 22, 2021 03:43 PM

Yes, the code you have listed will work. It will call NTP every 10 seconds which is a lot of usage. It might be best to run it once a day in a slowscan. The CR1000X clock is really steady and shouldn't need to be checked more than once a day. I would even say once a month might be good enough.


Benjamin.vial Jan 25, 2021 07:54 AM

Hi,

Ok then I'll modify to once per day at least. I have a CR1000 (not X).

Maybe after several weeks I will try more importante time between synchro (7 days, 14 days, ...), to test.

Thanks for your help,

bye

Log in or register to post/reply in the forum.