Created
March 15, 2016 05:57
-
-
Save shyampurk/82c470572445065b98f7 to your computer and use it in GitHub Desktop.
Smart Trash Can Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def distanceMeasurement(): | |
prev_distance = 0 | |
while 1: | |
ultrasonicSensor_init() | |
time.sleep(2) | |
GPIO.output(TRIG, True) | |
time.sleep(0.00001) | |
GPIO.output(TRIG, False) | |
#Starts the timer | |
while GPIO.input(ECHO)==0: | |
pulse_start = time.time() | |
#Waits for the timer to end once the pin is high | |
while GPIO.input(ECHO)==1: | |
pulse_end = time.time() | |
pulse_duration = pulse_end - pulse_start | |
distance = pulse_duration * 17150 | |
distance = round(distance, 2) | |
if(prev_distance != distance and prev_distance > (distance+3) or prev_distance < (distance-3)): | |
prev_distance = distance | |
mqttc.publish("garbaseData", "{\"container\":\""+GARBAGE_ID+"\",\"level\":"+str(distance)+"}") | |
print "Distance:",distance,"cm" | |
GPIO.cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def on_message(client, userdata, msg): | |
message = dict() | |
message = json.loads(msg.payload) | |
print pubnub.publish(channel="garbageApp-resp", message=message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment