Skip to content

Commit

Permalink
Logs Feature Added
Browse files Browse the repository at this point in the history
  • Loading branch information
vishal-pandey committed Jul 16, 2020
1 parent 90d8d83 commit 7716d95
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 13 deletions.
Binary file modified airtrik/__pycache__/iot.cpython-37.pyc
Binary file not shown.
36 changes: 36 additions & 0 deletions airtrik/iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
import os
import requests



welcome_message = """
█████╗ ██╗██████╗ ████████╗██████╗ ██╗██╗ ██╗ ██╗ ██████╗ ████████╗ ██████╗██╗ ██████╗ ██╗ ██╗██████╗
██╔══██╗██║██╔══██╗╚══██╔══╝██╔══██╗██║██║ ██╔╝ ██║██╔═══██╗╚══██╔══╝ ██╔════╝██║ ██╔═══██╗██║ ██║██╔══██╗
███████║██║██████╔╝ ██║ ██████╔╝██║█████╔╝ ██║██║ ██║ ██║ ██║ ██║ ██║ ██║██║ ██║██║ ██║
██╔══██║██║██╔══██╗ ██║ ██╔══██╗██║██╔═██╗ ██║██║ ██║ ██║ ██║ ██║ ██║ ██║██║ ██║██║ ██║
██║ ██║██║██║ ██║ ██║ ██║ ██║██║██║ ██╗ ██║╚██████╔╝ ██║ ╚██████╗███████╗╚██████╔╝╚██████╔╝██████╔╝
╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═════╝
"""


apiEndPoint = "https://airtrik.com/iot/"
logsEndPoint = "https://airtrik.com/api/logs/"
client = mqtt.Client()
AIRTRIK_key = ""

Expand All @@ -13,6 +28,9 @@
def connect(key):
global AIRTRIK_key
global client
global IS_CONNECTED
if IS_CONNECTED:
return

AIRTRIK_key = key

Expand All @@ -34,6 +52,7 @@ def connect(key):
client.tls_insecure_set(True)
client.username_pw_set(username, password)
client.connect("airtrik.com", 8883, 60)
IS_CONNECTED = True


def onConnect():
Expand Down Expand Up @@ -66,5 +85,22 @@ def subscribe(deviceId):
client.loop_start()


def logs(key=0):
if key == 0:
key = AIRTRIK_key
payload = {'key': key}
res = requests.post(logsEndPoint, data=payload)
return res.text


def waitForMessage():
try:
print(welcome_message)
# print("Waiting for message.")
while True:
pass
except KeyboardInterrupt:
print()
print("Disconnecting...")
print("Good Luck !!")
return
21 changes: 9 additions & 12 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import airtrik.iot as iot

device1 = "bulb"
device2 = "fan"
device = "bulb"

def onConnect():
print("Connected To Network")
# print(iot.logs())

def onReceive(deviceId, message):
if deviceId == device1:
print(device1, message)
if deviceId == device2:
print(device2, message)
print(device, message)


iot.onConnect = onConnect
iot.onReceive = onReceive

iot.connect("__APP_KEY__")
iot.subscribe(device1)
iot.subscribe(device2)
iot.subscribe(device)

# iot.waitForMessage()
# print(iot.logs())
iot.waitForMessage()


while True:
msg = input("Enter The Message to send\n")
iot.send(device1, msg)
# while True:
# msg = input("Enter The Message to send\n")
# iot.send(device, msg)
3 changes: 3 additions & 0 deletions publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source env/bin/activate
python setup.py sdist bdist_wheel
twine upload dist/*
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="airtrik",
version="0.1.1",
version="0.1.2",
author="Vishal Pandey",
author_email="[email protected]",
description="Connect IoT Devices to cloud and manage from anywhere.",
Expand Down

0 comments on commit 7716d95

Please sign in to comment.