Skip to content

Commit

Permalink
fix email alert bug, add #define DNS_IP and SMTP_IP
Browse files Browse the repository at this point in the history
  • Loading branch information
d0ughb0y committed Aug 22, 2014
1 parent 2a494b4 commit 32b7533
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 39 deletions.
2 changes: 1 addition & 1 deletion InterruptsIO.ino
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,6 @@ uint16_t getSonar() {
uint8_t getSonarPct() {
uint16_t numerator = conf.sonarlow*10-getSonar();
uint16_t denominator = conf.sonarlow - conf.sonarhigh;
return numerator/(denominator*10);
return numerator*10/denominator;
}

56 changes: 37 additions & 19 deletions Network.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ TinyWebServer web = TinyWebServer(handlers,headers);
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(LOCAL_IP);
IPAddress router(ROUTER_IP);
#ifdef DNS_IP
IPAddress dnsserver(DNS_IP);
#else
IPAddress dnsserver(ROUTER_IP);
#endif

boolean netCheck() {
static uint8_t retry = 0;
Expand All @@ -66,6 +71,7 @@ boolean netCheck() {
uint8_t s = client.status();
if (s==0 || s==0x18 || s==0x1C) {//closed || fin_wait || close_wait
hasFreeSocket=true;
client.stop();
break;
}
}
Expand All @@ -79,7 +85,7 @@ boolean netCheck() {
}
EthernetClient client;
IPAddress router(ROUTER_IP); //change the ip to your router ip address
if (client.connect(router,ROUTER_PORT)) {
if (client.connect(router,ROUTER_PORT)==1) {
client.stop();
retry=0;
return true;
Expand All @@ -93,15 +99,15 @@ boolean netCheck() {
}

void resetNetwork() {
Ethernet.begin(mac,ip,router,router);
Ethernet.begin(mac,ip,dnsserver, router);
web.begin();
chirp();
logMessage(F("Ethernet and Webserver reset."));
}

void initNetwork() {
//init ethernet shield
Ethernet.begin(mac,ip,router,router);
Ethernet.begin(mac,ip,dnsserver, router);
initClock();
logMessage(F("System initializing..."));
if (netCheck()) {
Expand Down Expand Up @@ -273,8 +279,13 @@ inline void webprocess() {
void sendEmail() {
if (!conf.emailalert) return;
logMessage(F("Sending email alert."));
EthernetClient& client = web.get_client();
if (client.connect(SMTPSERVER, SMTPPORT)){
EthernetClient client;
#ifdef SMTP_IP
IPAddress smtpip(SMTP_IP);
if (client.connect(smtpip,SMTPPORT)==1){
#else
if (client.connect(SMTPSERVER, SMTPPORT)==1){
#endif
if(!eRcv(client)) return;
client << F("EHLO CHAUVET16\r\n");
if(!eRcv(client)) return;
Expand Down Expand Up @@ -302,46 +313,51 @@ void sendEmail() {
client << F("\r\n");
#ifdef _TEMP
for (int i=0;i<MAXTEMP;i++) {
client << tempdata[i].name << ": " << getTemp(i) << F("\r\n");
client << (const char*)tempdata[i].name << ": " << getTemp(i) << F("\r\n");
}
#endif
#ifdef _PH
for (int i=0;i<MAXPH;i++) {
client << phdata[i].name << ": " << getAtlasAvg(phdata[i]) << F("\r\n");
client << (const char*)phdata[i].name << ": " << getAtlasAvg(phdata[i]) << F("\r\n");
}
#endif
#ifdef _COND
client << F("Cond: ") << getAtlasAvg(conddata) << F("\r\n");
#endif
#ifdef _ORP
client << F("Orp: ") << getAtlasAvg(orpdata) << F("\r\n");
client << F("Orp: ") << getAtlasAvg(orpdata) << F("\r\n");
#endif
#ifdef _SONAR
client << F("Top Off water level: ") << (uint8_t)getSonarPct() << F("%\r\n.\r\n");
client << F("Top Off water level: ") << (int)getSonarPct() << F("%\r\n");
#endif
#ifdef _DOSER
for (int i=0;i<MAXDOSERS;i++) {
client << F("Doser ") << i << F(": \r\n");
client << F(" ") << (const char*)conf.doser[i].name << F("\r\n");
client << F(" Dosed Volume: ") << dosedvolume[i]/100.0 << F("\r\n");
client << F(" Remaining Volume:") << conf.doser[i].fullvolume -dosedvolume[i]/100.0 << F("\r\n");
}
for (int i=0;i<MAXDOSERS;i++) {
client << F("Doser ") << i << F(": \r\n");
client << F(" ") << (const char*)conf.doser[i].name << F("\r\n");
client << F(" Dosed Volume: ") << dosedvolume[i]/100.0 << F("\r\n");
client << F(" Remaining Volume:") << conf.doser[i].fullvolume -dosedvolume[i]/100.0 << F("\r\n");
}
#endif
client << F(".\r\n");
if(!eRcv(client)) return;
client << F("QUIT\r\n");
if(!eRcv(client)) return;
client.stop();
logMessage(F("Successfully sent email."));
} else {
logMessage(F("Send email failed."));
}
}


byte eRcv(EthernetClient& client)
{
byte respCode;
while(!client.available()) delay(1);
while(client.connected() && !client.available()){
delay(1);
}
respCode = client.peek();
while(client.available())
while(client.connected() && client.available())
{
client.read();
}
Expand All @@ -357,8 +373,10 @@ byte eRcv(EthernetClient& client)
void efail(EthernetClient& client)
{
client.println(F("QUIT"));
while(!client.available()) delay(1);
while(client.available())
while(client.connected() && !client.available()) {
delay(1);
}
while(client.connected() && client.available())
{
client.read();
}
Expand Down
27 changes: 16 additions & 11 deletions Sensors.ino
Original file line number Diff line number Diff line change
Expand Up @@ -446,19 +446,24 @@ void atlasSerialHandler(){
}

void atlasHandler(AtlasSensorDef_t &data) {
char c = (char)data.saddr.read();
if (c=='\r') {
data.scratch[data.i]=0;
data.i=0;
data.value=atof(data.scratch);
data.isReady=true;
} else {
data.scratch[data.i++]=c;
if (data.i==14) {
int ccount = data.saddr.available();
for (int i=0;i<ccount;i++) {
char c = (char)data.saddr.read();
if (c=='\r') {
data.scratch[data.i]=0;
data.i=0;
data.scratch[0]=0;
data.value=0;
data.value=atof(data.scratch);
data.isReady=true;
return;
} else {
data.scratch[data.i++]=c;
if (data.i==14) {
data.i=0;
data.scratch[0]=0;
data.value=0;
data.isReady=true;
return;
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Utils.ino
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,15 @@ void logMessage(uint8_t ip[], const char* msg) {
void logAlarm() {
char buffer[20];
if (logSetup(now2(), buffer, "LOG", "log")) {
fileout_ << buffer << F(" Alarm Event : ");
fileout_ << buffer << F(" Alarm Event: ");
#ifdef _TEMP
for (uint8_t i;i<MAXTEMP;i++) {
fileout_ << tempdata[i].name << F(":") << getTemp(i) << F(" ");
for (uint8_t i=0;i<MAXTEMP;i++) {
fileout_ << (const char*)tempdata[i].name << F(":") << getTemp(i) << F(" ");
}
#endif
#ifdef _PH
for (uint8_t i;i<MAXPH;i++) {
fileout_ << phdata[i].name << F(":") << getAtlasAvg(phdata[i]) << F(" ");
for (uint8_t i=0;i<MAXPH;i++) {
fileout_ << (const char*)phdata[i].name << F(":") << getAtlasAvg(phdata[i]) << F(" ");
}
#endif
#ifdef _COND
Expand All @@ -515,7 +515,7 @@ void logAlarm() {
}
#endif
#ifdef _SONAR
fileout_ << F("Sonar:") << (uint8_t)getSonarPct() << F("%\n");
fileout_ << F("Sonar:") << (int)getSonarPct() << F("%\n");
#endif
fileout_.close();
}
Expand Down
6 changes: 4 additions & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define NTPSERVER 193,193,193,107 //pool.ntp.org
#define LOCAL_IP 192,168,0,15 //change this to a local fixed ip address
#define ROUTER_IP 192,168,0,1 //change this to your router ip address
//#define DNS_IP 75,75,75,75 //specify this if your router does not do dns forwarding
#define ROUTER_PORT 80 //usually port 80 for the ip configuration web page
//////////////////////////////////////////////////
// DS18B20 Temperature Sensor Section
Expand Down Expand Up @@ -105,11 +106,12 @@
//SMTPUSER = your email login, sample below is admin
//SMTPPASSWORD = your email password, sample below is password
#define BASICAUTH "YWRtaW46cGFzc3dvcmQ="
#define SMTPSERVER "my.smtp.net"
#define SMTPSERVER "smtp.gmx.net"
#define SMTP_IP 74,208,5,30
#define SMTPPORT 587
#define SMTPUSER "YWRtaW4="
#define SMTPPASSWORD "cGFzc3dvcmQ="
#define EMAILFROM "user@host.com"
#define EMAILFROM "user@gmx.com"
#define EMAILTO "[email protected]"
#define SD_CS 4
#define ETHER_CS 10
Expand Down

0 comments on commit 32b7533

Please sign in to comment.