Ricardo Reis
Published © GPL3+

Coke Vending Machine with Bitcoin and Lightning Network

A Coca-Cola machine accepting Bitcoin via the Lightning Network.

IntermediateFull instructions provided2 hours4,436
Coke Vending Machine with Bitcoin and Lightning Network

Things used in this project

Story

Read more

Schematics

circuito_PjtV29iqFx.jpg

Code

index.html

HTML
<html>
<head>
	<script src="https://js.pusher.com/4.3/pusher.min.js"></script>
	<script>
    // Enable pusher logging - don't include this in production
    Pusher.logToConsole = true;
    var pusher = new Pusher('18d514638e535062bd73', {
      cluster: 'us2',
      forceTLS: true
    });
    var channel = pusher.subscribe('my-channel');
    channel.bind('my-event', function(data) {
		window.location = "payment_received.html";
      //alert(JSON.stringify(data));
    });
  </script>
</head>
<body style="margin:0px; padding:0px">
<img onclick="window.location = 'payment_received.html';" src="qr.png" />
</body>
</html>

payment_received.html

HTML
<html>
<head>
	 <script src="jquery-3.3.1.min.js"></script>
</head>
<body style="margin:0px; padding:0px">
<video autoplay>
  <source src="coke.mp4" type="video/mp4">
</video>
<script>
	$.ajax({
	  url: "start_pump.php",
	  success: function() {
		setTimeout(function(){stopPump()}, 20000); 
	  }
});
function stopPump(){
	$.ajax({
		url: "stop_pump.php",
		success: function() {
			window.location = "index.html";
		}
	});
}
	</script>
</body>
</html>

start_pump.php

PHP
<?php
 $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
 $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1");
 ?>

stop_pump.php

PHP
<?php
  $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out");
  $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0");
?>

notification.php

PHP
<?php
echo 'oi';
  require __DIR__ . '/vendor/autoload.php';
  $options = array(
    'cluster' => 'us2',
    'useTLS' => true
  );
  $pusher = new Pusher\Pusher(
    '18d514638e535062bd73',
    '625eb4b95d5aa0d53c0b',
    '610995',
    $options
  );
  $data['message'] = 'BTCPAY say: Hey Raspberry, a payment was received. Please, deliver Coca to the customer!';
  $pusher->trigger('my-channel', 'my-event', $data);
?>

Credits

Ricardo Reis

Ricardo Reis

2 projects • 19 followers

Comments