LOGIN
Sai Prasad
30
Community Expert
Software Dev :) Let's build some dream ideas.
 · BhubaneswarIndia
Share
Report
Get Link
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.

5 likes 
Like
Award Contribution
Load 6 previous comments
Sai Prasad
30
Community Expert
Software Dev :) Let's build some dream ideas.
 · BhubaneswarIndia
Share
Report
Get Link

@Abhi Verma can i get the python script please?

Like
2 likes 
Award Contribution
Abhi Verma
42
Community Expert
ROBOToTHON 2017 Mentor, Electronics Engineer (Project Leader)
 · DelhiIndia
Share
Report
Get Link

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()




Like
1 like 
Award Contribution
Sai Prasad
30
Community Expert
Software Dev :) Let's build some dream ideas.
 · BhubaneswarIndia
Share
Report
Get Link

Thank you Abhi Verma

Like
1 like 
Award Contribution
Abhi Verma
42
Community Expert
ROBOToTHON 2017 Mentor, Electronics Engineer (Project Leader)
 · DelhiIndia
Share
Report
Get Link

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.

Like
1 like 
Award Contribution
Abhi Verma
42
Community Expert
ROBOToTHON 2017 Mentor, Electronics Engineer (Project Leader)
 · DelhiIndia
Share
Report
Get Link

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

Like
1 like 
Award Contribution
Sai Prasad
30
Community Expert
Software Dev :) Let's build some dream ideas.
 · BhubaneswarIndia
Share
Report
Get Link

Ok … I’ll add these to the app …

Like
1 like 
Award Contribution
Leave a reply...
DISCOVER
CHAT
HIRE
ACTIVITY
FEED
New Post
Help
Start Project
Online Users
Share Link
Write something before you submit it!
Photo updated
Request Sent!
Updated
Copied to Clipboard