Hi,
Looking at working in some email alerts to my program for CR1000 (OS31), using the emailrelay() function to send an email when the station receives > x mm of rainfall in 24 hours (30 second scan interval). Seems to be executing OK using a modification of the CRBasic example program, the email is triggered, but the ServerResponse comes back as "Not enough data stored", and the result is -2, which I understand is "did not occur when called (-2)". I have let the program run for 2880 records (24 hours, 30 second scans) and still receive the result below. Key parts of the program for this are below.
Public RainSum As Float
Public RainAlertOne As Boolean
Public ServerResponse As String *50
Public Message As String *250
Public EmailSuccess
Const ToAddr="email@email.com"
Const Subject = "Met Station Alert Test"
Const Attach=""
Const CRLF = CHR(13)+CHR(10)
TotalRun (RainSum,1,Rain,2880)
If RainAlertOne = False Then
If RainSum > 5 Then RainAlertOne = True
If RainAlertOne Then
Message = "Hello" + CRLF + CRLF
Message = Message + "This is a test automatic email message from the Strathcona datalogger station"
Message = Message + "An alarm condition has been identified. "
Message = Message + "Greater than 5 mm rainfall received." + CRLF + CRLF + CRLF
Message = Message + "Datalogger time is " + Status.Timestamp
EmailSuccess=EmailRelay (ToAddr,Subject,Message,ServerResponse,Attach)
EndIf
If RainSum > 6 Then RainAlertOne=False
EndIf
Thoughts or advice are welcome and thanks,
SK
I created a program as follows from your code:
Public RainSum As Float
Public RainAlertOne As Boolean
Public ServerResponse As String *100
Public Message As String *250
Public EmailSuccess
Const ToAddr="test@email.com" 'Changed
Const Subject = "Met Station Alert Test"
Const Attach=""
Const CRLF = CHR(13)+CHR(10)
BeginProg
Scan (30,Sec,3,0)
If RainAlertOne = true Then
Message = "Hello" + CRLF + CRLF
Message = Message + "This is a test automatic email message from the Strathcona datalogger station"
Message = Message + "An alarm condition has been identified. "
Message = Message + "Greater than 5 mm rainfall received." + CRLF + CRLF + CRLF
Message = Message + "Datalogger time is " + Status.Timestamp
EmailSuccess=EmailRelay (ToAddr,Subject,Message,ServerResponse,Attach)
RainAlertOne=false
EndIf
NextScan
EndProg
This worked just fine. However, I found two things:
1) the emails were sent but get trapped in Office 365 SPAM filters and quarantined. If you are using a simliar system you may need to add emailrelay@konectgds.com into a whitelist of allowed senders. This is probably not your problem though as I got an email sent success message.
2) I did wonder if you findings might have been triggered by you adding the ",Attach" parameter to the emailrelay command as this is not needed to send a message like this and may perhaps be triggering the logger to act in a different way, i.e. switch to streaming mode. Although it made no difference in my test I suggest you try removing that parameter, just in case.
Thanks for the prompt response. I created a new test program, copied your code with my email address and still received the -2 'not enough data stored' result. Tried removing the 'attach' parameter and sending to a gmail account, same -2 result. Am I missing a setting on the datalogger that allows this to work properly? Using CR1000 and tried on a IPn3Gb and a 4GMini modem, same result.
thanks,
SK
I am connected via an ethernet link out onto the internet. I will change to PPP.
I tried sending a mail to a gmail account and that worked OK so that is not your issue.
I just tried this on a PPP connection (our COM111 modem) and this works too, to gmail.
I think we need to see more of your program.
Hi and thanks. I don't think the issue is the program, it gives me that response when I copy and paste your code into a blank template. However, I can adjust the settings in the TCP/IP -> PPP settings in the Device Config Utility and get a -3 response that the Konect Server will not accept the input. So perhaps it is those settings, can you give advice as to how the PPP (wireless modem) settings should look? I am using this remotely and a full ethernet cable connection won't be an option.
I cannot really advise you on the correct PPP settings for those modems as I have no knowledge of them. You will need to check the recommended setting in the modem manual and help in our device configuraiton utility. Also remember to set the APN in the modem too. (If the modem has an ethernet connection to the modem this is not relevant)
If you get everything right then you should see an IP address assigned to the logger in the status windows of the PPP settings screen.
Once you have an IP address and a link to the internet then the emailrelay should work providing there are no firewall blocks in the network stopping the logger making an outgoing https connection. However, that would normally result in a server response message saying the logger could not connect to the Konect server.
I am also getting the "-2" return from EmailRelay with an associated "not enough data stored" message. I have an NL200 (OS 8) in "PakBus" mode, connected to CR800 (OS 31.02) via RS-232 port, all behind a home router. I can connect to the logger and NL200 from the outside using port 6785 (I have configured a hostname through dyn.com).
NL200: Bridge mode disabled, DHCP disabled, RS232 configuration = "PakBus"
CR800: pretty much standard setup. When I enable PPP mode I get "-3" returned with "Cannot connect to Konect."
I've tried sending to gmail, hotmail, my-phone-number@txt.att.net, and my work email address.
Here is my code:
Public PTemp Public EmailResult Public Subject As String * 30 Public Message As String * 250 Public ServRes As String * 100 Public Switch As Boolean Const ToAddr As String = "my-email@email.com" BeginProg Scan (10,Sec,3,0) PanelTemp (PTemp,_60Hz) NextScan SlowSequence Scan(1,sec,1,0) If Switch Then Subject = "" Message = "Message" EmailResult = EmailRelay(ToAddr, Subject, Message, ServRes) Switch = FALSE EndIf NextScan EndProg
Interesting, when PPP is not enabled, the resulting "-2" value is instant. When PPP is enabled, it takes the entire 75 seconds to get the "-3" result, but the server response "cannot connect to Konect" comes after 30 seconds or so.
I'm guessing that I have not configured my router correctly. I'm forwarding ports 6785 and 6786. Any advice would be much appreciated! Thanks,
Eric
The NL200 needs to be in bridge mode, not PakBus mode. In bridge mode, the NL200 becomes a native Ethernet interface to the datalogger and the datalogger's TCP/IP stack is initialized. EmailRelay(), EmailSend(), HTTPGet, etc. can be used.
In PakBus mode, the NL200 is just another PakBus router in the network. In Pakbus mode the datalogger's TCP/IP stack is not initialized and the TCP/IP instructions listed above will fail.
Page 15 of the NL200 manual has more details about bridge mode (section 7.2).
For PPP mode to work, the datalogger has to be connected to another device that does PPP. For example a Raven XT or RV50 cell modem. The NL200 does not do PPP.
Thanks Gary. In that case, I would have to connect the devices CS-I/O ports instead of RS-232?
Yes, you are correct. The datalogger must be connected to the NL200 via the CS I/O port in order to work in bridge mode.