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 15, 2020 12:30 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! 


GaryTRoberts Jun 15, 2020 03:39 PM

What does email_relay_server_response and email_relay_results_human_readable show when the threshold is reached? That gives you a good clue as to what is or is not happening.


#RD@2020 Jun 15, 2020 04:40 PM

In the above example program, an email message is sent when the datalogger panel temperature is greater than 30 degrees. A constant, _CR_LF, is declared to represent the carriage return and line feed characters, (CHR(13) and CHR(10), for ease of use in the email message. Case statements are used to convert server-response-error codes into human-readable text.

Using this program, the email message text will be similar to:

Warning!

This is an automatic email message from the datalogger station 1010. An alarm condition has been identified. The temperature is 30.50768 degrees C.

Datalogger time is 06/10/2020 13:52:27.0

I'm using an example of  CRbasic help If this works then I'm planning to put in the field program. First I tried to insert the same logic/program in-field program but this is not working. 

So I Have put a sample program but I haven't got an email from datalogger.

If you have a sample program I will try this one. But I really need an email from datalogger when strain gauge and temperature exceeds limits.

Thanks!


GaryTRoberts Jun 15, 2020 05:29 PM

One error I see it this line:

TCDiff (temperature,1,mV200C,1,TypeT,panel_temperature,True ,0,250,1.0,0)

The CR300 can do the vmV200C range. You will need to change this to mv2500 or mv34.

Your datalogger should be showing an error message. Something like line 24: Undeclared variable mV200C.


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

Thanks for your reply.

Yes, I have correct these errors. I have cr6 and cr3000 datalogger.

I didn't get the email from cr3000 and the problem is unable to connect the modem. I got an email from CR6(i have connected the modem to the CR6) 

can you tell me how can I connect modem or ethernet cable to the CR3000 Datalogger?

Thanks!

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