Error sending email

8 years 11 months ago #2739 by Southpaw
Error sending email was created by Southpaw
I'm attempting to send an email alert when the temperature drops below 58 degrees. In the console, I keep getting the following error message below:

****EMAIL SETUP****
2016-01-06T21:50:05.7690460-06:00 INFO EasyIoTWebinterface EasyIoTControl Module Virtual /Api/EasyIoT/Control/Module/Virtual/N1S0/ControlLevel/57.88
2016-01-06T21:50:05.7734340-06:00 INFO Virtual N1S0 Sensor.Temperature 57.88 -
Virtual N1S0 in program id 16 property Sensor.Temperature value 57.88
2016-01-06T21:50:05.7871060-06:00 ERROR Automation Error processing event in program: Email Test

I've verified that sending the email works (I moved the SendEmail statement outside the if statement to test this). Any idea what I might be doing wrong?

Code for the program follows:

/*
This code is running one time when program is enabled
*/
public void Setup()
{
bool TestCheck;
Console.WriteLine("****EMAIL SETUP****");
EmailHelper.SetupSmtp("This email address is being protected from spambots. You need JavaScript enabled to view it.", "password", "mail.mydomain.net", 25, false);
EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine(m.Domain + " " + m.Address + " in program id "+ Program.ProgramId.ToString()+ " property "+ p.Property + " value " + p.Value);
if ((m.Address == "N1S0") && (p.Property == "Sensor.Temperature") && (Int32.Parse(p.Value) <= 58))
{
TestCheck = EmailHelper.SendEmail("This email address is being protected from spambots. You need JavaScript enabled to view it.", "This email address is being protected from spambots. You need JavaScript enabled to view it.", "Temp: Alert", "TEST");
Console.WriteLine("SendEmail is " + TestCheck);
}
return true;
});
}

public void Run()
{
}

Please Log in or Create an account to join the conversation.

8 years 11 months ago #2756 by Southpaw
Replied by Southpaw on topic Error sending email
I've tracked down the apparent cause of the error, it seems that it's the last relational expression in the if statement that tests the temperature:

&& (Int32.Parse(p.Value) < 58)

If I omit the above test from the code below, the event gets successfully processed and the email message is sent). But without the test it's kind of useless...

Here is my code:

public void Setup()
{
Console.WriteLine("****EMAIL EVENT****");
EmailHelper.SetupSmtp("myemail", "password", "myserver", 25, false);
EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine("Domain is " + m.Domain + " " + m.Address + " in program id "+ Program.ProgramId.ToString()+ " property "+ p.Property + " value " + p.Value);
if ((m.Domain == Domains.VIRTUAL) && (m.Address == "N1S0") && (p.Property == "Sensor.Temperature") && (Int32.Parse(p.Value) < 58))
EmailHelper.SendEmail("myemail", "myemail", "Temp Alert", "TEST");
return true;
});
}

I'm running EasyIoT on a Raspberry Pi, BTW. My C programming skills are tenuous at best. Anyone have any ideas - or is there an alternative way to do the relational test on the p.Value string?

Console messages follow...

****EMAIL EVENT****
2016-01-09T09:59:19.2888960-06:00 INFO EasyIoTWebinterface EasyIoTControl Module Virtual /Api/EasyIoT/Control/Module/Virtual/N1S0/ControlLevel/51.01
2016-01-09T09:59:19.2916840-06:00 INFO Virtual N1S0 Sensor.Temperature 51.01 -
Domain is Virtual N1S0 in program id 17 property Sensor.Temperature value 51.01
2016-01-09T09:59:19.2995440-06:00 ERROR Automation Error processing event in program: Temp Alert

Please Log in or Create an account to join the conversation.

8 years 11 months ago #2760 by Southpaw
Replied by Southpaw on topic Error sending email
Figured out the problem.

The string contains a real number (e.g. 58.22) so Int32.Parse(p.Value) fails because the contents of the string ain't an integer!

The solution is to use Single.Parse(p.Value) to convert the string properly so the temperature value can be tested.

So now when the conditions of the test are met, the email notification gets sent.

Please Log in or Create an account to join the conversation.

Time to create page: 0.201 seconds

Forum latest

  • No posts to display.