Pages: [1]   Go Down
Author Topic: Telnet SMTP gmail with copperhead Wifi Shield  (Read 1700 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 126
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

alrighty, so I am trying to send an SMS via telnet to gmail, but i really have no idea what I am doing.

I am using this shield: http://www.cutedigi.com/wireless/wifi/linksprite-cuhead-wifi-shield-for-arduino.html

all of the sketches work fine. i've managed to connect the shield to the network.

Now onto executing telnet to gmail : I conceptually understand these guides on this process to connect illustrated here: http://www.tech-and-dev.com/2010/10/sending-email-using-gmail-smtp-server.html

and here is my attempt to fuse together somebodys ethernet shield example and the classes with the copperhead wifi shield. I have no clue what I am missing, what I need to consider, if anyone has working examples, what functions can be attached to this shields classes, etc. HELP.

Code:
/*
SEND AN EMAIL WITH ARDUINO
9/23/11
This code was created by modifying the connect example from arduino.cc
and with the help of the YABB forums and their very helpful members.
This code sends an email to any email address and then disconnects.
*/

#include <SPI.h>
#include <Ethernet.h>
#include <WiServer.h>




#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes

unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3
};

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters ----------------------------------------



//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Arduino's artificial mac address
//byte ip[] = { 192, 168, 1, 1 }; // my ip
byte server[] = { 64,233,183,109 }; // my smtp.xxx.net server ip f gmail

Client client(server, 465);

void setup()
{
  Ethernet.begin(local_ip, gateway_ip );
 Serial.begin(57600);

 Serial.println("connecting...");
 
 if (client.connect()) {
                        Serial.println("connected");
   
                        client.println("HELO itismeletschat"); /* say hello (statement after helo is needed but irrelevant)*/

                        client.println("MAIL From: me@my-isp.net"); /* identify sender, this should be the same as the smtp server you are using */

                        client.println("RCPT To: you@your-isp.net"); /* identify recipient */

                        client.println("DATA");

                        client.println("To: you@your-isp.net"); /* identify recipient */
                        client.println("Subject: You Have Arduino Mail!!"); /* insert subject */

                        client.println("Please let me know it worked!!!"); /* insert body */
                        client.println("."); /* end email */
                 
                        client.println("QUIT"); /* terminate connection */
                       
                        client.println();
   
 } else {
   Serial.println("connection failed");
 }
}

