LOGIN
Sai Prasad
Student
 · BhubaneswarIndia
Edit
Delete
Share
Report
IDEA

Initial app paper design… please do check it out and suggest some changes if need to improve the app. This is for android for now…!

Contributions
Sai Prasad

Initial app paper design created by Sai. Great work here.

added by:   Steven Reubenstone
5 likes 
Like
Share
Load 6 previous comments
Sai Prasad
Student
 · BhubaneswarIndia
Edit
Delete
Share
Report

@Abhi Verma can i get the python script please?

2 likes 
Abhi Verma
Electronics Engineer (Project Leader)
 · GhaziabadIndia
Edit
Delete
Share
Report

Sai Prasad here is the script.

#!/usr/bin/python
from time import sleep
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
import serial
import tkinter
from tkinter import *
root = Tk()
root.title("IOT AUTOMATION by ABHINAV VERMA")
root.geometry("1080x768")
var = StringVar()
var0 = StringVar()
var1 = StringVar()
var2 = StringVar()
var3 = StringVar()
var0.set("LED not connected")
var1.set("Light not connected")
var2.set("Fan not connected")
var3.set("TV not connected")
def arduino_connect():
   try:
       arduino.close()
       arduino.open()
   except serial.SerialException as e:
       print('IOT Device not found.')
   except TypeError as e:
       print('Unable to connect IOT device. Please Retry.')
   else:
       print('IOT Device connected.')
   return;
   
l = 1
while l==1:
   try:
       arduino = serial.Serial('COM7',115200,timeout=2)
   except serial.SerialException as e:
       print('IOT Device not found.')
       l=0
       sleep(2)
   except TypeError as e:
       print('Unable to connect IOT device. Please Retry.')
       l=0
       sleep(2)
   else:
       arduino.isOpen()
       print('IOT Device connected.')
       l=0
someurl = "http://api.thingspeak.com/channels/85291/fields/1.json?results=1"
req = Request(someurl)
while True:
   label = Label( root, textvariable=var)
   led = Message( root, textvariable=var0, relief=RAISED )
   light = Message( root, textvariable=var1, relief=RAISED )
   fan = Message( root, textvariable=var2, relief=RAISED )
   tv = Message( root, textvariable=var3, relief=RAISED )
   try:
       html=urlopen(someurl).read()
       response = urlopen(req)
   except HTTPError as e:
       print('The server couldn\'t fulfill the request.')
       print('Error code: ', e.code)
       print('Retrying in 10 seconds')
       var.set("The server couldn\'t fulfill the request. \n Retraying in 10 seconds")
   except URLError as e:
       print('We failed to reach a server.')
       print('Reason: ', e.reason)
       print('Retrying in 10 seconds')
       var.set("Failed to connect. Check your internet connection")
   else:
       var.set("Connected")
       url = "http://api.thingspeak.com/channels/85291/fields/3.json?results=1"
       html=urlopen(url).read()
       l = len(html)
       print(html)
       print(l)
       if(html[l-5]==72):
           try:
               arduino.write('H'.encode())
           except serial.SerialException as e:
               print("IOT Device Disconnected. Please check.")
               var.set("IOT Device Disconnected. Please check.")
               arduino_connect()
           except TypeError as e:
               print('IOT Device not working. Replug the Device.')
               var.set('IOT Device not working. Replug the Device.')
               arduino_connect()
           else:
               print('LED ON')
               var0.set("LED ON")
       if(html[l-5]==76):
           try:
               arduino.write('L'.encode())
           except serial.SerialException as e:
               print("IOT Device not connected")
               arduino_connect()
           except TypeError as e:
               print('Type error Device not connected')
               arduino_connect()
           else:
               print('LED OFF')
               var0.set("LED OFF")
   label.grid(columnspan=8,sticky=W)
   led.grid(row=1)
   light.grid(row=1,column=1)
   fan.grid(row=1, column=3)
   tv.grid(row=1, column=2)
   root.update_idletasks()
   root.update()
   sleep(1)
   label.destroy()
   led.destroy()
   light.destroy()
   fan.destroy()
   tv.destroy()




1 like 
Sai Prasad
Student
 · BhubaneswarIndia
Edit
Delete
Share
Report

Thank you Abhi Verma

1 like 
Abhi Verma
Electronics Engineer (Project Leader)
 · GhaziabadIndia
Edit
Delete
Share
Report

your welcome. anyways you have to change the channel id. i,m using this channel in something important so don’t want to mixup things. i’ll create new channel and will inform you here.

1 like 
Abhi Verma
Electronics Engineer (Project Leader)
 · GhaziabadIndia
Edit
Delete
Share
Report

Channel id - 196166
Write API Key - AWWVKKKG7M1KUAC9
Rest API request - GET https://api.thingspeak.com/update?api_key=AWWVKKKG7M1KUAC9&field1=0

Read Field request - GET https://api.thingspeak.com/channels/196166/fields/1.json?results=1

1 like 
Sai Prasad
Student
 · BhubaneswarIndia
Edit
Delete
Share
Report

Ok … I’ll add these to the app …

1 like 
Leave a reply...
DISCOVER
CHAT
ALERTS
-2
DISCUSSIONS
-1
FEED