X10 Community Forum

📱🖥️PiX10Hub => 🏥Help and Trouble Shooting => 🧞 ⛑HomeGenie Help => Topic started by: mike on February 18, 2019, 08:30:43 PM

Title: Email Script Help
Post by: mike on February 18, 2019, 08:30:43 PM
Can I ask for help here or should I ask in another spot?

sending email when sensor triggers fails - says it is old HG C+ code:

//Parameters
Program.Setup(()=>
{             
    Program.AddInputField("Sensor", "garage", "Sensors to alert on (comma separated)"); //e.g.: garage,window1
    Program.AddInputField("Email.Recipients", "a@a.com", "Email recipients");         //e.g.: a@a.com,b@a.com
}); 

//Code that executes on sensor changes:
When.ModuleParameterChanged((module, parameter)=> {
  if( parameter.Name == "Sensor.Generic")
  {
   if(Program.InputField("Sensor").Value.Contains(module.Instance.Name))
    {     
      Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
      DateTime time = DateTime.Now;
     string format = "HH:mm MMM ddd d";
     
      var openClosed = parameter.DecimalValue == 0 ? "closed":"open";
      var messagetext = module.Instance.Name + " " + openClosed + time.ToString(format);
      //Program.Notify("debug", "sending email " + messagetext); //uncomment for debugging
      var subject = "HomeGenie: Open/Closed" + messagetext;
      var recipients = Program.InputField("Email.Recipients").Value;
      if (recipients != "")
      {
        Program.RunAsyncTask(()=>{
          Net.SendMessage(recipients, subject, messagetext);
        });
      }
   }
  }
  return true;
});


Error says:

CR,4,13: `HomeGenie.Automation.Scripting.ProgramHelper.AddInputField(string, string, string)' is obsolete: `use 'Program.AddOption(<field>, <defaultValue>, <description>, <type>)' instead'
200 /hg/html/pages/control/widgets/homegenie/generic/doorwindow.html [OPEN]
CR,5,13: `HomeGenie.Automation.Scripting.ProgramHelper.AddInputField(string, string, string)' is obsolete: `use 'Program.AddOption(<field>, <defaultValue>, <description>, <type>)' instead'
CR,12,13: `HomeGenie.Automation.Scripting.ProgramHelper.InputField(string)' is obsolete: `use 'Program.Option' instead'
CR,22,32: `HomeGenie.Automation.Scripting.ProgramHelper.InputField(string)' is obsolete: `use 'Program.Option' instead'


I've tried replacing but it is still missing something...   If someone can update this for me I would post it back as exmple for HG?
Title: Re: Email Script Help
Post by: bkenobi on February 18, 2019, 10:29:37 PM
When I have programming questions, I always start with the documentation on the function.  Hopefully the link will work...

https://genielabs.github.io/HomeGenie/api/ape/a00010.html#a77342214dc230ce4eab47ffc4c10bd7f
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 07:18:05 AM
It is always best when going off topic with a Question to start another thread with a topic header that reflects your question. That way your question is less likely to be ignored or over looked. ;)
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 08:49:39 AM
This code is simular to what is included in the release versions of the PiX10Hub (E-mail GarageDoor Notification) I thought I had posted it in the beta section But can't seem to locate it.
The difference is I don't have it watching specific modules and don't add a date stamp to the email.
I get warnings but no errors on compiling.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 09:46:26 AM
If you get a moment, would  you mind posting a copy of your code for email notification?  I can compare the two, study bkenobi's github link on help below, and get a working model maybe...
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 10:24:16 AM
Here is the GarageDoor e-mail sample that is included in the piX10Hub image
Rename to 1004-E-Mail_GarageDoor_Notification.hgx then import to the messaging and social programs section you can then open and edit it  how you see fit.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 11:02:17 AM
Thanks.  I got my version maybe fixed;  when it compiles it says successful now.  but I am not sure how to run it!  haha!  double clicking on it in programs list just opens it to edit it...  maybe I need to find it in the list of modules and add it to a page...
Title: Re: Email Script Help
Post by: bkenobi on February 19, 2019, 11:16:13 AM
You need to set up the app before it will work. You need to define the sensor and email.recipients fields and also make sure the app is enabled (green or yellow icon).  If it has a bright red or dark red icon, the app is not going to work as it has a problem.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 11:37:08 AM
You need to set up the app before it will work. You need to define the sensor and email.recipients fields and also make sure the app is enabled (green or yellow icon).  If it has a bright red or dark red icon, the app is not going to work as it has a problem.

