Thursday, October 10, 2013

Whereabouts Software, Part 4 - Arduino Code

The Arduino code is responsible for connecting to the Wifi network, getting the latest data from the server (with the help of the fetch_current.php script), and moving the servos to the correct location.

Arduino sketch:  Whereabouts.ino

Before you download and install the sketch to your Arduino, you will need to update some of the code for your specific environment:

/* Network Information */
char ssid[] = "your_SSID";      //  your network SSID (name) 
char pass[] = "your_WPA_pass";  // your network password

// WiFi/Ethernet vars
IPAddress server(10,10,10,10);

This is all pretty self-explanatory. Add the Wifi SSID, WPA password, and server IP address to the sketch.

// Servo control vars
// The number of people (or hands) that I have on the clock
#define NUM_PEOPLE 5
// Names of the people we track (must match what is returned from the server
String peopleNames[NUM_PEOPLE] = {String("DAD"), String("MOM"), String("CHILD1"), String("CHILD2"), String("CHILD3")};
// The locations that we will fill from the server
String peopleLocations[NUM_PEOPLE] = {String(""), String(""), String(""), String(""), String("")};

This requires coordinating the sketch with the database user table. The strings "DAD", "MOM", etc. are usernames in the user table. These will be matched in the fetch_current.php script. If you have more or fewer users, they will need to be adjusted here.

// Make the HTTP request
client.println("GET /server_path/fetch_current.php HTTP/1.0");

Update the 'server_path' with the URL path to the fetch_current.php script on the server.

There are a few other tuning parameters in the sketch to control the servo movement, but these should get you started.


No comments:

Post a Comment