Using Parse for IoT to Create an Order Button

The Blog

Amazon announced the Dash button, a small device with a single button and a single purpose: Pressing the button orders an item on Amazon. This is just the latest in the continuing trend toward connected smart devices, and we immediately saw the possibilities for our developer community to create devices for their own apps. Feeling inspired to experiment, we spent half an hour with an Arduino Yún, a push button, and the new Parse for IoT SDK to create a device that simulates ordering toilet paper when we’re running low. As you’ll see here, it’s amazingly simple to build a working order button that connects to your app using Parse tools. Here’s how we did it:

We connected a push button to the Arduino and used a small breadboard so the button would sit neatly on top of the Arduino. As you’ll see later, we used the Arduino’s packaging as an enclosure.

IMG_2266

The code on the Arduino is as simple as it gets. You can find the full sketch file in the Github repo, but here’s the meat of it. It just calls a Cloud Function:

// Send request to parse from the Arduino Yùn
ParseCloudFunction cloudFunction;
cloudFunction.setFunctionName(“orderToiletPaper”);
ParseResponse response = cloudFunction.send();
response.close();

Deployed in Cloud Code, we have this bit of JavaScript. It makes a request to theShopify store we created, to order some toilet paper.

// Define the 'orderToiletPaper' Cloud Function
Parse.Cloud.define("orderToiletPaper", function(request, response) {
var shopifyAppId = 'your-shopify-app-id';
var shopifyAppPassword = 'your-shopify-app-password';
var shopifyStoreName = 'your-shopify-store-name';
var shopifyURL = 'https://' + shopifyAppId + ':' + shopifyAppPassword + '@' + shopifyStoreName + '.myshopify.com/admin/orders.json';
Parse.Cloud.httpRequest({
url: shopifyURL,
method: 'POST',
headers: { 'Content-Type' : 'application/json' },
body: {
order: {
email: 'matt@parse.com',
send_receipt: true,
line_items: [
{ title: 'Parse Toilet Paper', id: 443357149, quantity: 1, price: 0.00 }
]
}
}
}).then(function(data) {
response.success('Ordered some TP.');
}, function(error) {
response.error(error);
});
});

Some of our industrial designers and materials engineers used our state-of-the-art facility to create a truly beautiful product that you can’t help but fall in love with. As you can imagine, we used nothing but the latest technologies to create this masterpiece:

making

The next time we’re running out of toilet paper, you can be sure it will be promptly refilled with another cloud-soft roll.

IMG_2272

Taking this example further, you could associate devices with user accounts, fully integrate with Shopify or another API (or build your own!) and offer a premium push-button experience for people using your app. You can find the full source on our Github repository, but most of it is already in this blog post. The whole app is less than 100 lines of code!

We’re excited about the possibilities of Parse for IoT, including order buttons and much more. Let us know what you build!

Advertisements

Author: iotmaker

I am interested in IoT, robot, figures & leadership. Also, I have spent almost every day of the past 15 years making robots or electronic inventions or computer programs.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s