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.

automatic emailing with CR1000


schraubehaube Mar 14, 2017 10:12 AM

Hi everybody,

I try implement a automatic email procedure on a CR1000. This is my code so far, only the needed code for emailing is shown:

'settings for email transmition
Public PPP_IPAddress As String * 20 ' The current datalogger IP address
Public PPP_CloseResult As Boolean   ' The result of the last attempt to disconnect
Public count, count2
Public EMAIL_Result As Boolean ' The result of the last email attempt
Public EMAIL_Response As String * 255  ' The last repsonse from the smtp server
'Public pastloop
Public OutStat As Boolean
Public LastFileName As String * 100

Const PPP_TIMEOUT = 120  ' How long to wait until we have a valid PPP connection [s]
Const EMAIL_SERVER = "smtp.xxxxx.xxx"      ' The smtp server to use to send the email
Const EMAIL_USER = "logger_email_test"           ' The user name for the smtp server
Const EMAIL_PASS = "XXXXXX"         ' The password for the smtp server
Const EMAIL_TO = "xxx.xxx@xxxxx.com" '" The address to send the email to
Const EMAIL_FROM = "xxx_xxx_xxxxx@xxx.xx"     ' The email address the email will be sent from
Const EMAIL_SUBJECT = "Test for automatic eMail function. Ogorje 869"
Dim EMAIL_MESSAGE As String * 1000
Public EMAIL_ATTACH_FILE As String * 100 ' The path to the attach file on the datalogger


  'Table
  DataTable (Tabla,1,-1)'declaration
  DataInterval (0,10,Min,10)
 
 TableFile ("USR:Xxxxxx_Test_File_",8,-1,0,1,Min,OutStat,LastFileName)


 
EndTable

'Define Subroutines
' -- PPP Connect ----------------------------------------------------------------------
Sub PPP_Connect
  PPP_IPAddress = "0.0.0.0"
  ' Start a timer to time how long it takes to connect via PPP
  Timer (1,Sec,2)
  ' Keep looping until a valid IP address is returned
  Do While PPP_IPAddress = "0.0.0.0"
    ' See if we have a valid IP address yet
    PPP_IPAddress = PPPOpen()
    ' If we have been trying to connect for longer than the timeout period, exit the
    ' loop
    If Timer(1,Sec,4) >= PPP_TIMEOUT Then ExitDo
    ' Delay 1 second between attempts
    Delay(1,1,Sec)
  Loop
EndSub

' -- PPP Disconnect -------------------------------------------------------------------
Sub PPP_Disconnect
  ' Start a timer to time how long it takes to disconnect via PPP
  count = Timer (2,Sec,2)
  ' Reset the PPP Close Result, this may still be TRUE from the last close attempt
  PPP_CloseResult = FALSE
  ' Keep looping until the PPP connection is successfully closed
  Do While PPP_CloseResult = FALSE
    ' Try to close the PPP connection
    PPP_CloseResult = PPPClose()
    ' If we have been trying to disconnect for longer than the timeout period, exit the loop
    If Timer(2,sec,4) >= PPP_TIMEOUT Then ExitDo
    ' Delay 1 second between attempts
    Delay(1,1,Sec)
  Loop
   Timer(2,Sec,3) 'Reset timer
  ' Reset the datalogger IP address
  PPP_IPAddress = "0.0.0.0"
EndSub

' --Send_Email-----------------------------
Sub Send_Email
  EMAIL_Result = false 'incase not reset

  Do While EMAIL_Result = false
   
    Call PPP_Connect   ' Call the connect sub routine (usually called based on a condition)
    EMAIL_Result = EMailSend (EMAIL_SERVER,EMAIL_TO,EMAIL_FROM,EMAIL_SUBJECT,EMAIL_MESSAGE,EMAIL_ATTACH_FILE,EMAIL_USER,EMAIL_PASS,EMAIL_Response)
   
    count2 = Timer(3,Sec,0)
    If EMAIL_Result = true OR count2 >= PPP_TIMEOUT Then
      Call PPP_Disconnect 'all done close connection
      Timer(3,Sec,3) 'stop timer 3
      Exit Do
    EndIf
  Loop
  Call PPP_Disconnect 'all done close connection to be sure
  End Sub


