Go Down

Topic: Arduino Ethernet and Prowl (Read 23892 times) previous topic - next topic

dynek

Dec 16, 2012, 06:23 pm Last Edit: Dec 17, 2012, 07:59 am by dynek Reason: 1
Hello,

As it took me sometime to have it working as I wanted, I thought some other could be interested.
I hope somebody can benefit from this.

Few months back I saw this guy who created a project where when the mailman opens the mailbox, it sends a message onto a smartphone.
I have no clue if I'm going to use this but I found it funny ;-)
For the moment it's a button that simulates the opening of the mailbox and I used Prowl on my iPhone to be notified.

Code: [Select]
// Include libraries
#include <SPI.h>
#include <Ethernet.h>
#include <HTTPClient.h>

// Variables for ethernet connection
byte mac[] = {  0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // enter your MAC address here
byte serverIP[] = { 209,20,72,170 }; // api.prowlapp.com
EthernetClient client;

// Define Prowl API information
#define PROWL_API_KEY "00000000000000000000000000000000000" // enter your Prowl API key here
#define PROWL_API_SRV "api.prowlapp.com"
#define PROWL_API_URL "http://api.prowlapp.com/publicapi/add"

// Define notification application, event and description
#define PUSH_APPLICATION "Arduino"
#define PUSH_EVENT "Mailbox"
#define PUSH_DESCRIPTION "You've got mail!"

// Variables in regard to timing
const unsigned long sendInterval = 60000; // 1 minute minimum between notifications
unsigned long currentMillis = 0;
unsigned long previousMillis = 0;

// Variables in regard to INPUT / OUTPUT
int switchPin = 2;
int switchCurrentState;
int switchPreviousState;

void setup() { 
  // Start the serial port
  Serial.begin(9600);
 
  // Start the ethernet connection
  Serial.println("Configuring Ethernet Connection:");
  if( Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // No point in carrying on, so do nothing forevermore
    for(;;)
      ;
  }
 
  // Connection successful, display IP address
  Serial.println("Connection successful");
  Serial.print("My 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();
}

void loop() {
  // Read switch value
  switchCurrentState = digitalRead(switchPin);
  delay(10); // Fix to button boucing issue
  if (switchCurrentState == digitalRead(switchPin)) { // Read switch value a second time to fix button boucing issue
    // Get number of milliseconds since the Arduino board began running the current program
    currentMillis = millis();
    // If switch state changed, is LOW and delay has expired
    if (switchCurrentState != switchPreviousState && switchCurrentState == LOW && (previousMillis == 0 || currentMillis - previousMillis >= sendInterval)) {
      // Set previousMillis as currentMillis
      previousMillis = currentMillis;
     
      // Send message
      char apikey[] = PROWL_API_KEY;
      char application[] = PUSH_APPLICATION;
      char event[] = PUSH_EVENT;
      char description[] = PUSH_DESCRIPTION;
      sendProwlNotification(apikey, application, event, description);
    }
    // Set current value as last value for next iteration
    switchPreviousState = switchCurrentState;
  }
}

void sendProwlNotification(char* apikey, char* application, char* event, char* description) {
  char url[] = "";
  sendProwlNotification(apikey, application, event, description, 0, url);
}

void sendProwlNotification(char* apikey, char* application, char* event, char* description, int priority) {
  char url[] = "";
  sendProwlNotification(apikey, application, event, description, priority, url);
}

void sendProwlNotification(char* apikey, char* application, char* event, char* description, int priority, char* url) {
  // Convert priority from int to char*
  char sPriority[1];
  sprintf(sPriority, "%d", priority);

  // Create HTTPClient
  char serverHostName[] = PROWL_API_SRV;
  HTTPClient client(serverHostName, serverIP);
 
  // Create POST parameters
  http_client_parameter postParameters[] = {
    {"apikey", apikey},
    {"application", application},
    {"event", event},
    {"description", description},
    {"priority", sPriority},
    {NULL, NULL}
  };
 
  // Send POST to server
  char data[] = "";
  char apiURL[] = PROWL_API_URL;
  FILE* result = client.postURI(apiURL, postParameters, data);
 
  // Could we connect to API server ?
  if (result == NULL) {
    Serial.println("Failed to connect to API server");
  } else {
    // Check error code
    int returnCode = client.getLastReturnCode();
    if(returnCode == 200) {
      // Successfully sent notification
      Serial.println("Notification sent!");
    } else {
      // Display error code on serial
      Serial.print("Error sending notification! Error Code: ");
      Serial.println(returnCode);
    }
    client.closeStream(result);
  }
}


If you have any question or suggestion, I'm there.

Thanks

werkt-nu

i'm olso interested i am look for a coplet sketsch then can i make a litle modification i understand the api key etc.

who people will help

piet holland

werkt-nu

#2
Dec 21, 2012, 12:47 am Last Edit: Dec 21, 2012, 12:50 am by werkt-nu Reason: 1
Hello i'm new in arduino!!! can you help me? i can program my arduino one incl. shield but i have some asks!! ..

1 the program said: give your correct api key ???? where can i find it?

etc zie att. but can you fil the sketch?

piet

Chandler_B

Hey,
I know it's old, but maybe somebody could give me a good advice.
Because I have an Android, I tried it with NotifyMyAndroid.
I just had to change some lines

Code: [Select]

// Variables for ethernet connection
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // enter your MAC address here
byte serverIP[] = {50, 116, 34, 97}; // notifymyandroid.com
EthernetClient client;

// Define Prowl API information
#define PROWL_API_KEY "xxx...xxx" // enter your Prowl API key here
#define PROWL_API_SRV "notifymyandroid.com"
#define PROWL_API_URL "https://www.notifymyandroid.com/nmamail.jsp"


If i set switchPin to High, I get a message in the Serial Monitor:
Notification sent!

but I don't get a Notification on my phone.

What is still wrong? Normally the rest of the code should be the same.

Chandler_B


meccip

Hi, Chandler_B

Try this link AVViso GitHub.
Download and follow instructions. Copy files to Arduino library and open Avviso Exemple in Arduino. Modify sketch for NMA server (read instruction inside the sketch).

I am using PushingBox, but I use Avviso too for sending notifications directly to NMA server.

Go Up