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() attachment received but is empty

TLT Oct 27, 2019 06:36 AM

Hi All,

Need help over here.

Please help.

I am testing on CR1000 OS 32.03 sending the data via the FTPClient and the EmailRelay. Data interval every minute and send them every 2 minutes. My program as below.

For the FTP is working fine. but for the EmailRelay, Email was received with an empty .dat file attachment 0KB.

'The 'Interval' values will be numerical. The available 'Unit' values are: Sec, Min, Hr, Day

Const Interval = 1
Const Unit = Min


'Declare Public Variables
Public PTemp, batt
Public LDT1, LV1
Public FB(2)

'''EmailRelay() constants
Const EMAIL_ATTACHMENT = "USR:NCC_logger1_ftp.dat"
Const EMAIL_SUBJECT = "Email Message"
Const EMAIL_TO_ADDRESS = "user@yahoo.com.sg"
Const CR_LF = CHR(13) & CHR(10)

''''EmailRealy() variables
Const email_message = "Readings"
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

'FTP Variables
Public FTPSuccess As Boolean
Public OutStat As Boolean
Public LastFile As String * 100

'''Server' FTP Details
Const IPAddress = "ftp server"
Const User = "user"
Const Password = "password"
Const FileName = "/XXX/NCC_logger1_FTP.dat"

'Define Data
'Data table VW will store all of the data.
DataTable (NCC_logger1_FB,1,-1)
Sample (1,batt(),FP2)
Sample (1,PTemp(),FP2)
Sample (1,LDT1,IEEE4)
Sample (2,FB(),IEEE4)
Sample (1,email_relay_results_human_readable,String)

'VW_ftp will only store readings,
DataTable (NCC_logger1_ftp,1,2)
TableFile ("USR:VW",8,0,0,2,Min,OutStat,LastFile)
Sample (1,batt(),FP2)
Sample (1,PTemp(),FP2)
Sample (1,LDT1,IEEE4)
Sample (2,FB(),IEEE4)

'Main Program
'Set up USR drive to write data
SetStatus ("USRDriveSize",226584)
Scan (Interval,Unit,0,0)

PanelTemp (PTemp,250)
Battery (batt)

ExciteV (Vx1,0,1)

BrFull (LV1,1,mV7_5C,1,Vx1,1,2500,True ,True ,0,250,4000,0)'LDT Reading for testing use

LDT1= LV1*0.01 -(0)'LDT Factors plus initial for testing use

Delay (0,150,mSec)
BrFull (FB(1),1,mV25C,2,Vx2,1,2500,True ,True ,0,250,2000,0)
Delay (0,150,mSec)
BrFull (FB(2),1,mV25C,3,Vx2,1,2500,True ,True ,0,250,2000,0)

CallTable (NCC_logger1_FB)
CallTable (NCC_logger1_ftp)

'''Send data, via FTP
If OutStat = true Then
FTPSuccess = FTPClient (IPAddress,User,Password,LastFile,FileName,0)

'Email data
'1st attempt
email_tx_success = EmailRelay (EMAIL_TO_ADDRESS,EMAIL_SUBJECT,email_message,email_relay_server_response,EMAIL_ATTACHMENT)
'If EmailRelay was not successful, lets 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)

'Human readable error messages
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."

OutStat = false


nsw Oct 31, 2019 11:57 AM

The FTPClient works because the file it is looking to send is defined in variable "LastFile" which is generated by the "TableFile" instruction in the output table.

Your "EmailRelay" instruction asks to attach "Email_Attachment" which is set to look for "USR:NCC_logger1_ftp.dat", which does not exist. No instructions create this file. It maybe simpler to attach the data directly from the Tbale itself, using the optional parameters.

Please note, EmailRelay has a daily maximum on the number of emails that can sent through this free-of-charge service. I believe this is 100 per day.

TLT Nov 1, 2019 02:21 PM

Hi nsw,

Thanks for your reply.

Much appreciate if you could share a short program of sending data using “EmailRelay” instruction.

Thanks in advance.

GaryTRoberts Nov 1, 2019 03:17 PM

Even though this is the help for the CR1000X, the same parameters and examples can be used on the CR1000. https://help.campbellsci.com/crbasic/cr1000x/#instructions/emailrelay.htm%3FTocPath%3DCR1000X%2520Instructions%7CInternet%2520Protocols%7C_____3

TLT Nov 4, 2019 09:42 AM

Hi Gary,

Thanks for your help.

EmailRelay is working now. i am able to received the email with data.

I have 2 more questions.

1. I am getting EamilRelay's ServerResp -2, under what situation will the streaming interval become true?

2. Can I program to send out the 24 hours data daily at 8am specifically?

Tuser May 31, 2022 01:59 AM

Hi all

i am having same problem with CR310 datalogger.

Sending the data via the EmailRelay. 

The Email was received with an empty file attachment.

thank you.

nsw Jun 6, 2022 03:46 PM

Check you have the latest OS loaded in the CR310. Latest OS revision is 10.06. An earlier version had a bug with EmailRelay and zero file sizes in attachments.

CR300 Series OS: Get the latest download (campbellsci.com)

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