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 works the first time but not again

bond Jun 11, 2021 06:52 PM


I am having a weird issue with EmailRelay. I have a CR300 running OS CR300.Std.10.04 connected to an Airlink RV50 through the RS232 port. My goal is to have data recorded every 15 minutes, then sent to me once per day. If one fo the recorded values is outside of pre-defined thresholds, then i get an alert email once and hour. To save battery the RV50 is triggerred on the VX1 port, waking up before each data transmission attempt.

For testing i have asked the CR300 to transmit the data every 10 minutes.

So when the program runs, or the CR300 is reset (program set to run on boot), the EmailRelay works as intended and i get an email with the file attached. The issue is that the next loop, and every loop after that the program will close without sending. If i restart the logger then it happens again, first time through it works but not again after that.

Watching the PPP Network status during operation, when it fails, the IP state is opened, an IP address/gw/dns is updated, then a "user interrupt occurs and the program closes.


'CR300 Series Datalogger
Public rTime(9)               'declare as public and dimension rTime to 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)
Alias rTime(8) = WeekDay      'assign the alias WeekDay to rTime(8)
Alias rTime(9) = Day_of_Year  'assign the alias Day_of_Year to rTime(9)

'Declare Public Variables
Public PTemp, batt_volt

'''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
Public P3Open As String, P3Close
''''EmailRealy() variables for email readings Public email_trigger As Boolean Public email_tx_success Public email_ServerResp 'Declare Constants Public SM1C As Float Public SM2C As Float Public pH As Float Public pHmeter As Float Public SMS_Send_Res As Long 'Variable to hold SMSSend response Public OpenFile1 As Long Public Record_msg As String * 150 'Variable to hold the each Test message to send Public email_msg As String * 1800 '150 * 12 'Variable to hold the hourly message to send Public maxRec As Long, rec As Long Public CloseStat Const _CR_LF = CHR(13) & CHR(10) '''Set the time interval for storage data in table Const Interval = 15 Const Unit = Min '''The 'pH' values will be numerical. Const pH_Low = 6.0 Const pH_High = 9.0 'Define Data Tables DataTable (Test,1,-1) 'Set table size to # of records, or -1 to autoallocate Minimum (1,batt_volt,IEEE4,False,False) Sample (1,PTemp,IEEE4) Sample (1,SM1C,IEEE4) Sample (1,SM2C,IEEE4) Sample (1,pHmeter,IEEE4) Sample (1,pH,IEEE4) Sample (1,SMS_Send_Res,Long) EndTable ''''EmailRelay() constants for battery alert Const EMAIL_ATTACHMENT_ALERT = "" Const EMAIL_SUBJECT_ALERT = "Logger pH ALERT" Const EMAIL_TO_ADDRESS_ALERT = "myemailaddress" '''EmailRelay() constants for email readings Const EMAIL_ATTACHMENT = "" Const EMAIL_SUBJECT = "Logger Readings" Const EMAIL_TO_ADDRESS = "myemailaddress" Const CR_LF = CHR(13) & CHR(10) ''''EmailRealy() const for email readings Const email_message = "Logger Readings" 'MAIN PROGRAM+++ BeginProg P3Close = PPPClose Scan (15,min,0,0) PanelTemp (PTemp,60) Battery (batt_volt) RealTime (rTime)) VoltSe (SM1C,1,mV2500,1,1,0,60,1.0,0) VoltSe (SM2C,1,mV2500,2,1,0,60,1.0,0) VoltSe (pHmeter,1,mV2500,6,1,0,60,1.0,0) Const pH_slope = 4.6299 Const pH_offset = 2.5373 Const VpHscalefactor = 2.483483 Dim Vout, TK Vout = (pHmeter/1000)*VpHscalefactor TK = PTemp + 273 pH = 7.0 + (Vout - pH_offset)/(pH_slope * TK * 1.98416E-4) pH = 1.0640182915 * pH - 0.246710442 'Enter other measurement instructions 'Call Output Tables CallTable Test 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 (7,10,Min) Then PortSet(VX1, 1) P3Open = PPPOpen Delay (0,60,2) OpenFile1 = FileOpen ("CPU:Log-"+Month+"-"+DOM+".txt","w",0) email_msg = "" maxRec = Test.record(1,1) If maxRec > 96 Then maxRec =96 '24 hours worth For rec = 1 To maxRec GetRecord (Record_msg,Test,rec) FileWrite (OpenFile1,Record_msg,0) Next rec CloseStat=FileClose (OpenFile1) email_msg = "Hi," +_CR_LF + _CR_LF email_msg = email_msg + "Logger Data attached.(MaxRecords = " + maxRec +")." email_msg = email_msg + +_CR_LF + _CR_LF + "Bye!" email_tx_success = EmailRelay (EMAIL_TO_ADDRESS,EMAIL_SUBJECT,email_msg,email_ServerResp,"CPU:Log-"+Month+"-"+DOM+".txt") If email_tx_success <> -1 Then email_tx_success = EmailRelay (EMAIL_TO_ADDRESS,EMAIL_SUBJECT,email_msg,email_ServerResp,"CPU:Log-"+Month+"-"+DOM+".txt") EndIf SMS_Send_Res = email_tx_success email_trigger = False '''reset my trigger Delay (0,30,2) P3Close = PPPClose PortSet(VX1, 0) EndIf Loop SlowSequence 'Use Scan to define the alert notification frequency Scan (01,Hr,2,0) ''''Email battery voltage alert If pH < pH_Low OR pH > pH_High OR email_trigger_ALERT = True Then PortSet(VX1, 1) P3Open = PPPOpen Delay (0,60,2) 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 Delay (0,30,2) P3Close = PPPClose PortSet(VX1, 0) EndIf NextScan ' end of the scan (01,Hr,2,0) EndSequence EndProg


pokeeffe Jun 14, 2021 07:40 PM

The bare Do..Loop in the second SlowSequence is an interesting approach. I would have placed the If..EndIf block in the scan that defines alert frequency or wrote it as a Subroutine instead.

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