A super quick, super simple little example of how to get started with the AWS SDK2 for PHP. It connects to the S3 service with your credentials and checks to see if a file exists.
- Assuming you already have a LAMP setup, you may need to install php-pear:
sudo apt-get install php-pear
- Add the AWS channel and auto discover dependencies:
pear channel-discover pear.amazonwebservices.com
pear -D auto_discover=1 install pear.amazonwebservices.com/sdk
- Download the .phar file here and throw it on your server in this script’s directory (for this example).
- Replace the items in brackets and run the script. The [OBJECT KEY] is just the name of the file, so ‘mypicture.jpg’ in the root of the bucket would have the key ‘mypicture.jpg’.
$aws = Aws::factory(array(
'key' => '[KEY HERE]',
'secret' => '[SECRET HERE]'
$client = $aws->get('s3');
echo $client->doesObjectExist('[BUCKET NAME]', '[OBJECT KEY]');
You’ll get back the boolean response of that call (assuming it makes it that far without error). Refer to the API documentation for the other methods and their responses.
With an Arduino Ethernet, Processing, and a Kinect, I was able to easily create this little demo where hand movement can control a servo. This is just a tiny step in my master plan to create a robot clone so that I don’t have to leave my chair.
The following libraries and drivers made this work and also made it super easy for me to create it:
Daniel Shiffman’s Processing Kinect Library (he knows his stuff and has great examples on his site)
Arduino Ethernet UDP send / receive string
EMAX ES08A Servo
How it works:
- The Arduino Ethernet acquires an IP address and waits for UDP packets on a certain port.
- The machine with the Kinect sends packets to the Arduino that contain hand coordinate data.
- The Arduino then takes this data (an integer) and maps the range from 0 to 180 degrees.
- The mapped value is sent to the servo.
Uncaught TypeError: Cannot call method 'substr' of undefined
The transitions were working, but the previous image wasn’t ‘overlayed’ by the next image – it would just disappear and the new one would appear. It was almost like something else was there. Looking back at my ‘raw’ HTML code in the WordPress post, I had all three images in sequential order, but neatly aligned by pressing enter after each. What I didn’t know was that WordPress, even in HTML mode, was adding <br /> tags after I pressed enter, causing this problem.
Solution: Make the <img> tags back to back on the same line, thus removing the automatically generated <br /> tags.