Randika Silva
Published

IOTA Powered Remote Accessible Power Relay

This cellular IoT power relay is IOTA supported and users can recharge the wallet in order to turn on their electric appliances.

IntermediateFull instructions provided20 hours4,387
IOTA Powered Remote Accessible Power Relay

Things used in this project

Hardware components

Ideamart Smart Power Socket
×1
GreenPAK™ Dialog 4G SIM Card
×1

Software apps and online services

Ideamart IoT portal
IOTA Tangle
IOTA Tangle

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set
Extraction Tool, 6 Piece Screw Extractor & Screwdriver Set

Story

Read more

Schematics

Backside of Enclosure

There are holes for AC in and out

Printed Circuit Board of Power relay

This is based Ideamart IoT development board

Front side of Enclosure

There are holes for the antennas and LED indicators

Code

IOTA Python code for Power Relay

Python
# Imports some Python Date/Time functions and json
import time
import datetime
import json
import urllib2
  
# Imports the PyOTA library
from iota import Iota
from iota import Address
  
# 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 light funds 
# IOTA addresses can be created using the IOTA Wallet
address = [Address(b'GTZUHQSPRAQCTSQBZEEMLZPQUPAA9LPLGWCKFNEVKBINXEXZRACVKKKCYPWPKH9AWLGJHPLOZZOYTALAWOVSIJIYVZ')]
# Get current address balance at startup and use as baseline for measuring new funds being added.   
currentbalance = checkbalance()
lastbalance = currentbalance
# Define some variables
lightbalance = 0
balcheckcount = 0
relaystatus = False
  
req = urllib2.Request('https://iotdev.dialog.lk/axt-iot-mbil-instance0001001/apkios/axtitomblebckendde/iotadmindev/device')
req.add_header('Content-Type', 'application/json')
  
# Main loop that executes every 1 second
while True:
   # Check for new funds and add to relaybalance when found.
   if balcheckcount == 10:
       currentbalance = checkbalance()
       if currentbalance > lastbalance:
           relaybalance = relaybalance + (currentbalance - lastbalance)
           lastbalance = currentbalance
       balcheckcount = 0
   # Manage light balance and light ON/OFF
   if lightbalance > 0:
       if relaystatus == False:
           print("ON")
           data = {"operation":"deviceControl","deviceId":"PM-321","actionName":"actionOne", "actionParameters" : {"ac1Value1":"on"}}
            esponse = urllib2.urlopen(req, json.dumps(data))
           relaytstatus=True
       relaybalance = relaybalance -1       
   else:
       if relaystatus == True:
           print("OFF")
           data = {"operation":"deviceControl","deviceId":"PM-321","actionName":"actionOne", "actionParameters" : {"ac1Value1":"off"}}
            esponse = urllib2.urlopen(req, json.dumps(data))
           relaystatus=False
   # Print remaining light balance     
   print(datetime.timedelta(seconds=relaybalance))
   # Increase balance check counter
   balcheckcount = balcheckcount +1
   # Pause for 1 sec.
   time.sleep(1)

Credits

Randika Silva

Randika Silva

4 projects • 22 followers
An Electronic Engineer from Sri Lanka.

Comments