Tuicemens indeed ran (yell went green for 1 second) and HG said missing email recipient...

Mine goes yell to green 0.1sec and no report from HG...

I knew I had to give address but youtube showed entering it by clicking on the program;  that does not work. 

I just found a little 'options' button in the program summary page on Tuicemens...  bingo!  that is where to enter the AddInputField

Mine does not give such an option box for my AddOption    (:

Title: Re: Email Script Help
Post by: mike on February 19, 2019, 11:52:10 AM
why can Tuicemn use 'obsolete' program fields but I cannot??

My program would not compile using the SAME fields he used!@#@!$#GR!

// CR,5,13: `HomeGenie.Automation.Scripting.ProgramHelper.AddInputField(string, string, string)' is obsolete: `use 'Program.AddOption(<field>, <defaultValue>, <description>, <type>)' instead'
// CR,12,13: `HomeGenie.Automation.Scripting.ProgramHelper.InputField(string)' is obsolete: `use 'Program.Option' instead'
// CR,22,32: `HomeGenie.Automation.Scripting.ProgramHelper.InputField(string)' is obsolete: `use 'Program.Option' instead'

bottomline:  his works, mine does not.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 12:11:41 PM
so.  more studying on http://genielabs.github.io/HomeGenie/#/develop/programs

makes me keep my options instead of inputfields, but move the AddOptions to Startup tab in program instead...  add tuicemens widget line...  Now I too get Options choice in programs summary page screen.  I can enter email and which sensors to trigger on... 

doesn't work but at least I am making progress.
Title: Re: Email Script Help
Post by: bkenobi on February 19, 2019, 12:25:33 PM
doesn't work but at least I am making progress.

What does the log say?  What do you mean "doesn't work"?  For the email to succeed, you must have your mono certificates up to date.  If you don't keep it up to date, the email notifications will stop working after a couple months from my experience.  Best practice may be to use a cron event to run update/upgrade regularly so that things keep working.  I have not done this, but it would be something to try.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 01:16:29 PM
doesn't work meant it did nothing.  no yel to green flash.  Now they do that for .2 sec each but no email.  I am frustrated not being able to see the log file;  it is up to 25mb and downloads now in about 2 hours!  Ridiculously slow!

copying log file to my harddrive:  2kb/sec

Frustrating also that the locked up HG windows delays are back.  Have to refresh web browser about every 5th window change...

Wireshark shows little traffic from the pi so it is not something using all the bandwidth.

I am going to delete the log file and see if it starts a new small one...    nope.   copied small log file back to directory, try that..  ya, it downloads it now but it is still empty.  guess one is not allowed to delete the homegenie.log file.  oh well, seems I broke my system;  guess I am going to have to plug in my AHP cm15 again.

meanwhile, perhaps my SD card is dying causing the super slowness?
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 01:56:59 PM
To flush your log file turn it off then after a bit turn it back on.
Also when creating a program if it is messed up and you activate it it will slow things down considerably as it tries to implement things in the code.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 02:00:10 PM
thanks for the log off then back on, I did not think of that.  I am restoring from yesterday's backup...  It may be Kenobi's activity monitor as I imported it but it does not show up anywhere...  if my restore from yesterday gets me speeded up again, I will try once more to build email programs...   thanks
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 05:53:07 PM
I'm not sure you want a email for every open close event, maybe just an open event?
I've been playing with this code a bit as I feel it may be of use for some things and expanded on.
I can get this to send emails to any device in HG that has the option selected, including Door/Window sensors.
However I get 3 or 4 emails at a time so I still need to tweak it a bit.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 06:51:00 PM
I do not want it to email every door open or close;  I have a test DS10 on my desktop to use as tester.  When finished it will be triggered by TAMPER (I think this reports quicker than door open & causes SC1200 to trigger alarm even if activity monitor does not show door open.  Anyway, it will be triggered by TAMPER *AND* ARMED.
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 07:10:39 PM
OK, I understand but I'm not sure the Tamper reports quicker then an open.
However I've never played with that enough to be sure.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 07:56:45 PM
How does one know if email is functioning in HG?  my log shows ZERO comment with the word email, my email address, my smtp server, anything!  yet under programs-social there is the email thing with green light on it.

I do not think it is working
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 08:06:01 PM
Does my program work and send a email if you enter the info?
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 08:10:42 PM
Since your using a pre-release PiX10Hub version and if you haven't done a update/upgrade when installed or even since installing that beta, that could be your issue.
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 08:15:11 PM
IIRC updating to stable.37 a week ago did update and upgrade as part of it...   

I just found both yours and my email programs red circle;  they need to be disabled and then enabled again!  then they went yellow!  and i am back to them going green for .2 sec when widget pushed.  No email tho and no code in the log.

but but but!  THANKS!  since it slowed down today I replaced my SD card with last backup...  it is old stable v1 572!!!

so tomorrow I will update to the new version put up tonight!  that will get upgrade/update again.

gosh, so easy to go backwards!
Title: Re: Email Script Help
Post by: mike on February 19, 2019, 08:17:52 PM
I also just found that both your and my startup code in the hgx is gone!  probably an old HG version bug... 
Title: Re: Email Script Help
Post by: Tuicemen on February 19, 2019, 08:18:35 PM
IIRC updating to stable.37 a week ago did update and upgrade as part of it...   
But your still using a beta PiX10Hub image
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 10:18:08 AM
IIRC updating to stable.37 a week ago did update and upgrade as part of it...   
But your still using a beta PiX10Hub image

But other than you changing directories around, how is my older beginning image not as good as what you promote today?  I believe we both use the same programs with the same updates?
Title: Re: Email Script Help
Post by: Tuicemen on February 20, 2019, 10:33:53 AM
There were other things done with the initial boot besides moving directories for HG.
Do you know what beta or RC test your running?
Beta versions usually contain bugs which can affect other things.
It is not good practice to try and run a Beta build for regular use.
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 10:49:58 AM
I agree running beta programs when newer stable versions are available is not wise.  But I do not believe I am running any beta programs.  My HG is upto date with latest Gene build.  Doing his automatic update in HG maintenance page includes update and upgrade so all raspberry pi programs are also updated at the same time.  My HAbridge is a non beta working version that does its job flawlessly so I see no reason to change its version.  You added the start screen menu when opening a putty window;  that does not bother me as I know how to tab to finish and close it when I want to talk to the pi.

What am I missing?
Title: Re: Email Script Help
Post by: Tuicemen on February 20, 2019, 11:03:23 AM
Sound like your running Beta 2.
If you feel the image is work for you, I 'll not try to explain all the image differences.
However if programs are not located where the author designated them to be many things possibly will not work as coded.
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 11:04:27 AM
ah, ok. 
Title: Re: Email Script Help
Post by: bkenobi on February 20, 2019, 11:23:23 AM
the update/upgrade has nothing to do with a HG update.  You need to run an ssh session and run the update/upgrade commands.  HG may be updated but the reason email stops working is the certificates mono uses becoming out of date.  Update/upgrade will resolve this.  It will happen around every 2-3 months.
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 11:28:41 AM
Update:  I thought the HG program update ran generic update/upgrade, but watching closely this time I see it did not.  So issue is likely as Bkenobi says.  I wrote the following before remembering his comment on mono certificate comment the other day, and now reminder again (thank you).  I will do that next.

--------------------

So email not sending but both your program and mine are commanding HG to send.  I will try a different email to send from than gmail next as I cannot understand what the 'stack trace' error is. 

Log shows:

{"Title":"E-Mail Notification","Message":"ERROR: Notification **NOT** sent."}

and specifically:   

2019-02-20 11:12:34.9637 Trace SendMessage: called for recipients myemail.com         
2019-02-20 11:12:34.9701 Trace SendMessage: getting smtpSyncLock         
2019-02-20 11:12:34.9747 Trace SendMessage: got smtpSyncLock         
2019-02-20 11:12:35.2938 Trace SendMessage: going to send email System.Net.Mail.MailMessage using mailService 'smtp.gmail.com', port '465', credentials System.Net.NetworkCredential, using SSL = True         
 
then later:

2019-02-20 11:12:47.2021 Error System.Net.Mail.SmtpException: Message could not be sent. ---> System.IO.IOException: Connection closed            
  at System.Net.Mail.SmtpClient.Read () [0x000bd] in <8a8abae728c244359683ef777047ab9e>:0             
  at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message) [0x00000] in <8a8abae728c244359683ef777047ab9e>:0             
  at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message) [0x00050] in <8a8abae728c244359683ef777047ab9e>:0             
  at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x00084] in <8a8abae728c244359683ef777047ab9e>:0             
   --- End of inner exception stack trace ---            
  at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x0009f] in <8a8abae728c244359683ef777047ab9e>:0             
  at HomeGenie.Automation.Scripting.NetHelper.SendMessage (System.String from, System.String recipients, System.String subject, System.String messageText) [0x003f1] in <b08d74f9b7fb4c85b616d2d9beee8275>:0             
