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.

Sending email from Data Logger


#RD@2020 Jun 11, 2020 04:16 PM

Hi there,

I am using the CR300 Datalogger. I  want to test a small program for an email message, but a datalogger is unable to send emails. 

In the following example program, an email message is sent when the datalogger panel temperature is greater than 20 degrees.

'Main program variables
Public battery_voltage
Public panel_temperature
Public temperature


'EmailRelay() constants
Const _EMAIL_ATTACHMENT = ""
Const _EMAIL_SUBJECT = "Email Message"
Const _EMAIL_TO_ADDRESS = " email "
Const _CR_LF = CHR(13) & CHR(10)

'EmailRelay() variables
Public email_message As String * 300
Public email_relay_server_response As String * 100
Public email_relay_results_human_readable As String * 100
Public email_trigger As Boolean
Public email_tx_success

BeginProg
Scan (1,Sec,3,0)
Battery (battery_voltage)
PanelTemp (panel_temperature,250)
TCDiff (temperature,1,mV200C,1,TypeT,panel_temperature,True ,0,250,1.0,0)
'TCDiff (TCTemp(),5,mV20C,1,TypeT,PTemp,True ,0,250,1.0,0)
If temperature > 20 Then
email_trigger = True
EndIf
NextScan

SlowSequence
Do
If email_trigger = True Then
email_trigger = False 'reset my trigger
email_message = "Warning!" & _CR_LF & _CR_LF
email_message = email_message & "This is a automatic email message from the datalogger station " & Status.StationName & ". "
email_message = email_message & "An alarm condition has been identified." & _CR_LF
email_message = email_message & "The temperature is " & temperature & " degrees C." & _CR_LF
email_message = email_message & "Datalogger time is " & Status.Timestamp

'1st attempt
email_tx_success = EmailRelay (_EMAIL_TO_ADDRESS,_EMAIL_SUBJECT,email_message,email_relay_server_response,_EMAIL_ATTACHMENT)

'If EmailRelay was not successful, let us try one more time.
If email_tx_success <> -1 Then
'2nd attempt
email_tx_success = EmailRelay (_EMAIL_TO_ADDRESS,_EMAIL_SUBJECT,email_message,email_relay_server_response,_EMAIL_ATTACHMENT)
EndIf

'tell my human what happened with EmailRelay in human speak instead of longer speak
' my user got this information from the CRBasic help for EmailRelay
Select Case email_tx_success
Case -1
email_relay_results_human_readable = "EmailRelay server received the message from the datalogger successfully!"
Case 0
email_relay_results_human_readable = "The connection to the EmailRelay server failed."
Case -2
email_relay_results_human_readable = "Execution of the EmailRelay function did not occur due to lack of records or not enough time."
Case -3
email_relay_results_human_readable = "A connection to the EmailRelay server was made but there was an error in communication."
EndSelect
EndIf
Loop
EndProg

Thanks! 

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