Dangerous Prototypes

Other projects => Past projects => Web platform => Topic started by: mmmike on October 22, 2012, 08:34:08 pm

Title: Microchip's SMTPDemo ??
Post by: mmmike on October 22, 2012, 08:34:08 pm
Hi all. 

I'm hoping someone can help me with getting the WebPlatform to email me automatically on an event (button push).

I've been working with the SMTPDemo.c file, but haven't had any success yet.

I have successfully used the email demo, sending emails through gmail's smtp service with SSL.

I think the problem might be incorporating SSL into the smtpdemo.  I've added the line.........

SMTPClient.UseSSL = TRUE;  into the parameters, no luck. 

I also may not be implementing the function correctly.  Anyone have any ideas??

Thanks to everyone here,  I wouldn't have gotten as far as I have without the information here. I'm not a pro and much of this is new to me.  C is not a favorite of mine, but I'm learning , my mcu programming has been mostly assembly language upto this point.  I'm working on a home automation setup and I can control relays, get the temperature and light level etc. This auto-email thing has me stumped right now.

Thanks in advance. :) ,

noob
Title: Re: Microchip's SMTPDemo ??
Post by: Thorontir on October 23, 2012, 08:58:19 am
If I remember correctly, at least in Europe you had to purchase (At a ridiculous price, since it is something that was intended to be free) SSL libraries. Something to do with importing some kinds of cryptographic tecnology.

The demo was very simple (I made it work some years ago, with a PIC18). Just take another look at config (Server, username, password...)

And I think that in TCPCongig.h you need to add a global flag for SSL (Not just SSL for SMTP, I mean "general SSL client libraries").

Sorry for not being more specific, as I said, made it work a lot of time ago, and discarded it... So I remeber very few.

Hope it helps.
Title: Re: Microchip's SMTPDemo ??
Post by: dpropicweb on October 23, 2012, 09:53:56 am
[quote author="mmmike"]
I've been working with the SMTPDemo.c file, but haven't had any success yet.
[/quote]

Quote
I have successfully used the email demo, sending emails through gmail's smtp service with SSL.

Which is it? :)

The Microchip demo for the web platform included an SMTP demo that works without SSL. SSL required an additional library which had to be purchased from Microchip on CD and, not having the need, I didn't bother.
Title: Re: Microchip's SMTPDemo ??
Post by: mmmike on October 23, 2012, 02:29:09 pm
[quote author="dpropicweb"][quote author="mmmike"]
I've been working with the SMTPDemo.c file, but haven't had any success yet.
[/quote]

Quote
I have successfully used the email demo, sending emails through gmail's smtp service with SSL.

Which is it? :)

The Microchip demo for the web platform included an SMTP demo that works without SSL. SSL required an additional library which had to be purchased from Microchip on CD and, not having the need, I didn't bother.[/quote]

Hi gentlemen, thanks for the replies.

As far as the SSL goes,  I have the encryption libraries and have used them successfully with the "email demo".

The "SMTPDemo" is a different thing all together.  It does not work through a webpage, it uses real world button pushes. I'm sure I have all of the parameters entered correctly and the proper bits un-commented.

After gazing at code for a while last night, I do not think my issue is with the SSL.  I'm leaning more toward a lack of understanding of C language on my part.  Maybe I am not implementing the function correctly.  It should be waiting in the background looking for button activation.  Here is the code from Microchip's SMTPDemo.c, unaltered.  I am using the first part, which is supposed to send a simple message with no attachments.

eta:  Sorry, I couldn't attach the code, the forum thinks this was spam.  Just look at the file if you have the microchip solutions stuff
Title: Re: Microchip's SMTPDemo ??
Post by: dpropicweb on October 23, 2012, 03:43:12 pm
Ok. Well, I don't have the current MCHP solutions library to hand, but I suspect you will need to change the hardware config for the button in that demo so that it matches the web platform hardware (if you haven't already).
Title: Re: Microchip's SMTPDemo ??
Post by: Thorontir on October 23, 2012, 03:45:34 pm
That's the one I was talking: It worked, at least in previous versions.

You just need to be sure the function is called in your main function. And trigger the email sending, with a button in the demo (I changed that to a variable when I was trying it in order to send a mail every XX seconds). Anyway, you just need to be sure that the function is called in your main loop, and that the conditions for sending the mail are present. It works out of the box (Or at least, as I said, used to work...)

You can paste the code in the message, using the "code" tags:
Code: [Select]
[code]code that you want to show[/code]
Title: Re: Microchip's SMTPDemo ??
Post by: mmmike on October 24, 2012, 10:49:50 am
Thanks for the tips.  I should have a little time today to go through it again. 

I'll let you know what I find.
Title: Re: Microchip's SMTPDemo ??
Post by: mmmike on October 26, 2012, 03:11:11 pm
Still no luck.  I wish I knew exactly where it is failing.  I'll keep poking it :)
Title: Re: Microchip's SMTPDemo ??
Post by: mmmike on November 04, 2012, 07:33:26 pm
SOLVED!  WOOHOO!

After stepping away from this for a while, I took a fresh look at it yesterday.

I was going over the Microchip demos that used this function and found the line:

void SMTPDemo(void);

in the MAINDemo.h file.  I had not previously thought of looking there because the webPlatform version of the demo does not really use this file for anything.

So now that it is working, it's on to modifying it for my purposes.

One of the things I am going to do is install a float switch by my sump pump that will activate if the pump fails. This will alert me through email and text.  One issue I am anticipating is that a switch like this will bounce on/off for a while as the water level rises.  I would like to have a long delay built into this function that will eliminate a barrage of messages coming in.

Does anyone know of a delay routine that works in minutes, rather than us and ms? those are all I can find after a quick search.


THANKS EVERYONE!
Title: Re: Microchip's SMTPDemo ??
Post by: tayken on November 04, 2012, 07:46:12 pm
[quote author="mmmike"]Does anyone know of a delay routine that works in minutes, rather than us and ms? those are all I can find after a quick search.[/quote]
There is a GetTick() function used by the demo for some timing stuff. I used it in my own project. You can even do hours I believe.
Code: [Select]
if((TickGet() - StoredTicks) >= TICK_MINUTE){
DoStuff;
}
is kinda how you use it. Check out the heartbeat LED on the demo, MainDemo.c file, the section is:
Code: [Select]
// Line 51
TickInit(); //setup the tick timer

// Line 78
if((TickGet() - ticks) >= (TICK_SECOND/2)){ //blink LED
      ticks = TickGet();
      LED0_IO ^= 1;
}

Title: Re: Microchip's SMTPDemo ??
Post by: mmmike on November 04, 2012, 07:55:45 pm
Thanks for the quick reply tayken.

The tick.h file does have a TICK_HOUR and TICK_MINUTE feature.

I'll be playing with those while developing my code.

BIG THANKS!

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01172090984session_write_close ( )...(null):0
20.01212222576ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01212223352Database_MySQL->query( ).../DatabaseHandler.php:119
40.05772362088Database_MySQL->error( ).../Db-mysql.class.php:273