2019-02-20 11:12:47.4257 Error HomeAutomation.HomeGenie.Automation   NetHelper   Message could not be sent.   Exception.StackTrace     at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x0009f] in <8a8abae728c244359683ef777047ab9e>:0
  at HomeGenie.Automation.Scripting.NetHelper.SendMessage (System.String from, System.String recipients, System.String subject, System.String messageText) [0x003f1] in <b08d74f9b7fb4c85b616d2d9beee8275>:0             
2019-02-20 11:12:47.4601 Trace SendMessage: disposing smtpClient            





Title: Re: Email Script Help
Post by: mike on February 20, 2019, 11:52:31 AM
OK, I understand but I'm not sure the Tamper reports quicker then an open.
However I've never played with that enough to be sure.

Guess you are right;  I just know with my trest DS10 I can open and close quickly and HG module shows tamper right away and then may not ever show OPEN because I closed it quickly...  But the log proved me wrong;  I just checked and it shows tamper AND also OPEN on adjacent lines.  So good to know that even a loose wire on the reed switch terminal that comes and goes should be seen by HG.
Title: Re: Email Script Help
Post by: Tuicemen on February 20, 2019, 11:55:51 AM
Modified you r log file to Hide your Email Address.
I thought they were the same , Good to know
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 12:01:28 PM
thanks.   update did not fix sending email.  1/2 way thru upgrade and it did not fix sending either...  will try again in an hour or so when it is done with upgrade.  If no go, I will change to another non gmail account to send from. 
Title: Re: Email Script Help
Post by: bkenobi on February 20, 2019, 02:06:33 PM
I email through yahoo but I have used gmail at some point.  Mine is not working again so I need to run update/upgrade myself.  As I said before, this should really be added to a cron event IMO.  I haven't done it, but maybe I'll get to it some day.
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 02:11:54 PM
I finished update and upgrade.  Still no email sent - says stack error... 

