Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Ricardo Reis
Published

Bitcoin-Powered Coffee Maker

I built a Bitcoin-powered coffee machine to show how cryptocurrency can be used as actual programmable money.

BeginnerFull instructions provided1 hour4,426
Bitcoin-Powered Coffee Maker

Things used in this project

Story

Read more

Schematics

1_3oojhkxvnowohudjxumfyw1_M0509pHD7B.png

Code

1.php

PHP
Monitoring bitcoin address...
<?php 
session_start();
if(!isset($_SESSION['val'])){
  exec("gpio -g mode 18 pwm && gpio pwm-ms && gpio pwmc 192 && gpio pwmr 2000");
}
function inicio(){
	exec('gpio -g pwm 18 240');
	}
inicio();
?>
<html>

<a href="2.php">Testar</a> 
	
<img src="https://chart.googleapis.com/chart?chs=250x250&cht=qr&chl=1MEdoDvBbcGL2GduaDEzzfn1CPWW3D64Bk">
<br>
1MEdoDvBbcGL2GduaDEzzfn1CPWW3D64Bk
<div id="websocket">Monitorando o endereço 1MEdoDvBbcGL2GduaDEzzfn1CPWW3D64Bk e aguardando pagamento...</div>

<script>
var btcs = new WebSocket("wss://ws.blockchain.info/inv");
btcs.onopen = function (){
	btcs.send(JSON.stringify({"op":"addr_sub", "addr":"1MEdoDvBbcGL2GduaDEzzfn1CPWW3D64Bk"}));
};
btcs.onmessage = function (onmsg){
	var response =JSON.parse(onmsg.data);
	console.log(response);
	var getOuts = response.x.out;
	var countOuts = getOuts.length;
	
	for(i=0; i<countOuts; i++){
		var outAdd = response.x.out[i].addr;
		var address = "1MEdoDvBbcGL2GduaDEzzfn1CPWW3D64Bk";
		if(outAdd == address){
			var amount = response.x.out[i].value;
			var calAmount = amount / 100000000;
			document.getElementById("websocket").innerHTML = "Recebido: "+ calAmount+"BTC";
			window.location.href = "2.php";
		};
	};
};
</script>
</html>

2.php

PHP
Address received bitcoin? Then, start the engine.
<?php 
session_start();
if(!isset($_SESSION['val'])){
  exec("gpio -g mode 18 pwm && gpio pwm-ms && gpio pwmc 192 && gpio pwmr 2000");
}
function giraMotor(){
	  exec('gpio -g pwm 18 60');
}
giraMotor();
?>
<html>
	<p>Ok! PAGAMENTO RECEBIDO E MOTOR ACIONADO</p>
	
	<script>
	setTimeout(function(){window.location.href = "1.php";}, 1000);
	</script>
</html>

Credits

Ricardo Reis

Ricardo Reis

2 projects • 19 followers

Comments