send email, read txt files
Dependencies: EthernetInterface NTPClient SimpleSMTPClient mbed-rtos mbed
Revision 0:895c74a4fcf5, committed 2016-01-26
- Comitter:
- malcon_alex
- Date:
- Tue Jan 26 17:05:13 2016 +0000
- Commit message:
- Send email, read txt files.
Changed in this revision
diff -r 000000000000 -r 895c74a4fcf5 EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Tue Jan 26 17:05:13 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
diff -r 000000000000 -r 895c74a4fcf5 NTPClient_copy.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NTPClient_copy.lib Tue Jan 26 17:05:13 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/NTPClient/#881559865a93
diff -r 000000000000 -r 895c74a4fcf5 SimpleSMTPClient_copy.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SimpleSMTPClient_copy.lib Tue Jan 26 17:05:13 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/sunifu/code/SimpleSMTPClient/#27053679f44b
diff -r 000000000000 -r 895c74a4fcf5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jan 26 17:05:13 2016 +0000 @@ -0,0 +1,155 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "NTPClient.h" +#include "SimpleSMTPClient.h" +#include "string.h" +// +//#define HOSTNAME "mbedSE" +#define DOMAIN "mailnull.com" +#define SERVER "smtp.ualg.pt" +#define PORT "25" +#define USER "a44695" +#define PWD "Alambic79" +#define FROM_ADDRESS "a44695@ualg.pt" +//#define TO_ADDRESS "malcon_alex@hotmail.com" +#define SUBJECT "envio de PING" +Serial pc(USBTX, USBRX); +Serial GSM(p9, p10); +EthernetInterface eth; +NTPClient ntp; +SimpleSMTPClient smtp; + +LocalFileSystem local("local"); // Create the local filesystem under the name "local" +char IP1[15]; +char local_1[25]; +char IP2[15]; +char local_2[25]; +char IP3[15]; +char local_3[25]; +char email[100]; +char tel[9]; +char mensag[200]; +char envioemail[100]; + +void leitura_ip(){ + + FILE *DataFile1 = fopen("/local/dis.txt","r");// read file + //pc.printf("ola"); + int i; + for (i=0; i<1; i++){ + fscanf(DataFile1,"%s",&IP1); + pc.printf("%s\n\r",IP1); + } + for (i=1; i<2; i++){ + fscanf(DataFile1,"%s",&local_1); + pc.printf("%s\n\r",local_1); + } + for (i=2; i<3; i++){ + fscanf(DataFile1,"%s",&IP2); + pc.printf("%s\n\r",IP2); + } + for (i=3; i<4; i++){ + fscanf(DataFile1,"%s",&local_2); + pc.printf("%s\n\r",local_2); + } + for (i=4; i<5; i++){ + fscanf(DataFile1,"%s",&IP3); + pc.printf("%s\n\r",IP3); + } + for (i=5; i<6; i++){ + fscanf(DataFile1,"%s",&local_3); + pc.printf("%s\n\r",local_3); + } + fclose(DataFile1); +} + +void contactos(){ + + FILE *DataFile2 = fopen("/local/notif.txt","r");// read file + //pc.printf("ola"); + int i; + for (i=0; i<1; i++){ + fscanf(DataFile2,"%s",&email); + pc.printf("%s \n\r",email); + } + for (i=1; i<2; i++){ + fscanf(DataFile2,"%s",&tel); + pc.printf("%s\n\r",tel); + } + fclose(DataFile2); +} +void mensagem () +{ + sscanf("teste_de_envio_sms","%s",mensag); // apagar no final + GSM.printf("AT+CMGF=1"); + GSM.putc(0x0d); + wait(1); + GSM.printf("AT+CSCA=+351962100000"); + GSM.putc(0x0d); + wait(1); + GSM.printf("AT+CMGS=\"%s\"",tel); + GSM.putc(0x0d); + wait(1); + GSM.printf("%s", mensag); //mensagem a enviar + GSM.putc(0x1a); + wait(1); + //pc.printf("SMS enviados"); +} +void envio_email(){ + + //Host host(IpAddr();PORT, SERVER); + //EmailMessage msg; + int ret; + NTPClient ntp; + SimpleSMTPClient smtp; + //pc.printf("iniciar envio email"); + + char strTimeMsg[16]; + ntp.setTime("pool.ntp.org"); + time_t ctTime = time(NULL)+32400; // JST + printf("\nTime is now (JST): %d %s\n", ctTime, ctime(&ctTime)); + strftime(strTimeMsg,16,"%y/%m/%d %H:%M",localtime(&ctTime)); + + //EmailMessage msg; + smtp.setFromAddress(FROM_ADDRESS); + smtp.setToAddress(email); + smtp.setMessage("teste envio de email","mensagem do email"); //Envia email (assundo,menssagem) + smtp.addMessage("\n\r FIM \n\r"); + // + ret = smtp.sendmail(SERVER, USER, PWD, DOMAIN,PORT,SMTP_AUTH_NONE); + //sscanf("teste_de_envio_sms","%s",envioemail); // apagar no final + + //smtp.setMessage(envioemail,"teste"); + + + //msg.printf("\r\n",envioemail); + //pc.printf("%s\r\n",envioemail); + //smtp.sendmail(DOMAIN,SERVER,PORT, USER, PWD, SMTP_AUTH_PLAIN); + //printf("Last response | %s", smtp.getLastResponse().c_str()); + } +main() { + + //Iniciar porta ethernet + eth.init(); + eth.connect(); + pc.printf("IP connect %s\r\n",eth.getIPAddress()); + + FILE* DataFile1 = fopen("/local/dis.txt","w"); // create/overwrite file + fprintf(DataFile1,"192.168.1.25 AP_da_entrada\r\n"); + fprintf(DataFile1,"192.168.1.26 AP_da_sala_117\r\n"); + fprintf(DataFile1,"192.168.1.27 AP_do_corredor_DEE\r\n"); + fclose(DataFile1); + DataFile1 = fopen("/local/dis.txt","r"); // read file + fclose(DataFile1); + + FILE* DataFile2 = fopen("/local/Notif.txt","w"); // create/overwrite file + fprintf(DataFile2,"aureliocherondo@sapo.pt\r\n"); + fprintf(DataFile2,"967652943\r\n"); + fclose(DataFile2); + DataFile2 = fopen("/local/Notif.txt","r"); // read file + fclose(DataFile2); + leitura_ip(); + contactos(); + mensagem (); + envio_email(); +} \ No newline at end of file
diff -r 000000000000 -r 895c74a4fcf5 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Tue Jan 26 17:05:13 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#3d9d2b8b8f17
diff -r 000000000000 -r 895c74a4fcf5 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jan 26 17:05:13 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file