Push, SMS, Email Notifications inop.

General support questions and discussions.

Push, SMS, Email Notifications inop.

Postby Greg5972 » Sat Feb 13, 2016 3:25 pm

I just upgraded this project to the DF Robot shield from an Arduino with Ethernet shield. The Device worked perfectly for years and I always received sms Notifications. I Had long since lost the original Sketch I had uploaded to the old setup but it worked. Moving forward I now have the latest Sketch and can not seem to get any sort of Notification to work. The realy operation works fine from both inside and outside my home network. I Downloaded prowl and pasted the API key into the sketch and no success with notifications. I then tried setting up SMS notifications as I did on the Previous build using the same smtp setting as before but I still can't seem to get it to fire an notification. Email notifications also do not work. I am not sure what I am missing here. Ideally I would like to have the option to use Prowl but I will settle for a SMS notification at this point.

Note: The same SMTP settings were tried in Outlook and work no problem

Phone numbers and Passwords are modified for this forum..

The sms gateway for Fido is simply your phone number @fido.ca. If an Email is sent to this address it goes direct sms to my phone.

Please, have a look and et me know what I am missing,

Thanks,

Greg

/ Uncomment to turn ON serial debugging

#define MYDOOROPENER_SERIAL_DEBUGGING 1
#define NOTIFICATIONS_SERIAL_DEBUGGING 1
#define SMTP_SERIAL_DEBUGGING 1
#define PUSH_SERIAL_DEBUGGING 1

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

#include "MyDoorOpenerServer.h"

//*******************************************************************
// Global configuration (adjust to reflect your setup)
//*******************************************************************

// EthernetShield IP address (DHCP reserved, never allocated to anyone else). This is the internal
// network IP address you want your Arduino assigned. This is not the address you will be accessing
// your Arduino from the iPhone application or internet ... You need to configure NAT forwarding
// on your home router to do that. See http://en.wikipedia.org/wiki/Port_forwarding for more details.

uint8_t ip[4] = { 192, 168, 0, 13 };

// Port on which Arduino HTTP server will listen to

int port = 80;

// MAC address to be used by ethernet adapter

uint8_t mac[6] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// password required for operating door [max length = 16] (status fetching doesn't require password). This
// must match the password you set in the iPhone application (be careful as case is sensitive).

char* password = "+++++++++";

// Do not remove the following server definitions

EthernetServer server(port);
MyDoorOpenerServer myDoorOpenerServer(password, mac, ip);

//*******************************************************************
// Device/Door configuration (relais and sensors)
//*******************************************************************

// *** IMPORTANT NOTE ***
//
// THE ARDUINO ETHERNET SHIELD RESERVES DIGITAL PINS 10, 11, 12, 13 AS WELL AS
// ANALOG PINS 0, 1, THEREFORE YOU SHOULD NOT USE ANY OF THOSE PINS FOR YOUR DEVICE(S) OR DOOR(S)

// open/close trigger relay should be connected to these digital output pins (digitalWrite).
// Adjust to match the number of devices you have hooked up (examples provided below in comment) ...

//uint8_t relayPins[] = { 9 }; // single device at pin #9
//uint8_t relayPins[] = { 2, 3, 4, 5 }; // select if using DFRobot RelayShield
//uint8_t relayPins[] = { 2, 3 }; // two devices at pins #2 and #3
//uint8_t relayPins[] = { 2, 3, 4, ... }; // even more devices at pins #2, #3, #4, etc ...
uint8_t relayPins[] = { 7, 8 }; // select if using DFRobot XBoard Relay

// status contact should be connected to these analog input pins (anologRead).
// Adjust to match the number of devices you have hooked up (examples provided below in comment) ...

//uint8_t statusPins[] = { 3 }; // single device at pin #3
//uint8_t statusPins[] = { 2, 3, 4, 5 }; // select if using DFRobot RelayShield
//uint8_t statusPins[] = { 2, 3 }; // two devices at pins #2 and #3
//uint8_t statusPins[] = { 2, 3, 4, ... }; // even more devices at pins #2, #3, #4, etc ...
uint8_t statusPins[] = { 3 }; // select if using DFRobot XBoard Relay

// Comment if not using XBoard Relay
#define USING_XBOARD_RELAY

