I’ve mentioned a couple of times it would be interesting if we could create a case in salesforce.com by pressing something like a Staples “Easy” button. So I did it using a Raspberry Pi and an Easy Button. Turns out, it’s not that hard. I did it with a standard Developer Edition and a couple of Node.js libraries.
Bill of Materials
- Adafruit Raspberry Pi Starter Kit ($104.95)
- Staples Easy Button ($5.99, $6.99 in the stores with the fancy gift box you see in the video.)
- Optional: WiFi dongle for your Raspberry Pi. ($11.95)
Approach
I started by following my standard Raspberry Pi configuration steps. This created a simple environment where I could work with Node.js.
Next, I wanted to find the right library to help me work with the Raspberry Pi’s GPIO board. There are a few out there, and they all have one challenge: you can only use the GPIO if you are a superuser. The most popular library appears to be “pi-gpio“. It requires “gpio-admin” to work around the superuser requirement, but it didn’t seem to fail in a friendly way when I didn’t have gpio-admin, so I kept looking (note, this may not be pi-gpio’s fault). I came across “GpiO“. GpiO inherits the same superuser requirements, but if doesn’t require gpio-admin and offers some additional approaches, including gpio-admin. I did a quick test, which succeeded, so I moved on.
Next, I wanted to review a bit about how to connect a button on a Raspberry Pi. Now, buttons are pretty easy at their core. You press one, and it completes a circuit. But there’s always a little wiring required. Adafruit has a great learning section which describes the basic hardware configuration in detail. I also needed to double check how to configure an LED. Unsurprisingly, they have that as well. My simple adaptation is below. Note that I used a spare half-sized breadboard rather than the full-sized one that comes with the kit. The button connects to pin 23, the LED to pin 24.
The sample code Adafruit shows you is in Python. Nothing wrong with Python. However, I was thinking Node.js, which means I couldn’t use Adafruit’s example. No problem, I figured, there are great examples on the Github repos.
I then started to wonder about the best way to integrate with salesforce.com. There are a lot of ways, but I wanted to do the simplest thing that could possibly work and so landed on “Web to Case.” Not a universally perfect approach, but it’s easy to get started (in fact, I simply used the default configuration), and it led me to the useful request library which you’ll see I’ve used below.
My final code is pretty simple. I import a couple of libraries, declare a couple of gpio variables for specific pins, and have a request with form data that’s fired off.
var gpio = require("gpio"); var request = require("request"); function sendWebToCase() { var fields = { 'orgid': '00DU0000000YYhQ', 'name': 'Reidberry Carlberg', 'email': 'reid.carlberg@gmail.com', 'phone': '773-870-5554', 'subject': 'Auto case submission', 'description': 'Here is the detail -- we could also send a log' }; var r = request.post('https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8', { form: fields }, function (error, response, body) { console.log(body); } ); } function flashLed(led, state) { led.set(state); if (state == 1) { setInterval(function() { flashLed(led, 0); }, 5000); } } var gpio23 = gpio.export(23, { direction: "in", ready: function() { } }); var gpio24 = gpio.export(24, { direction: "out", ready: function() { } }); gpio23.on("change", function(val) { // value will report either 1 or 0 (number) when the value changes console.log("23" + val); if (val == 0) { sendWebToCase(); flashLed(gpio24,1); } });
That’s it! All that was left was to modify the Easy button.
There are quite a few guides on line on how to hack the Easy button–turns out this has been popular the entire time it’s been around. Most of them require some kind of soldering and circuit modification (example), which to my mind was unnecessary. The button itself has several parts: a speaker, battery case, some weights, a piece of metal to make that clicking sound, a small circuit board and the actual button.
The only think I really care about is the button. As I said earlier, all a button does is complete a circuit, right? If that’s the case, I wondered, why couldn’t I just add a new circuit? I started by covering the existing circuit with plain old tape, put on two new wires that would form the new circuit and taped them in place. Voila! The button is now mine, no soldering required.
Now, about that gift box. Turns out it is just about the perfect size to contain all these guts. Just about. I had to turn the Raspberry Pi case upside down, stack the breadboard on top of it, and feed the power supply through a special hole I added, but it worked.
Conclusions, Questions & Opportunities
Overall, I’m glad I did this, but I’m not convinced I have landed on the perfect solution just yet. I find myself wondering if an Electric Imp wouldn’t be a better choice. I also have an Arduino Yun that, with its smaller form factor, is an appealing option. Finally, I wonder how useful the Web to Case approach really is. It certainly creates Cases, which is the point, but it’s very one-way. It would be super interesting to to have some sort of bi-directional communication so the button could display the status of the case, or so that the initial case creation could include a richer set of data. This also begs the question of whether cases should move to a completely data-driven predictive model requiring zero human intervention, but that my friends is a subject for another day.
Questions, comments — I’d love to hear em. @ReidCarlberg