BeginProg
  LastFileName = ""
  Call PPP_Disconnect
    
   
  SetStatus("PPPInterface","1")
  SetStatus("PPPIPAddr","0.0.0.0")
  SetStatus("pppUsername","")
  SetStatus("pppPassword","t-d1")
  SetStatus("pppDial","AT+CGDCONT=1,IP,internet.t-d1.de;ATD*99#")
  SetStatus("pppDialResponse","CONNECT")
     
 
  Scan (1,Sec,0,0)
  
  


    'Modem Power Control
    RealTime(rTime)
    Hora=rTime(4) 'Capto la hora de la estacin
    encender=0
    If Hora >= 7 AND Hora <=18 Then encender=1   'We turn on modem at 8:00 and turn off at 19:00
    SW12(encender) 
    

       
    PanelTemp (T_datalogger,250)
    Battery (Bat)
               
    CallTable Tabla
   
    NextScan
   
 SlowSequence
    Scan(1,Min,3,0)
      Delay(1,5,Sec)
     
      EMAIL_MESSAGE = EMAIL_SUBJECT + CHR(13) + "DataLogger time is " + Status.Timestamp 'update time stamp
      EMAIL_MESSAGE = EMAIL_MESSAGE + CHR(13) 'attach cal data
     
      If LastFileName <> "" Then
        EMAIL_ATTACH_FILE = LastFileName
        Call Send_Email
        LastFileName = ""
      EndIf

    NextScan
  EndProg

So my questions are:

  1. is this correct in general
  2. do anyone know how to number the COM ports for the pppInterface command?

Thanks a lot


 


jra Mar 14, 2017 01:29 PM

Have you tried EmailRelay()? You may need to update your CR1000 Operating System. 

OS31 on the downloads section of: https://www.campbellsci.com/cr1000 

Update OS video: https://www.campbellsci.com/videos?video=76 


schraubehaube Mar 15, 2017 01:24 PM

Thanks for your answer. Can you or anybody else tell me how the COM ports are numbered so I can set the right port?


jra Mar 15, 2017 03:37 PM

I'm not sure I understand your question about the COM ports. If you look at the CR1000 wiring panel you'll see COM1 through COM4 labels on the bottom terminal strip. Does that help? 


schraubehaube Mar 16, 2017 06:11 AM

No that is not what I mean. When you have the code:

SetStatus("pppInterface","1")

The number represents the com port you choose for your modem. "1" is the 9pin RS232 port I guess. But when I want to use one of the COM1-4 ports, which number do they have? The manual just says that it is possible, but do not show the numbers for the ports.

I hope this shows better what I want to do.

Thank you


jra Mar 16, 2017 01:21 PM

Generally the PPP Interface is set in the CR1000 through the Device Configuration Utility. Using an instruction in your program to set it may cause the program to recompile which you usually want to avoid. 

If you must set it in the program use "COM1" or "COM2" etc. for those ports. 

I encourage you to use the Device Configuration utility to configure these settings in your datalogger. It is a great tool included in LoggerNet, or you can download it on its own for free. 


schraubehaube Mar 29, 2017 06:14 AM

It seems that it is not right to write 'SetStatus("ppp_interface","COM3")' . I set up the COM port by the Device Configuration Utility and on the CR1000KD it shows '11' for the ppp_interface. So my guess is that you have to write 'SetStatus("ppp_interface","11")' to set the COM3 port in the program.

So once again, is there any documentation for the numbering of the COM ports?

Sometimes, you have to send new programs by remote and setup the logger. Therefore it would be nice to know.

Thank you


schraubehaube Mar 29, 2017 06:14 AM

It seems that it is not right to write 'SetStatus("ppp_interface","COM3")' . I set up the COM port by the Device Configuration Utility and on the CR1000KD it shows '11' for the ppp_interface. So my guess is that you have to write 'SetStatus("ppp_interface","11")' to set the COM3 port in the program.

So once again, is there any documentation for the numbering of the COM ports?

Sometimes, you have to send new programs by remote and setup the logger. Therefore it would be nice to know.

Thank you


jtrauntvein Mar 29, 2017 07:09 PM

The enumeration for com ports has been subject to change in the past.  This is why the compiler defines certain symbols, such as COM3, automatically.  Rather than specifying "COM3" in quotes, you would specify just COM3 (no quotes).  The compiler will substitute this for the appropriate numeric value.


Rageth Mar 29, 2017 08:00 PM

I cxan't say I've tried this in the Device Configiuration Utility but in CRBasic COM ports (and many other features) are integer constants but are preset (as is common practice in Visual Basic) allowing the use of COM3 (no quotes) instead of "11".

Gareth.


schraubehaube Mar 30, 2017 05:21 AM

Oh I see. Yes, it works well without the quotes.

Thanks


schraubehaube Mar 30, 2017 01:33 PM

Do I have to use the SerialOpen command when I use the COM3 for pppInterface?


JDavis Mar 30, 2017 02:47 PM

SerialOpen would just be to serve the purpose of setting the baud rate on Com3. You can change the baud rate on the Comport Settings tab on the datalogger. Then, you wouldn't need SerialOpen in the program.

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