A smarter vending machine
Creating a connected drinks vending machine using a dumb dispenser machine, Crossbar.io, the Autobahn libraries and a Raspberry Pi.
Vending machines are simple¶
Vending machines are simple. You put in some coins, select the product you want, and the machine spits it out. That's the way it's been since the beginning.
Vending machines are complicated¶
Vending machines can be complicated:
- You don't have any coins
- You have coins, but the machine doesn't accept them
- The machine is out of change, and you don't have the precise amount
- The machine is out of the product you want
- The machine is just isn't working at all
That's just the customer perspecive.
Things aren't any easier for the operator.
The operating company's vending machines are usually spread across a large number of locations. There is no feedback about their state (fill level, or even whether they are operational) unless they send somebody there, or an enraged customer calls.
This means that refills and checks mostly occur at set intervals instead of when needed. There is no way to know what to bring for a refill before getting to the machine - which means transporting too much or too little product around on the refill tour. The only feedback about what was bought are the empty slots. You can't tell whether a slot has been empty for most of the interval between refills or got emptied just a few minutes ago. Cash brings it own set of problems: The mechanisms inside the machines which validate coins are prone to breaking. Handling coins is both a pain and, increasingly, really expensive. When coins get stuck, people hit and shake the machine to dislodge tehm, often damaging the machine. There's also a non-trivial chance that somebody will try to crack the machine and get away with the coins.
Why the interest in vending machines?¶
As customers, we at Crossbar.io never really thought about the operator perspective. Recently, however, a friend approached us about this issue. He runs a small business which delivers drinks and operates quite a few drinks vending machines. Our friend was looking for a way to upgrade the vending experience for the customers and make things much easier for his company.
We immediately thought that this would be a great Internet of Things/Industrial Internet showcase. It takes an everyday process and improves it dramatically for all participants. We also thought that this could be realized with relatively little effort.
The benefits of a fully connected drinks vending machine?
For the consumer there are some real benefits:
- check availability of drinks before going to the machine
- reserve drinks before going to the machine
- much higher change of desired drink actually being available
- no cash needed
For the operator the improvements are even bigger:
- real-time data on fill levels allows smart replenishment (bring exactly what's needed at a time when it best fits)
- purchasing history allows analytics on customers' demands and optimization of the choice of drinks offered
- change prices in real-time to ceate flexible pricing models (e.g. sales to get rid of stock shortly before a refill)
- less maintenance because of fewer moving parts on the dispenser (no order buttons, display or coin validator)
To get the above benefits, we wanted to get rid of as many moving parts as possible. That meant no coin validator as well as moving the interface to the customers' smartphones (no display, no buttons). We naturally wanted to use our technologies (Crossbar.io, WAMP, the Autobahn libraries) for connectivity.
For the rest, it was to be a learning experience for all involved. We at Crossbar.io are software developers. We've programmed quite a few demos using the devices such as the Raspberry Pi, Arduino Yun and Tessel, plus some hardware add-ons. This, however, was the first time we worked on something including hardware which was to be tried and used under real-life conditions.
Why do this ourselves?¶
Before we get into the details, there's the question of why we should do this ourselves at all. There are connected vending machines out there. I haven't seen one yet, but commercial solutions do exist.
These machines are expensive, however, and all use proprietary services for the data collection. They also have limited feature sets and are non-extensible. Doing things ourselves allows us to tailor the feature set to what's actually needed and have a basis for experimentation. It gives the operator the freedom to try things out.
Our friend brought us this drink dispenser.
It's compact, easy to refill (just roll the cans across the top) and well suited for use e.g. in an office or hackerspace. It's also a hell of a lot easier to transport than the classic vending machine (can be carried by two and fits in a regular car). What it isn't is an actual vending machine, i.e. it just dispenses drinks to anybody without restrictions.
This meant that we had to start from scratch in adapting the hardware for this purpose. While it's always nice to start with a clean slate, this meant we had to design a locking mechanism. We eventually settled on an external locking mechanism for the two slots - and found somebody who could build this for us just based on a rough idea.
The mechanism allows remote unlocking of a slot, and has sensors to detect the unlock and a can being taken from the slot. We also added a couple of sensors to detect refilling of the dispenser.
As a controller we picked our IoT Starter Kit (surpise!), which is basically a Rasperry Pi with some displays/LEDs and a breadboard in a nice custom case. The Pi is hardly ever the ideal solution for anything, but it does a lot of things well enough, it's easily available and there is a great community around it. This to us beats specialized solutions which are hard to get and have no support any time, at least for the prototyping stage.
On the software side we are using Crossbar.io and WAMP to connect the components in our application. Since connection establishment is from the components to Crossbar.io, we don't need to worry about open ports on the controller for the dispenser (so this won't easily become part of a botnet).
WAMP also allows us to trigger the dispense process with a routed remote procedure call to the controller and to receive progressive results for the different stages of the process - unlike with the pure PubSub protocols where getting to the same functionality is highly non-trivial.
There is a WAMP component on the Pi which offers a "dispense_product" procedure as its core, as well as procedures to get machine info and fill levels, and which publishes events about what's happening with the dispenser.
Two frontends running in the browser allow customers to check the fill level and request a drink, and suppliers to get information about the dispenser and purchases.
Last there's a backend component which persists customer information and translates events from the dispenser into those required by the frontends. (What we learned while developing the software may become the topic of a future blog post.)
Where we're at¶
What we have right now is a showcase, suited for use at workshops, in hackerspaces or offices where there is a limited amount of users and where these are generally trustworthy. The locking mechanism is only weakly protected and the dispenser itself is in no way vandal-proof.
The dispenser case is strongly branded, and filled with Crossbar.io-branded energy drinks (tastes a lot like the most famous energy drink on the planet).
We as the operators can get fill level, purchase history and an estimate for the refill time on a Web page.
Consumers can log on to a special Web page running on our demo Crossbar.io instance in the cloud, making this accessible without the need to share a wi-fi network with the dispenser. The page displays the fill level and allows the request of a free drink.
Free drinks are allocated based on a voucher code that the user enters. We sponsor the drinks for the time being - so this is, at the moment, strikly a promotion tool. The feedback from people we've demonstrated it to has been very positive so far, the full branding really attracts attention - and whe have something much less abstract to show than just a piece of "messaging-oriented middleware".
Standard use works fine, but there are definitely still corner-cases that the software doesn't handle properly. As usual, what appeared entirely trivial turned out to have some hidden depths.
It's been a great learning experience, with some insights into the difficulties of developing actual IoT applications. The project highlights the fact that today it's possible again to innovate and prototype in machines without a million-dollar R&D budget.
We are going to deploy the dispenser to a coworking space around the corner from our office in the coming weeks, and see how it works in practice. There's hope that in the course of getting it ready for this there'll also be time for some code and API cleanup.
There are many ways to modify and extend this.
Integration of cashless payment would expand the use cases. Integrating PayPal is one option, but really limits the circle of potential users, at least here in Germany.
Contactless payment cards and mobile wallets are being pushed hard in Germany (and elsewhere) at the moment and are certainly a possibility going forward.
For the time being, we are happy to have this as a showcase, and to send it as an ambassador for Crossbar.io to coworking and hacker spaces.
As for our friend who started the entire project - we are working on a second machine for him which he can use for his own tests. He is glad to have a technical basis for his future experiments, and he'll add a different perspective again, that of the professional operator. We're curious about his feedback.
We started with a dumb dispenser and added all the necessary parts for an initial promotional deployment. The dispenser can be operated and monitored via Web pages, and things so far work as expected. As usual, things turned out to be more complex than intended, but the dispenser is a great showcase for our technology, for the benefits of the IoT and for how modern technology enables the modern wave of makers. We live indeed in exciting times, and we're glad to be part of the current technological revolution.