Skip to content

Commit

Permalink
Added Controls over MQTT Protocol and Added Required Micropython File…
Browse files Browse the repository at this point in the history
…s for ESP32
  • Loading branch information
abhimanyus1997 committed Apr 2, 2019
1 parent 068d602 commit 260341b
Show file tree
Hide file tree
Showing 21 changed files with 809 additions and 519 deletions.
76 changes: 76 additions & 0 deletions 01pir_final.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import network
import ure
import time
from machine import Pin, PWM
import ubinascii
import machine
import micropython
import umqtt_simple
from umqtt.simple import MQTTClient

#connecting to hotspot
ssid = "whotspot"
ssid_password = "manumanu"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid,ssid_password)

# Direction Pin of Motor1 assuming value=1 as forward
m1_dir = Pin(2, Pin.OUT, value=1)

# MQTT Broker IP
server="192.168.137.160"

# Received messages from subscriptions will be delivered to this callback
def sub_cb(topic, msg):
#print((topic, msg))
msgDecoded=msg.decode("utf-8") #Converts Byte Data into UTF-8 Strings
#Using Micropython RegEXP lib to seperate data
#where data[0] denotes Direction and data[1] denotes Speed
sep = ure.compile("-") # Delimiter is "-"
data = sep.split(msgDecoded)
print("Direction:",data[0],"\t Speed:",data[1],"\t State:",data[2])
if data[0] == "w":
#m1_dir.value(1)
motor(1,int(data[1]),int(data[2]))
elif data[0] == "s":
#m1_dir.value(0)
motor(0,int(data[1]),int(data[2]))
else:
#m1_dir.value(0)
motor(0,0) #Frequency Becomes zero so motor stops


def pircontrol(server="192.168.137.160"):
c = MQTTClient("esp32_pir_mqttClient", server)
c.set_callback(sub_cb)
c.connect()
c.subscribe(b"esp32/control")
while True:
if True:
# Blocking wait for message
c.wait_msg()
else:
# Non-blocking wait for message
x=c.check_msg()

# Then need to sleep to avoid 100% CPU usage (in a real
# app other useful actions would be performed instead)
time.sleep(1)
c.disconnect()

def motor(dir,speed,state,duty_cycle=750):
stepper1 = PWM(Pin(2), freq=speed, duty=duty_cycle)
if state==0:
stepper1.deinit()
else:
stepper1 = PWM(Pin(2), freq=speed, duty=duty_cycle)
direction1 = Pin(4, Pin.OUT, value=dir)
# if speed==0:
# stepper1.deinit()
# direction2 = Pin(4, Pin.OUT, value=dir)
# direction3 = Pin(4, Pin.OUT, value=dir)


if __name__ == "__main__":
pircontrol()
50 changes: 50 additions & 0 deletions pir_wifi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
def connect(ssid=None,ssid_password=None):
import network
if ssid is None:
ssid = "whotspot"
print('Error!!: Invalid Credentials Provided')
print('Using Default SSID')
if ssid_password is None:
ssid_password = "manumanu"
print('Using Default WIFI Authentication Password...')
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('Connecting to network...')
wlan.connect(ssid,ssid_password)
while not wlan.isconnected():
pass
print("\n****Connection Successful****")
print('Network config:', wlan.ifconfig())

def disconnect():
import network
print('Disconnecting...')
wlan = network.WLAN(network.STA_IF)
if not wlan.isconnected():
print('Warning: Already Disconnected!')
else:
wlan.disconnect()
print('\n****Disconnected Successfully****')

#def update(pkg=None):
# import network, upip
# if not network.WLAN(network.STA_IF).isconnected():
# print('Error!!: Connect to Internet')
# else:
# if pkg is None:
# pkg=["micropython-uasyncio","micropython-pkg_resources","picoweb","utemplate","micropython-ulogging"]
# print("Warning!:No Library name provided.")
# i=0
# while i<len(pkg):
# print("\n"+"Updating Default Library: "+pkg[i])
# upip.install(pkg[i])
# i+=1
# print("\n****Library update successful****")
# else:
# print("Updating Library: "+pkg)
# upip.install(pkg)




Large diffs are not rendered by default.

Binary file modified platforms/android/app/build/outputs/apk/debug/app-debug.apk
Binary file not shown.
15 changes: 7 additions & 8 deletions platforms/android/app/src/main/assets/www/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@
<body>


<section id="team" class="text-center section">
<section id="team" class="text-center section mt-2">
<div class="container">
<h2><span class="highlight_secondary">Our</span> Team</h2>
<h2><span class="highlight_secondary">Team</span> Members</h2>

<h4>
Our people are our greatest asset and biggest differentiator.<br>They also believe in having a lot of
fun along the way.
Development of Pipe Inspection and Cleaning Robot Prototype
</h4>

