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.

EmailRelay- Email Daily data


TLT Jul 19, 2020 10:10 PM

Hi,

I have two EmailRelay in the same program, one to email out 24 hours data everyday in the morning 08:00am and other EmailRelay to send out an alert for low battery voltage. The alert is working fine but for 24 hours data email was received at 08:00am and the attached data was starting from 00:15 to 00:00. I wanted the data to be from 08:15 to 08:00. I added RealTime for this.

'''The 'Interval' values will be numerical. The available 'Unit' values are: Sec, Min, Hr, Day
'''Scanning interval
Const Interval = 15
Const Unit = Min

'''The 'batt_ALERT' values will be numerical.
Const batt_ALERT = 13.4
''''-------------------------------------------------------------------------
''''-------------------------------------------------------------------------
''''EmailRelay() constants for battery alert
Const EMAIL_ATTACHMENT_ALERT = ""
Const EMAIL_SUBJECT_ALERT = "Logger Battery ALERT"
Const EMAIL_TO_ADDRESS_ALERT = "email@email.com"

'''EmailRealy() variables for battery alert
Public email_message_ALERT As String * 300
Public email_trigger_ALERT As Boolean
Public email_tx_success_ALERT
Public email_ServerResp_ALERT

'''EmailRelay() constants for email readings
Const EMAIL_ATTACHMENT = "TEMP"
Const EMAIL_SUBJECT = "Logger Readings"
Const EMAIL_TO_ADDRESS = "email@email.com"
Const CR_LF = CHR(13) & CHR(10)

''''EmailRealy() variables for email readings
Const email_message = "Logger Readings"
Public email_trigger As Boolean
Public email_tx_success
Public email_ServerResp


Public PTemp, batt_volt, T107_C

Public rTime(9)
'Alias rTime(1) = Year 'assign the alias Year to rTime(1)
'Alias rTime(2) = Month 'assign the alias Month to rTime(2)
'Alias rTime(3) = DOM 'assign the alias DOM to rTime(3)
Alias rTime(4) = Hour 'assign the alias Hour to rTime(4)
Alias rTime(5) = Minute 'assign the alias Minute to rTime(5)
'Alias rTime(6) = Second 'assign the alias Second to rTime(6)
'Alias rTime(7) = uSecond 'assign the alias uSecond to rTime(7)


DataTable (TEMP,1,-1)
Sample (1,batt_volt,FP2)
Sample (1,PTemp,FP2)
Average (1,T107_C,FP2,0)
Sample (1,Hour,IEEE4) 'place Hour in VALUES table
Sample (1,Minute,IEEE4) 'place Minute in VALUES table
EndTable


BeginProg

Scan (Interval,Unit,0,0)'Scan every 15 minute
PanelTemp (PTemp,250)
Battery (batt_volt)
RealTime( rTime )
Therm107 (T107_C,1,3,Vx1,0,_60Hz,1.0,0)

CallTable TEMP

''''Check battery voltage
If batt_volt < batt_ALERT Then
email_trigger_ALERT = True
EndIf

''''Check Time
If rTime(4) = 8 AND rTime(5) = 0 Then
email_trigger = True
EndIf
NextScan

SlowSequence
Do
'''Email data
If email_trigger = True Then
email_trigger = False '''reset my trigger

email_tx_success = EmailRelay (EMAIL_TO_ADDRESS,EMAIL_SUBJECT,email_message,email_ServerResp,EMAIL_ATTACHMENT,0,24,Hr,8)

EndIf

''''Email battery voltage alert
If email_trigger_ALERT = True Then
email_trigger_ALERT = False '''reset my trigger
email_message_ALERT = "Warning!" & CR_LF & CR_LF
email_message_ALERT = email_message_ALERT & "This is a automatic email message from the datalogger station " & Status.StationName & ". "
email_message_ALERT = email_message_ALERT & "An alarm condition has been identified." & CR_LF
email_message_ALERT = email_message_ALERT & "The battery voltage is " & batt_volt + " volts." & CR_LF
email_message_ALERT = email_message_ALERT & "Datalogger time is " & Status.Timestamp

email_tx_success_ALERT = EmailRelay (EMAIL_TO_ADDRESS_ALERT,EMAIL_SUBJECT_ALERT,email_message_ALERT,email_ServerResp_ALERT,EMAIL_ATTACHMENT_ALERT)

EndIf
Loop

EndProg

Thanks,

TLT


JCaycho Jul 20, 2020 09:30 PM

Hello TLT,

I have modified your code to get data log by email with EmailRelay at the required time with "IfTime" instruction.

I have inserted some comments so that you can continue adapting it to your requirements.

 

'CR1000 Series Datalogger

'Declare Public Variables
Public PTemp, batt_volt, T107_C

'''EmailRealy() variables for battery alert
Public email_message_ALERT As String * 300
Public email_trigger_ALERT As Boolean
Public email_tx_success_ALERT
Public email_ServerResp_ALERT

