Darko Vranesa
Published © MIT

Electric Bicycle Monitoring and Signaling

Now when I leave my bike parked, I will know if someone moves it. Using sensors in IoT kit to detect motion and send signal to me.

IntermediateWork in progress5 hours358

Things used in this project

Story

Read more

Schematics

E bike NXP Rapid IOT studio

Code

E bike firmware

C/C++
Bin file, you must upload it to NXP rapid IOT
No preview (download only).

E bike source code

C/C++
No preview (download only).

Phyton scripts py4

Python
Place on RPI3
# Using NXP IOT with Python
import pexpect
import time
import struct

# PUT YOUR DEVICE ADRESS HERE 
 
DEVICE = "00:60:37:0A:AF:96"
 
#print("NXP IOT address:"),
#print(DEVICE)
 
# Run gatttool interactively.
#print("Run gatttool...")
child = pexpect.spawn("gatttool -I -b 00:60:37:0A:AF:96")
 
# Connect to the device.
#print("Connecting to "),
#print(DEVICE)
child.sendline("connect")
child.expect("Connection successful", timeout=30)
#print("Connection successful"),
child.sendline("characteristics")
child.expect("handle:", timeout=30)
#print("Read temp. characteristics ")
 
# function to transform hex string like "0a cd" into signed integer
def hexStrToInt(hexstr):
 val = int(hexstr[0:2],16) + (int(hexstr[3:5],16)<<8)
 if ((val&0x8000)==0x8000): # treat signed 16bits
     val = -((val^0xffff)+1)
 return val


# Termometer
child.sendline("char-read-hnd 0x0023")
child.expect("Characteristic value/descriptor: ", timeout=10)
child.expect("\r\n", timeout=10)
#print("Temperature (hex): "),
#print(child.before)
#print((child.before)[0:2])
#print((child.before)[3:5])
#print((child.before)[6:8])
#print((child.before)[9:11])
str=((child.before)[0:2])+((child.before)[3:5])+((child.before)[6:8])+((child.before)[9:11])
#print(str)
bin_str = str.encode('utf-8')
temp_float_value=struct.unpack('<f',bin_str.decode('hex'))[0]
temp_float_value = (round(temp_float_value, 1))
print(temp_float_value)
 

Phyton scripts py5

Python
# Using NXP IOT with Python
import pexpect
import time
import struct
# PUT YOUR DEVICE ADRESS HERE 
DEVICE = "00:60:37:0A:AF:96"
 
#print("NXP IOT address:"),
#print(DEVICE)
 
# Run gatttool interactively.
#print("Run gatttool...")
child = pexpect.spawn("gatttool -I -b 00:60:37:0A:AF:96")
 
# Connect to the device.
#print("Connecting to "),
#print(DEVICE)
child.sendline("connect")
child.expect("Connection successful", timeout=30)
#print("Connection successful"),
child.sendline("characteristics")
child.expect("handle:", timeout=30)
#print("Read temp. characteristics ")
 
# function to transform hex string like "0a cd" into signed integer
def hexStrToInt(hexstr):
 val = int(hexstr[0:2],16) + (int(hexstr[3:5],16)<<8)
 if ((val&0x8000)==0x8000): # treat signed 16bits
     val = -((val^0xffff)+1)
 return val


# Hygrometer
child.sendline("char-read-hnd 0x0026")
child.expect("Characteristic value/descriptor: ", timeout=10)
child.expect("\r\n", timeout=10)
#print("Temperature (hex): "),
#print(child.before)
#print((child.before)[0:2])
#print((child.before)[3:5])
#print((child.before)[6:8])
#print((child.before)[9:11])
str=((child.before)[0:2])+((child.before)[3:5])+((child.before)[6:8])+((child.before)[9:11])
#print(str)
bin_str = str.encode('utf-8')
hyg_float_value=struct.unpack('<f',bin_str.decode('hex'))[0]
hyg_float_value = (round(hyg_float_value, 1))
print(hyg_float_value)
 

Node red flow

Textile
Node red flow for RPI
[{"id":"94252b5e.069b28","type":"exec","z":"2bcc0f5b.bb3f5","command":"python2 /home/pi/4.py","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":320.5,"y":150.5,"wires":[["9bd2251c.833d38","8ade71d1.185c4","82b9d06.11d803"],[],[]]},{"id":"a1eac40e.a5d6f8","type":"inject","z":"2bcc0f5b.bb3f5","name":"","topic":"","payload":"","payloadType":"date","repeat":"20","crontab":"","once":true,"onceDelay":"2","x":108,"y":150,"wires":[["94252b5e.069b28"]]},{"id":"9bd2251c.833d38","type":"debug","z":"2bcc0f5b.bb3f5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":524,"y":73,"wires":[]},{"id":"8ade71d1.185c4","type":"ui_gauge","z":"2bcc0f5b.bb3f5","name":"","group":"4edbae19.8239b","order":1,"width":0,"height":0,"gtype":"gage","title":"Temeprature","label":"degrees","format":"{{value}}","min":"0","max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":553,"y":137,"wires":[]},{"id":"82b9d06.11d803","type":"ui_chart","z":"2bcc0f5b.bb3f5","name":"","group":"4edbae19.8239b","order":2,"width":"0","height":"0","label":"chart temperature","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":true,"ymin":"20","ymax":"30","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":570,"y":223,"wires":[[],[]]},{"id":"87f4c3f6.e73fd","type":"exec","z":"2bcc0f5b.bb3f5","command":"python2 /home/pi/5.py","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":310,"y":366,"wires":[["ecc2553.14a83a8","853b098b.b8ff78","53ed0dbd.6a0494"],[],[]]},{"id":"4026e648.1cf6e8","type":"inject","z":"2bcc0f5b.bb3f5","name":"","topic":"","payload":"","payloadType":"date","repeat":"20","crontab":"","once":true,"onceDelay":"12","x":97.5,"y":365.5,"wires":[["87f4c3f6.e73fd"]]},{"id":"ecc2553.14a83a8","type":"debug","z":"2bcc0f5b.bb3f5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":513.5,"y":288.5,"wires":[]},{"id":"853b098b.b8ff78","type":"ui_gauge","z":"2bcc0f5b.bb3f5","name":"","group":"4edbae19.8239b","order":3,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"%","format":"{{value}}","min":"0","max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":532.5,"y":352.5,"wires":[]},{"id":"53ed0dbd.6a0494","type":"ui_chart","z":"2bcc0f5b.bb3f5","name":"","group":"4edbae19.8239b","order":4,"width":"0","height":"0","label":"chart humidity","chartType":"line","legend":"true","xformat":"HH:mm:ss","interpolate":"step","nodata":"","dot":true,"ymin":"0","ymax":"100","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":true,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":549.5,"y":438.5,"wires":[[],[]]},{"id":"4edbae19.8239b","type":"ui_group","z":"","name":"Sensors","tab":"448a83db.86803c","order":1,"disp":true,"width":"6","collapse":false},{"id":"448a83db.86803c","type":"ui_tab","z":"","name":"NXP rapid IOT","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

Credits

Darko Vranesa

Darko Vranesa

2 projects • 4 followers

Comments