Sending Email from Your Datalogger Just Got Easier!

von Dana Worley | Aktualisiert: 01/25/2017 | Kommentare: 10

Stichwörter

CRBasic EmailSend()

Blog Themen


Suchen Sie im Blog


Blog abonieren

Erhalten Sie eine Email wenn ein neuer Artikel veröffentlicht wird. Wählen Sie die Themen die Sie interessieren.


Geben Sie Ihre Emailadresse ein:



Artikel vorschlagen

Gibt es ein Thema zu dem Sie mehr erfahren möchten?

Leave this field empty

datalogger sending email

Have you had problems finding an SMTP server to use to send emails from your datalogger? Are compatibility issues causing you to look for a work-around? Keep reading for a solution that may be just what you need.

Some Background

In 2006, we added the ability in our operating systems for IP-enabled dataloggers to send emails using a function called EmailSend() This function opened up a whole new world, giving our dataloggers the ability to issue notifications about the status of a station, transfer data files as attachments, or alert someone about an alarm condition.

Over the years we have found that users often have a problem with finding an SMTP server to use. Many customers rely on publicly available free services such as Gmail or Yahoo, but increasingly, these services have added restrictions that prohibit dataloggers from sending emails. Sometimes the fix requires digging through settings to change in the free account, sometimes the fix requires bribing the “IT guy” to make network changes, and sometimes, it can’t be fixed at all.

Our Solution: EmailRelay() Function

To provide a better experience for customers who need to send emails from their dataloggers, we introduced the EmailRelay() function with the following datalogger operating systems:

In its simplest form, EmailRelay() has only four parameters:

EmailRelay (ToAddr,Subject,Message,ServerResponse)

The function has additional parameters that let you send attachments or send data directly from a data table, without first writing the data to a file. (We refer to this as “streaming.”)

With EmailRelay() you can send up to 30 emails each day, and each message can be up to 1 M in size (size includes the message overhead, the message itself, and any attachments). The message count is reset on a daily basis.

Tip: When creating and testing a program using EmailRelay(), make sure to use a manual trigger to run the EmailRelay() function, and to set that trigger back to False after execution of the function. This ensures you won’t exceed the daily email limit during the first test run of your program.

Example Program

Here's a quick test program to get you started. Just change the constant ToAddr to send an email from your datalogger to yourself.


‘declare program variables and constants
Const ToAddr="YourEmail@yourcompany.com"
Const Subject="Email Message Test"
Const CRLF = CHR(13)+CHR(10)
 
Public Batt
Public AlarmTrigger As Boolean
Public Message As String * 250
Public EmailSuccess
Public ServerResponse As String * 50
 
BeginProg
	Scan (1,Sec,3,0)
		Battery (Batt)
	NextScan
 
	SlowSequence
	Scan(1,sec,1,0)
 
		'Set Alarm Trigger Manually
		If AlarmTrigger Then
			Message = "Hello!" + CRLF + CRLF
			Message = Message + "This is an automatic email message from your friendly datalogger named  " + Status.StationName + ". "
			Message = Message + "An alarm condition has been triggered. "
			Message = Message + "The battery voltage is " + Batt + " volts." + CRLF + CRLF + CRLF
			Message = Message + "Datalogger time is " + Status.Timestamp
			EmailSuccess=EmailRelay (ToAddr,Subject,Message,ServerResponse)
			AlarmTrigger=False
		EndIf
 
		Erase (Message)'Erase the message after sending 
 
	NextScan
EndProg

Tip: Run EmailRelay() in a SlowSequence, as shown above, to avoid the delay of critical measurements and other important tasks executed in the main scan. 

The From Address of the email sent by the datalogger is emailrelay@konectgds.com. Konect GDS is Campbell Scientific's cloud-hosted data collection platform. It is also where the Campbell Scientific email server is hosted.

EmailSend() versus EmailRelay()

EmailSend() is still included in the datalogger operating systems. If you are already using the EmailSend() function and it works well for you, there is no need to change. However, if you have struggled with compatibility with your existing SMTP server, give this new function a try. We hope you will find it easier to use.

If you have comments about this new function in the datalogger operating systems, leave us a note below!


Artikel teilen



Über den Author

dana worley Dana Worley joined Campbell Scientific, Inc., as an Applications Engineer in 1997. During her career she has provided customer support and technical training, developed on-line and written documentation, managed a software test and support group, and managed a software product line. Dana currently works as a Project Manager in the Research & Development department. Outside of work, Dana enjoys hiking, biking, travelling, and photography. She is also an accomplished glass artist with expertise in glass fusing.

Alle Artikel von diesem Author anzeigen.


Kommentare

ganzlin | 01/25/2017 at 11:41 AM

Thanks for this update. I am on OS 31 on my CR3000s and up to date with the patch on LoggerNet to 4.4.2 but still don't see EmailRelay in the list of commands in CRBasic editor. Also, could you explain what the command CRLF does and an example of a logical operator to trigger an email alert? Thanks

jra | 01/25/2017 at 12:14 PM

Hi ganzlin,

When you download an OS from our web site you need to run the executable to update your CRBasic instructions and Help files. Once you do that you will see EmailRelay() in the instruction list. 

CRLF is a carriage return line feed. Back in the old days of typewriters, when the typing mechanism (a carriage) got to the end of a line you had to return it and advance the paper (line feed). Const CRLF = CHR(13)+CHR(10) does that digitally now. 

Here's an article on different ways to use time to trigger an action. 

Hope that helps,

Janet

ganzlin | 01/25/2017 at 01:15 PM

Thank you that did it!

francesco.sabatini | 02/01/2017 at 08:48 AM

Dear Dana, Thank you for implementing this new function, we found it very useful. We would like to know if there is a limited number of email addresses that can be inserted in the variable "ToAddr" as for your example. Actually we are inserting 4 email adrresses and yesterday it sent the messages only to one of the adddress out 4.

On which basis you calculate the threshold of 30 email per day: by email address or by data logger serial number? There are some filter on the recipients?

Thank you again for your support, ciao

Francesco and Alessandro

Dana | 02/01/2017 at 08:56 AM

Hello Francesco and Alessandro,

The limit of 30 emails per day is based on the datalogger. If you send one email to 5 people, you have used up only one of your emails for the day.

With the EmailRelay function, you can send to multiple email addresses at once. My first guess, without testing, is that the "ToAddr" would need to be a String variable rather than a Constant. I'm currently not at my desk to test, but I will double-check. You can also give it a go and see if you have success. 

I'm glad you're finding this new function useful. I think it is a great way to simplify sending email from a Campbell datalogger!

Kind regards, Dana

francesco.sabatini | 02/01/2017 at 11:44 PM

Dear Dana, 

thank you so much for your real time reply, much appreciated.

Actually in the present program "ToAddr" has been define as follows:

Const ToAddr = "alessandro.materassi@cnr.it,f.sabatini@ibimet.cnr.it,....+2 recipients"

So we will try to set it as a string variable.

Our best regards from Italy, ciao

Francesco & Alessandro

Memrys | 10/10/2018 at 09:46 AM

Hello,

I cannot seem to find a working version of EmailRelay through any example. Operating on a cr1000 with Std.32.03. Using the above example I obtain a -2 response. Even through CRBasic help and making a few changes does not seem to produce a result. Connection is through a RV50 modem using CSI template.

JDavis | 10/10/2018 at 10:57 AM

The -2 response code means you don't have enough data to send yet. Just wait, and it should work.

JFE2011 | 11/12/2018 at 09:59 AM

Hi, 

I have a situation where I want to send an email with data table as an attachment, but only once a week. My understanding is that the slowest a scan sequence can run is once a day. Is there a way of scheduling emailrelay to run once a week?

Thanks

Joel

Dana | 11/12/2018 at 10:25 AM

Hello Joel,

One solution is to trigger EmailRelay based on the result of the RealTime instruction. This is from the help in CRBasic:

The RealTime instruction loads the destination array (Dest argument) with the current time values in the following order: (1) year, (2) month, (3) day of month, (4) hour of day, (5) minutes, (6) seconds, (7) microseconds, (8) day of week (1-7; Sunday = 1), and (9) day of year. The destination array must be dimensioned to 9. The time returned is the time of the datalogger's clock at the beginning of the scan in which the RealTime instruction occurs.

As an example, you could use

      If RealTime(8) = 1 and RealTime(4) = 12

To trigger the event to happen every Sunday at noon.

Best, Dana

Please log in or register to comment.