void loop()
{
   delay(10000);
   if (!client.connected()) {
   Serial.println();
   Serial.println("disconnecting.");
   client.stop();
   for(;;)
     ;
 }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I have no clue what I am missing
A description of what that code does right, what it does wrong, and what needs to be changed, to name a few things.

Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 126
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As mentioned above, I am able to connect the wifi shield to the network. that is where I am at. I am not sure how to use the class, what alternatives are available to me. insightful resources, sample code, etc are appreciated.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11162
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As mentioned above, I am able to connect the wifi shield to the network. that is where I am at.

You seem to have a sketch that connects to an SMTP server and tries to send an email using SMTP.

Does the sketch compile and run? What happens when you run it? Does the TCP/IP interface come up OK? Are you able to connect to the server?

I notice that you're sending messages to the SMTP server but not reading back any responses. You should read the responses back and I suggest you print them out for debug purposes, this will enable you to see where your SMTP transaction is succeeding and where it is failing.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Full Member
***
Karma: 0
Posts: 126
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

it doesnt run. the syntax for the ethernet library does not work with the classes for the Wifi shield library. the sketch alone for just ethernet does not even compile. i have the library installed, but no luck.



Quote
You seem to have a sketch that connects to an SMTP server and tries to send an email using SMTP.

thats essentially what I want to. don't i need to specify login information? maybe an example sketch could get me going? I dont know what the issue is 
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 126
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

look, i dont know what questions to ask, where to begin so forgetting everything i posted except knowing what hardware im using,

i just want to send an sms through email.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11162
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

look, i dont know what questions to ask, where to begin so forgetting everything i posted except knowing what hardware im using,

i just want to send an sms through email.

I'm not trying to be unhelpful, but now I'm confused about what you're trying to achieve.

You have a WiFi shield, which means your Arduino can connect to your local network. Assuming you have an internet connection on your network, you can also connect to the internet.

The Arduino has a library which enables it to establish TCP connections and send and receive data over TCP. By opening a TCP connection to an SMTP email server and sending it the right sequence of commands, you can submit an email. Some SMTP servers will accept connections from anywhere, some will only accept them from addresses it knows about (for example your ISP may decide to only accept email from their own subscribers), some require you to authenticate and there are various ways that can be done and different servers support different ways.

So, you can send and receive email on your PC using telnet or PuTTY. With a little more work, you can write a sketch to run on an Arduino to send and receive email.

Nowhere in this has SMS been mentioned. If you want to send SMS messages you need either a GSM/GPRS modem (phone/dongle) or access to a service that will send SMS messages for you. It is then up to the people providing that service to define how they will accept requests from you. Perhaps there is one that will accept SMS requests via SMTP but I don't know of any.

What are you trying to achieve? Are you trying to send emails, or SMS text messages? Are you trying to send them from a PC, or an Arduino?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Full Member
***
Karma: 0
Posts: 126
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

First off, thanks for the extremely helpful explanation.

Second, I am trying to send an SMS directly from the arduino. I figured I'd achieve this with wifi, since each service provider has unique email addresses to send texts to a phone number (i.e. 3122224444@txt.att.net)

So, that is where I am at. I am unaware of where to begin, based on the sample sketches that have been supplied with this wifi shield.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11162
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sending an email request to send an SMS seems like a rather contrived way of going about it, but I suppose it could work.

Have you been able to send an email to that email address manually and get the SMS sent?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8915
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some test email code you might try with your ISP's SMTP server.

Code:
//zoomkat 4/08/12
//email test code using DNS
//developed from code posted by various persons

#include <SPI.h>
#include <Ethernet.h>

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = "smtp.yourISP.net"; // your ISP's SMTP server
EthernetClient client;

//////////////////////

void setup(){
  Serial.begin(9600);
  Serial.println("DNS and DHCP-based email test 4/08/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  // print your local IP address:
  Serial.print("Arduino IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print(".");
  }
  Serial.println();
  Serial.println();
}

void loop()
{
  byte inChar;
  inChar = Serial.read();
  if(inChar == 'e')
  {
    if(sendEmail()) Serial.println("Email sent"); //start sendEmail()
    else Serial.println("Email failed");
  }
}

//////////////////////////////// email function
byte sendEmail()  //sendEmail() function that returns 1 or 0
{
  //start and check for email server connection
  if (client.connect(serverName, 25)) {
    Serial.println("connected");
  }
  else {
    Serial.println("connection failed");
    return 0; //send 0 (failed) back to sendEmail() function
  }
 
  //wait for server "queing" response
  while(!client.available()) delay(1);

  client.println("HELO itismeletschat"); /*hello (statement after helo is needed but irrelevant)*/

  //wait for server "hello" response
  while(!client.available()) delay(1);

  client.println("MAIL From: me@athome.net"); // identify sender, this should be the same as the smtp server you are using*/

  //wait for server "sender ok" response
  while(!client.available()) delay(1);

  client.println("RCPT To: you@athome.net"); /* identify recipient */

  //wait for server "receipent ok" response
  while(!client.available()) delay(1);

  client.println("DATA");

  //wait for server to say "enter your message" response
  while(!client.available()) delay(1);
 
  //send email message to server
  client.println("To: you@athome.net"); /* identify recipient */
  client.println("Subject: You Have Arduino Mail!!"); /* insert subject */
  client.println("Please let me know it worked!!!"); /* insert body */
  client.println("."); /* end email */

  //wait for server "message accepted" response
  while(!client.available()) delay(1);

  client.println("QUIT"); /* terminate connection */
 
  //wait for server "goodby" response
  while(!client.available()) delay(1);

  //stop client connection
  client.stop();
  Serial.println("disconnected");
  return 1; //send 1 (success) back to sendEmail() function
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: