Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet with PoE module on: December 21, 2012, 11:40:56 am
It wasn't working because the PoE injector I have using is not 802.3af compliant.
2  Topics / Home Automation and Networked Objects / Arduino Ethernet and Prowl on: December 16, 2012, 12:23:13 pm
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:
// 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
3  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet with PoE module on: December 16, 2012, 12:07:05 pm
Thanks to both of you for your answers.

By "Until today I didn't have hardware to test the PoE module and just did" I meant I didn't have PoE switch.
Now I do have one and I'm plugged on the switch side on the correct port.

Thank you
4  Using Arduino / Networking, Protocols, and Devices / Arduino Ethernet with PoE module on: December 16, 2012, 11:51:11 am
Hello Guys,

I bought few months back an Arduino Ethernet card with PoE module.
Until today I didn't have hardware to test the PoE module and just did.
Is there anything special to do have current coming from PoE or any special cable to use (I currently use a category 5, 4 pairs cable) ?

I am asking this because the card is not powered when I plug the cable.

Thank you
5  Using Arduino / Programming Questions / Re: Millis overflow on: March 06, 2012, 02:40:40 pm
Aaaahhh my bad, unsigned variable!!!

Thank you
6  Using Arduino / Programming Questions / Re: Millis overflow on: March 06, 2012, 02:27:55 pm
So like I said it's gonna roll over and start from the beginning, right ?
It will just skip one interval (as previousMillis will be higher than currentMillis) and go on afterwards.
7  Using Arduino / Programming Questions / Millis overflow on: March 06, 2012, 02:13:40 pm
Hello all,

I am using the millis function as timer instead of using delay. It's mentioned on the reference page that the number of milliseconds will overflow after approximately 50 days.
What will happen when it overflows if I use the following: http://arduino.cc/en/Tutorial/BlinkWithoutDelay
Just skip one interval and go on afterwards ?

Thank you
8  Using Arduino / Project Guidance / Re: Multiple tasks with one board on: January 20, 2012, 11:02:52 am
The second one is more complex, but can do more : you create a small routine that gets called when a specific event (interrupt) takes place.

See http://www.codeproject.com/KB/system/Arduino_interrupts.aspx  or http://www.arduino.cc/en/Reference/AttachInterrupt to get started.
This is very interesting. Even if I read the hardware page with care a few times I never realized about the interrupts!
Thank you!
9  Using Arduino / Project Guidance / Re: Multiple tasks with one board on: January 20, 2012, 08:32:41 am
Yes, of course.
Probably the single most useful example, and one of the simplest, is the "blink without delay" tutorial.
The code is tiny, but the implications huge.
Excellent suggestion! Thank you.
10  Using Arduino / Project Guidance / Re: Multiple tasks with one board on: January 20, 2012, 05:08:21 am
Thank you for your answer Jantje.

Your answer sure helps. Thank you for your time.

I will dig into the forum and play as much as I can with my new toys :-)
11  Using Arduino / Project Guidance / Multiple tasks with one board on: January 20, 2012, 04:45:09 am
Hello everyone,

I'm all new to Arduino stuff and pretty excited about what can be done with such cheap and small hardware! I'm really looking forward to play with it (I've started already but am waiting for a few wires to go further).

There's something that I'm wondering though. Every example of code that I see handles virtually one single task.
For instance, get a value from an INPUT (light sensor, ...) and do something on an OUTPUT (LED, ...).
Can one board be used for multiple purposes (tasks) ?
For instance if I want to have my board report temperature every hour and react permanently to a switch state change (both tasks followed by a remote ethernet connection to send information).

I am actually able to visualize how the code would look like but I want to ensure I'm not going to wrong way.

Also when you tested your project successfully using a breadboard, how do you guys finalize it ?
Do you have someone creating a special board that you can plug onto your arduino (or externally using wires) ?
What do you do in regard to cases ? Do you create them yourselves ?

Thank you for your time!
Pages: [1]