Simple Ethernet Shield Program - Acts different
hi all,
so i'm trying use ethernet shield send simple email via smtp using telnet.
the problem shield unpredictable. code below worked once , not connect server. used return 0 @ client.connect("smtpcorp.com", 2525); stays stuck @ function. 0 not valid return value according http://arduino.cc/en/reference/clientconnect.
here's code:
can explain going on , how can connect reliably?
so i'm trying use ethernet shield send simple email via smtp using telnet.
the problem shield unpredictable. code below worked once , not connect server. used return 0 @ client.connect("smtpcorp.com", 2525); stays stuck @ function. 0 not valid return value according http://arduino.cc/en/reference/clientconnect.
here's code:
code: [select]
// email via telnet
#include <spi.h>
#include <ethernet.h>
byte mac[] = { // mac adress
0xde, 0xad, 0xbe, 0xee, 0xee, 0xee };
ipaddress ip(192,168,1,66); // ip\
//ip address of server 207.58.147.66
ipaddress server(207,58,147,66);
//initialize client libaray
ethernetclient client;
void setup(){
// start ethernet connection mac , ip
ethernet.begin(mac, ip);
serial.begin(9600);
delay(1000);
serial.println("connecting...");
// if connection, report via serial:
int connectstat = client.connect("smtpcorp.com", 2525);
serial.println(connectstat);
if (connectstat) {
serial.println("connected");
}
else {
// if didn't connection server:
serial.println("connection failed");
}
}
void loop(){
if (client.available()) { // read see if there read
char c = client.read();
serial.print(c);
}
if (client.connected()) {
client.print("ehlo");
}
if (client.available()) { // read see if there read
char c = client.read();
serial.print(c);
}
while(true);// stay here , nothing
}
void senddata(){
}
can explain going on , how can connect reliably?
the valid return value successful connection using domain name 1. 0 (unable connect server) or negative (unable resolve domain name) return value failed connection.
edit: had them change client.connect reference page show dns fails (-1 -5), left out 0 return, unable connect server.
code: [select]
if (connectstat == 1) {
serial.println("connected");
}
else if (connectstat == 0) {
// if didn't connection server:
serial.println("connection failed");
}
else {
// if didn't resolution on domain:
serial.println("dns failed");
}
edit: had them change client.connect reference page show dns fails (-1 -5), left out 0 return, unable connect server.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Simple Ethernet Shield Program - Acts different
arduino
Comments
Post a Comment