Tried changing to my own server smtp and it does same thing.

tried a reboot of pi in case that was required, no change.

So the HGx programs WORK, they call:

2019-02-20 13:22:54.4055 Trace SendMessage: going to send email System.Net.Mail.MailMessage using mailService 'smtp.gmail.com', port '465', credentials System.Net.NetworkCredential, using SSL = True

fail on this:

2019-02-20 13:23:05.4538 Error System.Net.Mail.SmtpException: Message could not be sent. ---> System.IO.IOException: Connection closed
  at System.Net.Mail.SmtpClient.Read () [0x000bd] in <8a8abae728c244359683ef777047ab9e>:0
  at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message) [0x00000] in <8a8abae728c244359683ef777047ab9e>:0
  at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message) [0x00050] in <8a8abae728c244359683ef777047ab9e>:0
  at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x00084] in <8a8abae728c244359683ef777047ab9e>:0
   --- End of inner exception stack trace ---

and report this:    2019-02-20 13:23:05.4500 Trace SendMessage: error sending email {0}
Title: Re: Email Script Help
Post by: Tuicemen on February 20, 2019, 02:26:16 PM
I email through yahoo but I have used gmail at some point.  Mine is not working again so I need to run update/upgrade myself.  As I said before, this should really be added to a cron event IMO.  I haven't done it, but maybe I'll get to it some day.
I use Hotmail myself and the weird thing is I've not did a Update/Upgrade since Sept or later and am still getting email notifications from my off grid place ::) :'  So I should expect a failure soon :o I thought moving up from Mono 4 fixed that issue. ???
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 02:35:05 PM
I will try a yahoo account next, but I am thinking the issue is something else...  the error seems to be more HG can't write the variable into its email routine?

Error System.Net.Mail.SmtpException: Message could not be sent. ---> System.ArgumentException: Stream was not writable.
Title: Re: Email Script Help
Post by: Tuicemen on February 20, 2019, 02:49:34 PM
Yep that will do it.
Title: Re: Email Script Help
Post by: Tuicemen on February 20, 2019, 03:26:07 PM
This thread has inspired me to work on a Smart_E-mailer which once done should make a lot of my email Alert Programs obsolete. ::) :'  Currently it works for most modules in HG I have. However I don't have the Arm/Disarm or Night sends coded as yet as I'm still playing with those implementations.  I'm thinking of removing the send when Disarm option and if Armed is selected it only sends then otherwise always unless night is checked. It also only emails when the configured module status value changes to 1

Hope I don't confuse myself with all the ifs and elses  rofl
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 03:32:52 PM
wow!  And here I am with another 7 hours into trying to get basic emailing to run on HG!  I suppose if you accomplish this thing I will have to start over with your latest image that includes it.  I just shudder at the thought of going to a new image SD card since I KNOW HAbridge will be broken again and require another 20 hours of fiddling to get it to run again! 
Title: Re: Email Script Help
Post by: Tuicemen on February 20, 2019, 03:42:14 PM
You can always backup your settings of HA-Bridge configuration and devices and copy them to your PC to later put back on the PI. That's what backups are for, to save hours of fiddling if a re-build is needed.
Actually you could copy the whole HA-Bridge folder to your PC then move it back. However that would require some File attribute changes I believe.


I have to take a break from the emailer. :( it didn't take long for the Ifs & Elses to make me dizzy  rofl
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 03:46:38 PM
I have TWO email writing programs, mine & yours...   I did NOT update yours - it is identical to what you sent me, using the obsolete

Program.AddInputField("Email.Recipients", "", "Comma separated list of recipients e-mails that will get a test e-mail");
Program.AddInputField("Email.Message", "HomeGenie Notification.", "E-mail message");
Program.AddInputField("Email.Subject", "HomeGenie Alert Warning", "E-mail subject");
var subject = Program.InputField("Email.Subject").Value;
var recipients = Program.InputField("Email.Recipients").Value;
var messageText = Program.InputField("Email.Message").Value;


I think this is why you get the error when compiling but it seems to still work.

I DID update mine to the new commands for above

Program.AddOption("Sensor", "garage", "Sensors to alert on (comma separated)", "text")
Program.AddOption("Email.Recipients", "a@a.com", "Email recipients", "text")
if(Program.Option("Sensor").Value.Contains(module.Instance.Name))
var recipients = Program.Option("Email.Recipients").Value
Title: Re: Email Script Help
Post by: mike on February 20, 2019, 03:51:16 PM
dizzy, ha! 

Ya, I am good at using WinSCP & putty to CHOWN pi:pi directory -R!  I can copy and put back like that;  but IIRC the last time I did that it did not work - seems the SD card name changed from mine to yours and THAT stopped it in its tracks...  So I assume if I start over I will find some similar issue to stop me...

I make HG backups like 20 times per day when working on stuff like this...   Think I am at 20 so far today!

I am going to try sending this next, too long today so probably tomorrow:

from:
bool SendMessage   (   string    recipients,
string    subject,
string    messageText
)      
Sends an E-Mail.

Returns
true, if message was sent, false otherwise.
Parameters
recipients   Message recipients.
subject   Message subject.
messageText   Message text.

I will change one of the sends from:

 Net.SendMessage(recipients, subject, messagetext)

to:

 Net.SendMessage(me@my.com, test subject, hi Bob)

If that doesn't work then:

 Net.SendMessage("me@my.com", "test subject", "hi Bob")

Title: Re: Email Script Help
Post by: Tuicemen on February 20, 2019, 06:05:45 PM
I don't get errors just warnings, there is a difference. ;)
I believe the HG code hasn't been fully updated to use the new suggested methods. ::)
If you change the Program.AddInputField to Program.AddOption in the Start up code but leave the Program.AddInputField in the Program code the emails still get sent. I can use either method. :o
The error warnings all point to the Startup code.

I have no Program.AddInputField entry anywhere in my new code but I still get 6 warnings about outdated code even though  what it points to uses the new suggested method. ::) :' I can change the code to use a Program.AddInputField in the Program code but then I still get 6 errors not 7  B:(.
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 09:47:49 AM
So frustrating having to use experimentation to find out how things work in HG!  I want a simple program with a single C+ line:

Net.SendMessage("cc@cc.com", "test subject", "hi Bob");

