Vending Machine/Cashless Device Implementation: Difference between revisions

From Nottinghack Wiki
Jump to navigation Jump to search
m Category
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==Versions==
We now have two versions of the custom cashless device:
# v1 - created for the [[Vending Machine/Westomatic|Westomatic]] vending machine, and uses a [http://wiki.london.hackspace.org.uk/view/Project:Nanode nanode] and RDM880 based RFID module, and is build mostly on perf board.
# v2 - created for the [[Vending Machine/BevMax45|BevMax45]] vending machine, and is heavily based on v1, but now uses a custom PCB with a SAM D21 MCU (same as the Arduino Zero), a WizNet Ethernet shield and a MFRC522 RFID reader. There is an aim to update the first vending machine to use a v2 cashless device, but as of Dec 2018, this hasn't been done yet.
==Hardware==
==Hardware==
===v1===
The cashless device has been built around a [http://wiki.london.hackspace.org.uk/view/Project:Nanode nanode], which is connected using UDP/IP over an Ethernet connection to [[holly]].
The cashless device has been built around a [http://wiki.london.hackspace.org.uk/view/Project:Nanode nanode], which is connected using UDP/IP over an Ethernet connection to [[holly]].


Line 5: Line 11:


The nanode is connected (using software serial) to an [http://www.skpang.co.uk/catalog/1356mhz-rfid-module-ios14443a-p-1000.html RFID reader] mounted under the 'H' logo on the outside of the Vending machine.
The nanode is connected (using software serial) to an [http://www.skpang.co.uk/catalog/1356mhz-rfid-module-ios14443a-p-1000.html RFID reader] mounted under the 'H' logo on the outside of the Vending machine.
There is also a micro-switch attached to the coin-reject mechanism (to allow any RFID card read to be cleared from memory), and a blue LED above the reader to indicate when a card has been read & recognised.  
There is also a micro-switch attached to the coin-reject mechanism (to allow any RFID card read to be cleared from memory), and a blue LED above the reader to indicate when a card has been read & recognised. An LCD to show your username & current balance was added in July 2013.
 
Firmware for this device is in [https://github.com/NottingHack/instrumentation-arduino/tree/master/Vend GitHub].


The diagram below shows the connection between devices:<br />
The diagram below shows the connection between devices:<br />
[[File:vend_devices.png]]
[[File:vend_devices.png]]


==UDP Messages==
===v2===
To keep things simple, the UDP/IP interface to [[holly]] is text based; the sequence of messages is shown in the flowchart below:<br />
The second cashless device uses a [https://github.com/NottingHack/nv-vend-PCB cutom PCB] using the SAM D21 MCU (as used in the Arduino Zero), and has numerous changes, including:
* A MFRC522 RFID module, which is the same as the [[NoteAcceptor]], [[Nhtools|tools boards]], etc., instead of a RDM880 based module
* Uses TCP/IP to connect to a Mosquitto MQTT broker on [[holly]] instead of UDP/IP. The messages sent remain the same.
* A serial based setup menu, to allow for entry of device name, IP, etc. This should allow the same firmware to be used unmodified in both machines.
 
[[File:vend_pcb.jpg|350px]]
[[File:vend_pcb2.jpg|350px]]
[[File:cashless_device2_display.jpg|350px]]
 
Firmware for this version is also in [https://github.com/NottingHack/instrumentation-arduino/tree/master/Vend2 GitHub].
 
 
==Messages==
To keep things simple, the interface to [[holly]] is text based; the sequence of messages is shown in the flowchart below:<br />
[[File:vend_messages.png|350px]]
[[File:vend_messages.png|350px]]
For v1, these messages are sent using UDP/IP, for v2 they use MQTT, transmitting on the <code>nh/<device_id>/tx</code> topic and receiving on the <code>nh/<device_id>/rx</code> topic. Not an ideal implementation for MQTT by a long way, but reuses a message flow that's been working well for some years.


===Message details===
===Message details===
Line 32: Line 55:
|VM||Holly||<code>VSUC:''<RFID serial>'':''<transaction number>'':''<position>''</code><br />Sent after the VMC reports to the nanode that the product has been successfully vended.
|VM||Holly||<code>VSUC:''<RFID serial>'':''<transaction number>'':''<position>''</code><br />Sent after the VMC reports to the nanode that the product has been successfully vended.
|-
|-
|VM||Holly||<code>VFAL:''<RFID serial>'':''<transaction number>''</code><br />Sent if the VMC reports that the vend failed. ***UNTESTED***. Not sure if our vending machine can/would ever report a failed vend.
|VM||Holly||<code>VFAL:''<RFID serial>'':''<transaction number>''</code><br />Sent if the VMC reports that the vend failed. ***UNTESTED*** for the [[Vending Machine/Westomatic|Westomatic]] machine, as we don't beleive the  machine can/would ever report a failed vend. The [[Vending Machine/BevMax45|BevMax45]] ''can'' report failed vends (if enabled on the machine), but due to a fault with the drop sensors, it was reporting every vend as failed, so this has been switched off.
|-
|-
|VM||Holly||<code>VCAN:''<RFID serial>'':''<transaction number>''</code><br /> Sent if the coin reject button is pressed. Will record a cancelled vend if an AUTH has been sent, but no VREQ yet received - otherwise it has no effect.
|VM||Holly||<code>VCAN:''<RFID serial>'':''<transaction number>''</code><br /> Sent if the coin reject button is pressed. Will record a cancelled vend if an AUTH has been sent, but no VREQ yet received - otherwise it has no effect.
Line 60: Line 83:


==Source Code==
==Source Code==
Source code for the firmware running on the Nanode is in the [https://github.com/NottingHack/Vend github] repo, the code of the server side component is on [http://code.google.com/p/nottinghack-instrumentation/source/browse/ Google code] (the relevant part is "nh-vend.cpp").
The code of the server side component is on [https://github.com/NottingHack/instrumentation Github] (the relevant part is [https://github.com/NottingHack/instrumentation/blob/master/cpp/nh-vend.cpp nh-vend.cpp]). This code is common to both v1 & v2 of the cashless device, and also handles payments received via the [[NoteAcceptor]] & [[CoinAcceptor]].


[[Category:Projects]]
[[Category:Projects]]
[[Category:Projects (complete)]]
[[Category:Instrumentation]]
[[Category:Instrumentation]]
[[Category:Network]]
[[Category:Infrastructure]]
[[Category:Vending machine]]
[[Category:Software]]

Latest revision as of 16:20, 24 February 2019

Versions

We now have two versions of the custom cashless device:

  1. v1 - created for the Westomatic vending machine, and uses a nanode and RDM880 based RFID module, and is build mostly on perf board.
  2. v2 - created for the BevMax45 vending machine, and is heavily based on v1, but now uses a custom PCB with a SAM D21 MCU (same as the Arduino Zero), a WizNet Ethernet shield and a MFRC522 RFID reader. There is an aim to update the first vending machine to use a v2 cashless device, but as of Dec 2018, this hasn't been done yet.

Hardware

v1

The cashless device has been built around a nanode, which is connected using UDP/IP over an Ethernet connection to holly.

There is a board between the Nanode (see Media:VMC-Nanode Schematic.png) and the vending machine which both powers the nanode from the ~34vdc supply, and allows serial communication with the VMC.

The nanode is connected (using software serial) to an RFID reader mounted under the 'H' logo on the outside of the Vending machine. There is also a micro-switch attached to the coin-reject mechanism (to allow any RFID card read to be cleared from memory), and a blue LED above the reader to indicate when a card has been read & recognised. An LCD to show your username & current balance was added in July 2013.

Firmware for this device is in GitHub.

The diagram below shows the connection between devices:

v2

The second cashless device uses a cutom PCB using the SAM D21 MCU (as used in the Arduino Zero), and has numerous changes, including:

  • A MFRC522 RFID module, which is the same as the NoteAcceptor, tools boards, etc., instead of a RDM880 based module
  • Uses TCP/IP to connect to a Mosquitto MQTT broker on holly instead of UDP/IP. The messages sent remain the same.
  • A serial based setup menu, to allow for entry of device name, IP, etc. This should allow the same firmware to be used unmodified in both machines.

Firmware for this version is also in GitHub.


Messages

To keep things simple, the interface to holly is text based; the sequence of messages is shown in the flowchart below:

For v1, these messages are sent using UDP/IP, for v2 they use MQTT, transmitting on the nh/<device_id>/tx topic and receiving on the nh/<device_id>/rx topic. Not an ideal implementation for MQTT by a long way, but reuses a message flow that's been working well for some years.

Message details

From To Details
VM Holly AUTH:<RFID serial>
Sent when RFID card first read
Holly VM GRNT:<RFID serial>:<transaction number>
Sent in response to AUTH if the card is known & marked as active in the database.
Holly VM DENY:<RFID serial>
Sent in reply to AUTH if the card is either not know, or marked as expired/canceled.
VM Holly VREQ:<RFID serial>:<transaction number>:<amount>
Sent when a selection is keyed in. <amount> is in pence.
Holly VM VNOK:<RFID serial>:<transaction number>
Sent in response to VREQ if the purchase is permitted (e.g. credit limit won't be exceeded).
Holly VM VDNY:<RFID serial>:<transaction number>
Sent in response to VREQ is the vend should be denied for any reason.
VM Holly VSUC:<RFID serial>:<transaction number>:<position>
Sent after the VMC reports to the nanode that the product has been successfully vended.
VM Holly VFAL:<RFID serial>:<transaction number>
Sent if the VMC reports that the vend failed. ***UNTESTED*** for the Westomatic machine, as we don't beleive the machine can/would ever report a failed vend. The BevMax45 can report failed vends (if enabled on the machine), but due to a fault with the drop sensors, it was reporting every vend as failed, so this has been switched off.
VM Holly VCAN:<RFID serial>:<transaction number>
Sent if the coin reject button is pressed. Will record a cancelled vend if an AUTH has been sent, but no VREQ yet received - otherwise it has no effect.
VM Holly INFO:<debug message>
Information message that can be sent at any stage - has no effect other than being written to a log on holly.
Variable Description
<RFID serial> RFID serial number - expected to be 9 digits long
<transaction number> Unique number assigned to the vending machine transaction when an AUTH message is received with an active RFID serial, and must be included in all related messages.
<position> Position in the vending machine as reported by the VMC. Note that this location is mapped to the locations codes displayed in the vending by holly (e.g. 41-31 reported here corresponds to location A1).

Example session

(card presented)
AUTH:999999999
GRNT:999999999:352
(Selection made)
VREQ:999999999:352:300
VNOK:999999999:352
(Product vended)
VSUC:999999999:352:43-37

Source Code

The code of the server side component is on Github (the relevant part is nh-vend.cpp). This code is common to both v1 & v2 of the cashless device, and also handles payments received via the NoteAcceptor & CoinAcceptor.