''''EmailRealy() variables for email readings
Public email_trigger As Boolean
Public email_tx_success
Public email_ServerResp

'Declare Constants

'''Set the time interval for storage data in table
Const Interval = 15
Const Unit = Min

'''The 'batt_ALERT' values will be numerical.
Const batt_ALERT = 12.0

''''EmailRelay() constants for battery alert
Const EMAIL_ATTACHMENT_ALERT = ""
Const EMAIL_SUBJECT_ALERT = "Logger Battery ALERT"
Const EMAIL_TO_ADDRESS_ALERT = "email@email.com"


'''EmailRelay() constants for email readings
Const EMAIL_ATTACHMENT = "TEMP"
Const EMAIL_SUBJECT = "Logger Readings"
Const EMAIL_TO_ADDRESS = "email@email.com"
Const CR_LF = CHR(13) & CHR(10)

''''EmailRealy() const for email readings
Const email_message = "Logger Readings"


'Define Data Tables.

DataTable (TEMP,1,-1)
DataInterval (0,Interval,Unit,10)'Save data every 15 minute
Sample (1,batt_volt,FP2)
Sample (1,PTemp,FP2)
Average (1,T107_C,FP2,0)
EndTable

'MAIN PROGRAM+++
BeginProg

Scan (1,sec,3,0)

  PanelTemp (PTemp,250)
  Battery (batt_volt)
 
  Therm107 (T107_C,1,3,Vx1,0,_60Hz,1.0,0)
	'Enter other measurement instructions
	
  'Call Output Tables
		
  CallTable TEMP

NextScan

SlowSequence
  Do
  '''Email data
  'Use IfTime (481,1440,Min) in minutes to indicate the time of the data sending at 08:01 hours.
  'Also considered a trigger with a boolean in public values
   
  If email_trigger = True OR IfTime (481,1440,Min) Then
  
  email_tx_success = EmailRelay (EMAIL_TO_ADDRESS,EMAIL_SUBJECT,email_message,email_ServerResp,EMAIL_ATTACHMENT,0,-24,Hr,8)
 
  email_trigger = False '''reset my trigger
  EndIf
  
  Loop


SlowSequence

'Use Scan to define the alert notification frequency, considering that the battery voltage below the alert level will always be low at all times.
  Scan (01,Hr,2,0)  
  
  ''''Email battery voltage alert
    If batt_volt < batt_ALERT OR email_trigger_ALERT = True Then
    
    email_message_ALERT = "Warning!" & CR_LF & CR_LF
    email_message_ALERT = email_message_ALERT & "This is a automatic email message from the datalogger station " & Status.StationName & ". "
    email_message_ALERT = email_message_ALERT & "An alarm condition has been identified." & CR_LF
    email_message_ALERT = email_message_ALERT & "The battery voltage is " & batt_volt + " volts." & CR_LF
    email_message_ALERT = email_message_ALERT & "Datalogger time is " & Status.Timestamp
    
    email_tx_success_ALERT = EmailRelay (EMAIL_TO_ADDRESS_ALERT,EMAIL_SUBJECT_ALERT,email_message_ALERT,email_ServerResp_ALERT,EMAIL_ATTACHMENT_ALERT)
    
    email_trigger_ALERT = False '''reset my trigger
    EndIf

   NextScan  ' end of the scan (01,Hr,2,0)
EndSequence

EndProg

Regards,


Juan Caycho B.


TLT Jul 22, 2020 07:08 PM

Hi Juan Caycho B.,

The program works well.

Thanks for your great help.

Regards,

TLT

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