The Smart Tea Machine is a simple demonstration of how Ethereum can be integrated into a device especially devices like Bolt IoT. It shows the relative ease and simple code that can be used to have basic functionality in a standard machine without display.
The main idea of this project is to make a machine that can be used with Ethereum.
The Existing old tea machine is used to prove the concept.***
A standard old tea machine has been modified to be controlled by a Bolt IoT WiFi Module with a 5v Relay. The Bolt IoT WiFi Module can directly on the dispensing 5V DC Pump inside the Tea machine for a Tea. The Bolt IoT WiFi Module connects over WiFi to a Bolt Cloud and a python program with an Ethereum Node and checks regularly to see if a new transaction has appeared at the address. When it finds one, it wakes the Tea machine and dispenses a Tea.
Flow diagramBuy electronic components with free shipping on utsource.net
Opening the Old Tea MachineNow that the machine is open we are going to solder 2 wire to the DV Pump. As you can see in the image above.
Bolt IoT ConnectionThe connections between the Relay and BoltIoT are:
- Bolt IoT PIN0: Relay IN
- Bolt IoT 5v: Relay Vcc
- Bolt IoT Gnd: Relay Gnd
- Bolt IoT 5v: Relay Com
- Relay NO: DC Pump(+)
- Bolt IoT Gnd: DC Pump(-)
The final wiring for the project looks a bit messy but worked just fine.
After it was all wired up, We just test it out with a basic on-off program and then proceeded to check that the relay was firing.
Ethereum is an open-source, public, blockchain-based distributed computing platform and operating system featuring smart contract functionality. It supports a modified version of the Nakamoto consensus via transaction-based state transitions.
Read More - https://www.coindesk.com/learn/ethereum-101/what-is-ethereum
What is an Ethereum wallet?Wallets are applications that make it easy to hold and send ETH, as well as interact with applications built on Ethereum.
I am using MetaMask Wallet for this project
To see how to create an account in MetaMask Wallet, go to https://metamask.io/
In order to test this Machine, you will also need a personal wallet. I had used Ropsten Test Network for testing. To collect free ETH for your personal wallet, I recommend checking these links:
Registering to an RPC node (Infura)In order to interact with the Ethereum blockchain, an RPC node exposing API is needed. In this example, we’ll be using https://infura.io that offers this service for free. Register to their website and note your API key.
Web3.pyWeb3.py is a python library for interacting with Ethereum. Its API is derived from the Web3.js Javascript API and should be familiar to anyone who has used web3.js
.
1. Install Web3.py using pip:
pip install web3
2. Install Bolt Python library using pip:
pip install boltiot
3. Run this python code.
import time
import decimal
from web3 import Web3
from boltiot import Bolt
api_key = "xxx15dxxx-xxxx-xxxx-xxxx-xxx1f7dfxxxx" # Your Bolt Cloud API key
device_id = "BOLTxxxxxx" # Bolt device id that you want to control
# Fill in your infura API key here
infura_url = "https://ropsten.infura.io/v3/xxx642xxx2exxxxxx571xxxf47ff0xxx"
web3 = Web3(Web3.HTTPProvider(infura_url))
print(web3.isConnected())
#print(web3.eth.blockNumber)
# Fill in your account here
success = False
preBal = 0
# Script actually runs continuously with 5 sec intervel
while True:
# API method to check balance
balance_m = web3.eth.getBalance("0xbD4B0a62a4Ab49D442A7fF6aD9DAE924569AD695")
balance = (web3.fromWei(balance_m, "ether"))
# response['balances'] is a list!
if web3.isConnected():
#print('Found the following information for address ' + str(my_address) + ':')
#print('Balance: ' + str(response['balances'][0]) + 'i')
current_balance = balance
print('Balance: ' + str(balance) + 'eth')
add_amt = decimal.Decimal('0.1')
if current_balance == preBal+add_amt:
print("Recived 0.1eth, processing in 1 seconds...")
preBal = current_balance
#mybolt = Bolt(api_key, device_id)
#response = mybolt.digitalWrite('1', 'HIGH')
#print(response)
#response = mybolt.digitalWrite('1', 'LOW')
#print(response)
mybolt = Bolt(api_key, device_id)
response = mybolt.digitalWrite('0', 'HIGH')
print(response)
time.sleep(15) # Wait for 15 seconds
response = mybolt.digitalWrite('0', 'LOW')
print(response)
success = True
else:
preBal = current_balance
else:
print('Not online checking after 30 sec')
time.sleep(30) # Pause for 30 sec.
time.sleep(5)
After the user has transferred the ETH, and if its get Confirmed by the network. It will automatically check for the amount received and will on the DC pump for the fixed time to dispense the Tea.
You can see the source code on google colab-
https://colab.research.google.com/drive/1H1Q1XAtlU13WIvqdNXVLyC9x0qjlc-Xu
(Unfortunately, it's not working with google colab)
Putting It All TogetherFinally, it was time to power on the Bolt IoT WiFi Module and check all the routines are working as per plan.
**Validating the ETH cantake a couple of seconds**.
You can see the transaction on etherscan.io- https://ropsten.etherscan.io/tx/0xbd34d864355cbcb5025fa1f64e3a1f603528c8205b270ac5baab58e9b7a135fb
We are done!
I hope this gives you an idea of how you might go about integrating Ethereum with Bolt IoT WiFi Module.
Let me know if you have any questions!!
Comments
Please log in or sign up to comment.