Published © Apache-2.0

Smart Prepaid Refrigerators

Come forward to see the prepaid refrigerators which is working on the basis of the IOTA protocol.

IntermediateFull instructions provided3 hours895
Smart Prepaid Refrigerators

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Solid State Relay
Solid State Relay
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian
IOTA Tangle
IOTA Tangle

Story

Read more

Schematics

Circuit

For wiring

Code

code

Python
import time
import datetime
import RPi.GPIO as GPIO

# Imports the PyOTA library
from iota import Iota
from iota import Address

# Setup O/I PIN's
relay=12
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(relay,GPIO.OUT)
GPIO.output(relay,GPIO.LOW)

# Function for checking address balance on the IOTA tangle. 
def checkbalance():

    print("Checking balance")
    gb_result = api.get_balances(address)
    balance = gb_result['balances']
    return (balance[0])

# URL to IOTA fullnode used when checking balance
iotaNode = "https://nodes.thetangle.org:443"

# Create an IOTA object
api = Iota(iotaNode, "")

# IOTA address to be checked for new device funds 

address = [Address(b'XXXXXXXXXXQCTSQBZEEMLZPQUPAA9LPLGWCKFNEVKBINXEXZRACVKKKCYPWPKH9AWLGJHPLOZZOYTALAWOVSIJIYVZ')]

# Get current address balance at startup and use as baseline for measuring new funds being added.   
currentbalance = checkbalance()
lastbalance = currentbalance

# Define some variables
balance = 0
balcheckcount = 0
status = False

# Main loop that executes every 1 second
while True:
    
    # Check for new funds and add to balance when found.
    if balcheckcount == 10:
        currentbalance = checkbalance()
        if currentbalance > lastbalance:
            balance = balance + (currentbalance - lastbalance)
            lastbalance = currentbalance
        balcheckcount = 0

    # Manage device balance and device ON/OFF
    if balance > 0:
        if  status == False:
            print("ON")
            GPIO.output(relay,GPIO.HIGH)
            status=True
        balance = balance -1       
    else:
        if  status == True:
            print("OFF")
            GPIO.output(relay,GPIO.LOW)
            status=False
 
    # Print remaining device balance     
    print(datetime.timedelta(seconds=balance))

    # Increase balance check counter
    balcheckcount = balcheckcount +1

    # Pause for 1 sec.
    time.sleep(1)

Credits

Comments