I can make the program, compile it (not sure that is required when there is a save button on bottom right that seems to do the same thing), but go to a group and try to add it as a module and it does not exist!   I have tried all kind of experminieting but cannot figure out why some programs show up (in apparent random places to boot) in the add module list and others do not.

What is the secret to adding a button to test this program?
Title: Re: Email Script Help
Post by: Tuicemen on February 21, 2019, 09:52:05 AM
This should help explain some things
https://genielabs.github.io/HomeGenie/#/develop/programs
The documentation is out there, it is just knowing where to look, which can be frustrating B:(
Title: Re: Email Script Help
Post by: Tuicemen on February 21, 2019, 09:54:10 AM
Also just because you compile it or save it doesn't mean it is activated so you have to do that in some cases. ::) :'
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 09:55:48 AM
thanks.  that link does not work for me.  I like

https://genielabs.github.io/HomeGenie/api/ape/index.html

But its search feature cannot find the commands so it is frustrating time waster to search each are until I find the one I want explained...

Not sure why   Program.UseWidget("homegenie/generic/program");   did not show the module in the add module list before but I just tried it again and it now shows...  so I can test more.
Title: Re: Email Script Help
Post by: Tuicemen on February 21, 2019, 10:01:19 AM
Not sure why   Program.UseWidget("homegenie/generic/program");   did not show the module in the add module list before but I just tried it again and it now shows...  so I can test more.
Ya I found HG slow to add new modules to the list but running this on a Zero W that can be expected I guess. ::) :'
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 10:11:49 AM
My peck and test method of trying to make something i know little about work is beginning to make me believe the command

Net.SendMessage("cc@cc.com", "test subject", "HiBob messageText")

does NOT actually send an email.  My log shows this program is running but shows nothing of email sending.  So the only one actually trying to send is your version;  I assume the actual send is this that I do not understand as I cannot find docs on the words:

 Program.RunAsyncTask(() => {
    byte[] img;
    for (int x=0; x<3; x++) {
       
     
        Pause(1);
    }

Do you know if there is a simple single line C+ code that SENDS an email?
Title: Re: Email Script Help
Post by: Tuicemen on February 21, 2019, 10:27:01 AM
The line you use is what I use
Net.SendMessage( "YOUR EMAIL ADDRESS", "YOUR SUBJECT", "YOUR Message" );

HomeGenie uses C# not C+ though simular finding info may be difficult if searching the wrong programing language.
HomeGenie can also use Javascript - Jint, Python - IronPython, Ruby - IronRuby so if your more familiar with one of those try them.
Title: Re: Email Script Help
Post by: bkenobi on February 21, 2019, 11:20:12 AM
Just to make sure you completed all the steps, did you set up certificates for your specific email host?

I don't have my install script in front of me, but part of the setup process is getting certificates set up.  I believe the line you need to verify is:

Code: [Select]
certmgr -ssl smtps://smtp.gmail.com:465
I know I've posted the script somewhere, but don't remember which forums.  It's at home and on my flash drive (which is at home).  The command above was found by asking google about "raspberry mono certificate gmail" in case you need more info.  My script also has a line that can be used to test if the certificates are correctly installed, but I don't recall what that command is.  Google should be able to help.
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 12:00:08 PM
I am beginning to see that one cannot send emails from HG without also doing more background stuff with this mono thing...

I found:
https://www.mono-project.com/docs/faq/security/

It is heavy into stuff it appears must be manually done before any email can ever be sent! 

Beknobi, your line  certmgr -ssl smtps://smtp.gmail.com:465 is similar to what is reported in the mono security write up...  when I type it into putty it just makes my pi mad: it sits there and does nothing until I 'end' it with ctl-x

I have been researching email and pi and HG for a couple hours.  I see tidbits here and there about the certificate issues and such, but nowhere yet any definitive 'fix' to make HG send an email, with or without SSL.
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 01:09:10 PM
Tuiceman, using my last backup SD I just found that Habridge indeed broke again.  I will have to search for how I fixed it before...  something to do with the SD card name changing IIRC.  I may just put my SD card back in that worked last week and go from there...
Title: Re: Email Script Help
Post by: bkenobi on February 21, 2019, 02:09:38 PM
I am beginning to see that one cannot send emails from HG without also doing more background stuff with this mono thing...

Correct.  I don't have an approach that is fully hands off setup and will work indefinitely without intervention.  As a result, I have notifications working less than they don't work.  I don't have anything set up to notify other than for loss of power which only happens 2-3 times a year and I generally already know about it.
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 03:14:37 PM
I put back my working SD card and got HAbridge back.  I updated and upgraded it.  Gotta remember to make a new backup SD card...

Bkenobi, it seems I read there is a way to make the certificate work forever in the doc:

https://www.mono-project.com/docs/faq/security/

One of the 4 'ways to fix this certificate issue.'  But I won't swear to it. 

I am putting my email from HG on the sideburner for now;  not enough time in the day to experiment pecking at the keyboard on a topic I don't grasp enough. 

If you would not mind reposting for this dumby here your step by step you have at home sometime, I would be very greatful.  I see a HG scheduler crone event to remind to do that thing again in 3 months (* * * 3 *).  If it is definable in a C-something code, then it might even be automatic.   :)

thanks.
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 03:51:22 PM
Meanwhile I encourage you Tuicemen to continue on your great idea of adding email capability to security devices!  Thank you!
Title: Re: Email Script Help
Post by: Tuicemen on February 21, 2019, 04:29:19 PM
Mike I'm still plugging away at it.
right now it is ignoring my conditions, B:( I'll soon be dizzy again today. rofl
Title: Re: Email Script Help
Post by: Tuicemen on February 21, 2019, 04:51:29 PM
OK, got everything but the Email when security is Disarmed and a module changes to On or status 1
I'm not sure if that is needed but I'll attempt to add it. ;)
Title: Re: Email Script Help
Post by: Tuicemen on February 21, 2019, 05:02:07 PM
Wow! That was simple enough, and no dizzy spell  rofl.
Now to test everything during night and day. ::) :'
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 07:38:45 PM
You Are amazing!   I will learn from this and challenge you more often!   :)
Title: Re: Email Script Help
Post by: mike on February 21, 2019, 07:39:43 PM
Do you think if I download your latest Sd image it would send email for me too?
Title: Re: Email Script Help
Post by: Tuicemen on February 21, 2019, 07:51:09 PM
You Are amazing!   I will learn from this and challenge you more often!   :)
rofl Well I finished testing and all works as I designed (may not be how others wish it to perform) now to clean and polish up the code.
Do you think if I download your latest Sd image it would send email for me too?
The latest image may fix your issue as HG is where Gene designed it to be and it is locked to a mono version which is suppose to solve the email issues bkenobi references.
However since the consensus was to remove HA-Bridge from the image that is no longer on it, but you should have no problem installing it following the set by step I posted here  http://forums.x10.com/index.php?topic=30440.msg175106#msg175106
 you will need to be sure Homegenie is not on port 80 prior to installing HA-Bridge