// status reading strategy (uncomment only one ... the one that reflects how you want status to be interpreted)

//#define STATUS_STRATEGY_3VCLOSED_5VOPENED // initial approach - uses analogRead combined with STATUS_OPEN_TRESHOLD (opened == +5v, closed == +3v)
//#define STATUS_STRATEGY_5VCLOSED_3VOPENED // alternate approach - uses analogRead combined with STATUS_OPEN_TRESHOLD (opened == +3v, closed == +5v)
#define STATUS_STRATEGY_NORMALLY_CLOSED // classic door sensor - uses digitalRead to interpret door/device status (opened == high-impedance, closed == GND)
//#define STATUS_STRATEGY_NORMALLY_OPENED // alternate approach - uses digitalRead to interpret door/device status (opened == GND, closed == high-impedance)

// Analog boundary value (0-1023) used to distinguish between device/door status == opened and closed. Only applicable
// when STATUS_STRATEGY_3VCLOSED_5VOPENED or STATUS_STRATEGY_5VCLOSED_3VOPENED is being used.

#define STATUS_OPEN_TRESHOLD 888

//*******************************************************************
// Notifications
//*******************************************************************

// if defined, will fire a notification when any door/device stays open more than the specified number of minutes
#define NOTIFICATIONS_WATCHDOG_MINUTES 2

// if defined, will fire a notification every time and as soon as any door/device gets opened
#define NOTIFICATIONS_OPEN

//*******************************************************************
// iOS push notifications (via Prowl)
//*******************************************************************

// if defined, will fire notifications using iOS push notifications (uncomment to turn ON)
#define PUSH_NOTIFICATIONS

#if defined(PUSH_NOTIFICATIONS)

// after installing Prowl (iTunes store) on your iPhone, set to match the Prowl API key that was
// assigned for your iPhone http://www.prowlapp.com/api_settings.php
char prowlApiKey[] = "d7004df9da669ca4dc8f2198cdfeb5d36d1e8c65";

// set to Prowl HTTP server name (typically api.prowlapp.com)
char prowlServerName[] = "api.prowlapp.com";

// set to Prowl HTTP port number (typically port 80)
int prowlServerPort = 80;

// set to Prowl API base url (typically /publicapi/add)
char prowlApiBaseUrl[] = "/publicapi/add";

#endif

//*******************************************************************
// SMS notifications (via carrier provided SMS gateway, relies on SMTP)
//*******************************************************************

// if defined, will fire notifications using SMS notifications (uncomment to turn ON - rember to adjust SMTP settings too)
#define SMS_NOTIFICATIONS

#if defined(SMS_NOTIFICATIONS)

// using http://en.wikipedia.org/wiki/List_of_SMS_gateways set to match your mobile carrier and phone number
char smtpToForSms[] = "6047++++44@fido.ca";

#endif

//*******************************************************************
// SMTP email notifications (also used for SMS notifications)
//*******************************************************************

// if defined, will fire notifications using SMTP notifications (uncomment to turn ON)
//#define SMTP_NOTIFICATIONS

#if defined(SMTP_NOTIFICATIONS) || defined(SMS_NOTIFICATIONS)

// set to your ISP's SMTP server name
char smtpServerName[] = "mail.shaw.ca";

// set to your ISP's SMTP server port (typically port 25)
int smtpServerPort = 25;

// set to the email address you want notifications sent to
char smtpToForEmail[] = "g++++++@shaw.ca";

#endif

//*******************************************************************
// Misc configuration constants (should not require any changes)
//*******************************************************************

// number of milliseconds relay pin will be held high when triggered.

int RELAY_DELAY = 1000;

// misc size constants

#define HTTP_PARAM_NAME_SIZE 16
#define HTTP_PARAM_VALUE_SIZE 64

#define PASSWORD_HEX_SIZE 32
#define PASSWORD_SIZE 16
#define AES256_CRYPTO_KEY_SIZE 32
#define CHALLENGE_TOKEN_SIZE 16

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
#if defined(PUSH_NOTIFICATIONS)

//----------------------------------------------------------------------------------------------------
void getUrlEncoded(const char* msg, char* encodedMsg)
{
const char hex[] = "0123456789abcdef";

while(*msg != '\0')
{
if(('a' <= *msg && *msg <= 'z') || ('A' <= *msg && *msg <= 'Z') || ('0' <= *msg && *msg <= '9'))
{
*encodedMsg = *msg;
encodedMsg++;
}
else
{
*encodedMsg = '%';
encodedMsg++;

*encodedMsg = hex[*msg >> 4];
encodedMsg++;

*encodedMsg = hex[*msg & 15];
encodedMsg++;
}

msg++;
}
}

EthernetClient pushClient;

//----------------------------------------------------------------------------------------------------
void notifyViaPush(const char* subject, const char* body)
{
#if defined(PUSH_SERIAL_DEBUGGING)
Serial.print(F("*** Push - server name: '"));
Serial.print(prowlServerName);
Serial.print(F("' - "));
Serial.print(F("apiKey: '"));
Serial.print(prowlApiKey);
Serial.print(F("' - "));
Serial.print(F("subject: '"));
Serial.print(subject);
Serial.print(F("' - "));
Serial.print(F("body: '"));
Serial.print(body);
Serial.println(F("' ***"));
#endif

if (pushClient.connect(prowlServerName, prowlServerPort))
{
#if defined(PUSH_SERIAL_DEBUGGING)
Serial.println(F("*** Push - connection established ***"));
#endif

pushClient.print(F("GET "));

pushClient.print(prowlApiBaseUrl);
pushClient.print(F("?apikey="));
pushClient.print(prowlApiKey);
pushClient.print(F("&application=MyDoorOpener"));
pushClient.print(F("&url=mydooropener%3A%2F%2Fstatus"));

char encodedBuffer[100] = "";

pushClient.print(F("&event="));
memset(encodedBuffer, 0, 100);
getUrlEncoded(subject, encodedBuffer);
pushClient.print(encodedBuffer);

pushClient.print(F("&description="));
memset(encodedBuffer, 0, 100);
getUrlEncoded(body, encodedBuffer);
pushClient.print(encodedBuffer);

pushClient.println(F(" HTTP/1.1"));

pushClient.print(F("Host: "));
pushClient.println(prowlServerName);

pushClient.print(F("Accept: *"));
pushClient.print(F("/"));
pushClient.println(F("*"));
pushClient.println(F("Connection: close"));

pushClient.println();

pushClient.stop();

#if defined(PUSH_SERIAL_DEBUGGING)
Serial.println(F("*** Push - connection stopped ***"));
#endif
}

#if defined(PUSH_SERIAL_DEBUGGING)
Serial.println(F("*** Push - completed ***"));
#endif
}

#endif

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
#if defined(SMTP_NOTIFICATIONS) || defined(SMS_NOTIFICATIONS)

EthernetClient smtpClient;

//----------------------------------------------------------------------------------------------------
void notifyViaEmail(const String& to, const String& subject, const String& body)
{
#if defined(SMTP_SERIAL_DEBUGGING)
Serial.print(F("*** SMTP - server name: '"));
Serial.print(smtpServerName);
Serial.print(F("' - "));
Serial.print(F("to: '"));
Serial.print(to);
Serial.print(F("' - "));
Serial.print(F("subject: '"));
Serial.print(subject);
Serial.print(F("' - "));
Serial.print(F("body: '"));
Serial.print(body);
Serial.println(F("' ***"));
#endif

if (smtpClient.connect(smtpServerName, smtpServerPort))
{
#if defined(SMTP_SERIAL_DEBUGGING)
Serial.println(F("*** SMTP - connection established ***"));
#endif

smtpClient.println(F("HELO relai.mydooropener.com"));

smtpClient.print(F("MAIL FROM:"));
smtpClient.println(F("noreply@mydooropener.com"));

smtpClient.print(F("RCPT TO:"));
smtpClient.println(to);

smtpClient.println(F("DATA"));

smtpClient.print(F("SUBJECT: "));
smtpClient.println(subject);


smtpClient.println();

smtpClient.print(body);
smtpClient.print(F(" "));
smtpClient.println(F("mydooropener://status"));

smtpClient.println(F("."));
smtpClient.println(F("."));

smtpClient.println(F("QUIT"));

smtpClient.stop();

#if defined(SMTP_SERIAL_DEBUGGING)
Serial.println(F("*** SMTP - connection stopped ***"));
#endif
}

#if defined(SMTP_SERIAL_DEBUGGING)
Serial.println(F("*** SMTP - completed ***"));
#endif
}