<div class="hr big_size_hr invisible_hr">
Expand Down Expand Up @@ -73,14 +72,14 @@ <h4>
<div class="team-name"><a href="#">
<h5>Abhimanyu Singh</h5>
</a></div>
<div class="team-role">Co-founder</div>
<div class="team-role">Developer</div>
<div class="team-description m3"></div>
</div><!-- /.team-content -->
</div><!-- /.team -->
</div>
<br>
<!-- MEMEBER-2 -->
<div class="col-md-3 col-sm-10">
<div class="col-md-3 col-sm-10 mt-4">
<div class="team">
<div class="team-image">
<a href="#">
Expand All @@ -103,7 +102,7 @@ <h5>Abhimanyu Singh</h5>
<div class="team-name"><a href="#">
<h5>Lakshya Maleti</h5>
</a></div>
<div class="team-role">Co-founder</div>
<div class="team-role">Co-Developer</div>
<div class="team-description m-3"></div>
</div><!-- /.team-content -->
</div><!-- /.team -->
Expand Down Expand Up @@ -134,7 +133,7 @@ <h5>Lakshya Maleti</h5>
<div class="team-name"><a href="#">
<h5>Vaibhav Agarwal</h5>
</a></div>
<div class="team-role">Co-founder</div>
<div class="team-role">Co-Developer</div>
<div class="team-description m3"></div>
</div><!-- /.team-content -->
</div><!-- /.team -->
Expand Down
47 changes: 47 additions & 0 deletions platforms/android/app/src/main/assets/www/img/broken-link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 7 additions & 40 deletions platforms/android/app/src/main/assets/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,56 +59,27 @@
</nav>

<!-- CONTROLLER BELOW -->

<!-- <div class="col-md-3 col-sm-2">
<table class="table table-borderless">
<tbody>
<tr>
<td></td>
<td><a class="btn btn-lg px-3 btn-none btn-outline-success" href="#" role="button"><img
src="res/dpad/001-up-arrow.svg" style="width: 100%;height: 100%" alt="up"></a></td>
<td></td>
</tr>
<tr>
<td><a class="btn btn-lg px-3 btn-none btn-outline-success" href="#" role="button"><img
src="res/dpad/003-back.svg" style="width: 100%;height: 100%" alt="left"></a></td>
<td></td>
<td><a class="btn btn-lg px-3 btn-none btn-outline-success" href="#" role="button"><img
src="res/dpad/002-next.svg" style="width: 100%;height: 100%" alt="right"></a></td>
</tr>
<tr>
<td></td>
<td><a class="btn btn-lg px-3 btn-none btn-outline-success" href="#" role="button"><img
src="res/dpad/004-down-arrow.svg" style="width: 100%;height: 100%" alt="down"></a>
</td>
<td></td>
</tr>
</tbody>
</table>
</div> -->

<div class="container mt-4 mb-4">
<div class="row">
<div class="col-xs-3 col-2 mt-2 ml-1"><button type="button" class="btn btn-warning btn-circle btn-xl"><img src="img/outline-keyboard_arrow_up-24px.svg" alt=""></button></div>
<div class="col-xs-3 col-2 mt-2 ml-1"><button type="button" class="btn btn-warning btn-circle btn-xl" id="fwdBtn"><img src="img/outline-keyboard_arrow_up-24px.svg" alt=""></button></div>
<div class="col-xs-3 col-2 mt-2 ml-1"></div>
<div class="col-xs-5 col-3 mt-2"><button type="button" class="btn btn-block btn-raised ripple-effect btn-danger ">STOP</button></div>
<div class="col-xs-5 col-4 mt-2"><button type="button" class="btn btn-block btn-raised ripple-effect btn-danger" id="motorStopBtn">STOP</button></div>
</div>
<div class="row">
<div class="col-xs-3 col-2 mt-1 mb-2 ml-1"><button type="button" class="btn btn-warning btn-circle btn-xl"><img src="img/outline-keyboard_arrow_down-24px.svg" alt=""></button></div>
<div class="col-xs-3 col-2 mt-1 mb-2 ml-1"><button type="button" class="btn btn-warning btn-circle btn-xl" id="bckBtn"><img src="img/outline-keyboard_arrow_down-24px.svg" alt=""></button></div>
<div class="col-xs-3 col-2 mt-2 ml-1"></div>
<div class="col-xs-5 col-4 mt-2"><button type="button" class="btn btn-block btn-raised ripple-effect btn-success">START</button></div>
<div class="col-xs-5 col-4 mt-2"><button type="button" class="btn btn-block btn-raised ripple-effect btn-success" id="motorStartBtn">START</button></div>
</div>
</div>
<hr> <hr>
<div class="col-md-3 col-sm-2 mx-auto">
<label for="customRange1">PWM Speed Control</label>
<input type="range" class="custom-range" id="customRange1" data-toggle="tooltip" min="0" max="1750" step="50">
<input type="range" class="custom-range" id="pwmRange" data-toggle="tooltip" min="0" max="1000" step="20">
<p id="demo"></p>
</div>


<!-- SENSOR DATA -->
<br>
<div class="border border-primary rounded-3 mt-4 mx-2 p-2 w-80" id="sensor">
<code>Data Streaming</code>
<br>
Expand All @@ -124,7 +95,7 @@
<tbody>
<tr>
<th scope="row">1</th>
<td>Obstacle Sensor</td>
<td>Obstacle Detection</td>
<td>0 m</td>
<td><button type="button"
class="btn btn-circle btn-flat btn-success btn-xs disabled nohover">ok</button>
Expand All @@ -147,11 +118,7 @@


</div>






<script type="text/javascript" src="cordova.js"></script>
<!-- <script type="text/javascript" src="lib/framework7/js/framework7.min.js"></script> -->
<script type="text/javascript" src="js/my-app.js"></script>
Expand Down
Loading

0 comments on commit 260341b

Please sign in to comment.