Title: Re: Email Script Help
Post by: mike on February 22, 2019, 08:58:02 AM
I'm pretty sure my mono is the same one from your image so I doubt that is the issue.

 mono --version
Mono JIT compiler version 5.4.0.201 (tarball Fri Oct 13 22:19:03 UTC 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,vfp+hard
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen (concurrent by default)
Title: Re: Email Script Help
Post by: Tuicemen on February 22, 2019, 09:35:23 AM
yep, I wasn't sure you stuck with it or were on the latest build.

I posted my Smart_E-mailer program as I got it all cleaned up and tested with different devices.
http://forums.x10.com/index.php?topic=30881.0
 >!
Title: Re: Email Script Help
Post by: mike on February 22, 2019, 03:30:36 PM
Just to make sure you completed all the steps, did you set up certificates for your specific email host?

I don't have my install script in front of me, but part of the setup process is getting certificates set up.  I believe the line you need to verify is:

Code: [Select]
certmgr -ssl smtps://smtp.gmail.com:465
I know I've posted the script somewhere, but don't remember which forums.  It's at home and on my flash drive (which is at home).  The command above was found by asking google about "raspberry mono certificate gmail" in case you need more info.  My script also has a line that can be used to test if the certificates are correctly installed, but I don't recall what that command is.  Google should be able to help.

If you could find your post on this and post it here I would be forever grateful!
Title: Re: Email Script Help
Post by: bkenobi on February 22, 2019, 05:00:45 PM
Was sick last night and spent a few hours shivering under a blanket.  Will try to get to it this weekend.
Title: Re: Email Script Help
Post by: mike on February 22, 2019, 07:42:18 PM
Hey bkenobi get well first!   I can wait!  I hear the flu is going around strong this year!  Stay warm and get better!