//----------------------------------------------------------------------------------------------------
void notifyViaEmail(const char* subject, const char* body)
{
notifyViaEmail(smtpToForEmail, subject, body);
}

#endif

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
#if defined(SMS_NOTIFICATIONS)

//----------------------------------------------------------------------------------------------------
void notifyViaSms(const char* subject, const char* body)
{
notifyViaEmail(smtpToForSms, subject, body);
}

#endif

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
void configureStatusPin(int pinNumber)
{
#if defined(STATUS_STRATEGY_3VCLOSED_5VOPENED) || defined(STATUS_STRATEGY_5VCLOSED_3VOPENED)
pinMode(pinNumber, INPUT);
#elif defined(STATUS_STRATEGY_NORMALLY_CLOSED) || defined(STATUS_STRATEGY_NORMALLY_OPENED)
#if defined(USING_XBOARD_RELAY)
pinMode(pinNumber+18, INPUT_PULLUP); // addressing analog pins as digital pins (+18)
#else
pinMode(pinNumber+14, INPUT_PULLUP); // addressing analog pins as digital pins (+14)
#endif
#endif
}

//----------------------------------------------------------------------------------------------------
boolean isOpen(int pinNumber)
{
#if defined(STATUS_STRATEGY_3VCLOSED_5VOPENED) || defined(STATUS_STRATEGY_5VCLOSED_3VOPENED)
int status = analogRead(pinNumber);
#elif defined(STATUS_STRATEGY_NORMALLY_CLOSED) || defined(STATUS_STRATEGY_NORMALLY_OPENED)
#if defined(USING_XBOARD_RELAY)
int status = digitalRead(pinNumber+18); // addressing analog pins as digital pins (+18)
#else
int status = digitalRead(pinNumber+14); // addressing analog pins as digital pins (+14)
#endif
#endif

#if defined(MYDOOROPENER_SERIAL_DEBUGGING)
Serial.print(F("*** isOpen - status value for pin: '"));
Serial.print(pinNumber);
Serial.print(F("' is '"));
Serial.print(status);
#endif

boolean retVal = false;

#if defined(STATUS_STRATEGY_3VCLOSED_5VOPENED)
retVal = status >= STATUS_OPEN_TRESHOLD;
#elif defined(STATUS_STRATEGY_5VCLOSED_3VOPENED)
retVal = status <= STATUS_OPEN_TRESHOLD;
#elif defined(STATUS_STRATEGY_NORMALLY_CLOSED)
retVal = status == LOW;
#elif defined(STATUS_STRATEGY_NORMALLY_OPENED)
retVal = status == HIGH;
#endif

#if defined(MYDOOROPENER_SERIAL_DEBUGGING)
Serial.print(F("' returing: '"));
Serial.print(retVal ? F("Opened") : F("Closed"));
Serial.println(F("' ***"));
#endif

return retVal;
}

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
#if defined(NOTIFICATIONS_WATCHDOG_MINUTES)

//----------------------------------------------------------------------------------------------------
void watchDogNotificationsHandler()
{
static time_t initialOpen = NULL;
time_t latestOpen = NULL;

static boolean notificationSent = false;
boolean openDetected = false;

for (int i = 0; i < sizeof(statusPins); ++i)
{
if (isOpen(statusPins[i]))
{
if (!initialOpen)
initialOpen = now();

latestOpen = now();

if((latestOpen - initialOpen) > NOTIFICATIONS_WATCHDOG_MINUTES * 60)
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.print(F("*** watchdog notification handler - detected opened device/door @ pin #"));
Serial.print(statusPins[i]);
Serial.println(F(" ***"));
#endif

if (!notificationSent)
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.println(F("*** watchdog notification handler - sending notification ***"));
#endif

char subject[] = "MyDoorOpener Notification";
char body[100] = "";
sprintf(body, "A door or device has been opened for more than %i minute(s).", NOTIFICATIONS_WATCHDOG_MINUTES);

#if defined(PUSH_NOTIFICATIONS)
notifyViaPush(subject, body);
#endif

#if defined(SMS_NOTIFICATIONS)
notifyViaSms(subject, body);
#endif

#if defined(SMTP_NOTIFICATIONS)
notifyViaEmail(subject, body);
#endif

notificationSent = true;
}
else
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.println(F("*** watchdog notification handler - NOT sending notification ***"));
#endif
}
}

openDetected = true;
break;
}
}

// if all door/devices are closed, reset notificationSent semaphore and timer so that further notifications
// can be sent. This is done to avoid floading recipient with notifications for a same event occurrence.

if (!openDetected)
{
notificationSent = false;
initialOpen = NULL;
delay(500);
}
}

#endif

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
#if defined(NOTIFICATIONS_OPEN)

//----------------------------------------------------------------------------------------------------
void openNotificationsHandler()
{
static boolean notificationSent = false;
boolean openDetected = false;

for (int i = 0; i < sizeof(statusPins); ++i)
{
if (isOpen(statusPins[i]))
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.print(F("*** open notification handler - detected an opened device/door @ pin #"));
Serial.print(statusPins[i]);
Serial.println(F(" ***"));
#endif

if (!notificationSent)
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.println(F("*** open notification handler - sending notification ***"));
#endif

char subject[] = "MyDoorOpener Notification";
char body[] = "A door or device has just been opened.";

#if defined(PUSH_NOTIFICATIONS)
notifyViaPush(subject, body);
#endif

#if defined(SMS_NOTIFICATIONS)
notifyViaSms(subject, body);
#endif

#if defined(SMTP_NOTIFICATIONS)
notifyViaEmail(subject, body);
#endif

notificationSent = true;
}
else
{
#if defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.println(F("*** open notification handler - NOT sending notification ***"));
#endif
}

openDetected = true;
break;
}
}

// if all door/devices are closed, reset notificationSent semaphore so that further notifications
// can be sent. This is done to avoid floading recipient with notifications for a same event occurrence.

if (!openDetected)
{
notificationSent = false;
delay(500);
}
}

#endif

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
void setup()
{
#if defined(MYDOOROPENER_SERIAL_DEBUGGING) || defined(WEBDUINO_SERIAL_DEBUGGING) || defined(SMTP_SERIAL_DEBUGGING) || #defined(PUSH_SERIAL_DEBUGGING) || defined(NOTIFICATIONS_SERIAL_DEBUGGING)
Serial.begin(9600);
#endif

#if defined(MYDOOROPENER_SERIAL_DEBUGGING)
Serial.println(F("*** MyDoorOpener setup begin ***"));
#endif

for (int i = 0; i < sizeof(statusPins); ++i)
configureStatusPin(statusPins[i]);

for (int i = 0; i < sizeof(relayPins); ++i)
{
pinMode(relayPins[i], OUTPUT);
digitalWrite(relayPins[i], LOW);
}

// start web server

myDoorOpenerServer.setup(statusPins, sizeof(statusPins));

#if defined(MYDOOROPENER_SERIAL_DEBUGGING)
Serial.println(F("*** MyDoorOpener setup completed ***"));
#endif
}

//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
void loop()
{
myDoorOpenerServer.loop();

#if defined(NOTIFICATIONS_WATCHDOG_MINUTES)
watchDogNotificationsHandler();
#endif

#if defined(NOTIFICATIONS_OPEN)
openNotificationsHandler();
#endif
}
Greg5972
 
Posts: 2
Joined: Sat Feb 13, 2016 3:10 pm

Re: Push, SMS, Email Notifications inop.

Postby support » Thu Feb 25, 2016 10:24 pm

I suggest you setup SERIAL debugging and check if you are actually firing any notification events. For notifications to work
the Arduino needs access to the internet. For some this requires changing the way the Arduino connects. Search the forums
for multiple threads that deal with this matter already, such as viewtopic.php?f=2&t=353
support
Site Admin
 
Posts: 384
Joined: Thu Aug 22, 2013 7:30 pm

Re: Push, SMS, Email Notifications inop.

Postby Greg5972 » Fri Feb 26, 2016 1:32 am

Down graded to 2.3 and used arduino 1.0.3 IDE. also used actual ip address of Prowl. Works perfect.
Greg5972
 
Posts: 2
Joined: Sat Feb 13, 2016 3:10 pm


Return to Support



cron