Skip to content

Instantly share code, notes, and snippets.

@vindolin
Created January 4, 2014 10:18
Show Gist options
  • Save vindolin/8253815 to your computer and use it in GitHub Desktop.
Save vindolin/8253815 to your computer and use it in GitHub Desktop.
import android
from sendmail import sendemail
from sys import stdout
from time import sleep
trapped = False
image_path = '/sdcard/cat.jpg'
counter = 0
mail_tpl = '''
Batterie Level: %(battery)s%%
Empfangsstaerke: %(gsm)s%%
'''
BT_DEVICE_ID = '00:12:03:09:05:18'
#BT_DEVICE_ID = None # open the device selection popup
droid = android.Android()
droid.wakeLockAcquirePartial()
last_sms_count = droid.smsGetMessageCount(True).result
print 'sms count: %s' % last_sms_count
droid.toggleBluetoothState(True) # turn on bluetooth
print droid.bluetoothConnect('00001101-0000-1000-8000-00805F9B34FB', BT_DEVICE_ID)
print droid.bluetoothGetConnectedDeviceName()
def get_phone_info():
result = {}
droid.batteryStartMonitoring()
droid.startTrackingSignalStrengths()
sleep(1)
result['battery'] = droid.batteryGetLevel().result
result['gsm'] = droid.readSignalStrengths().result['gsm_signal_strength'] * 100 / 31
droid.batteryStopMonitoring()
droid.stopTrackingSignalStrengths()
return result
def send_mail():
droid.cameraCapturePicture(image_path)
mail = mail_tpl % get_phone_info()
sendemail('[email protected]', 'vindolin', '*******', '[email protected]', 'trapped!', mail, ['/sdcard/cat.jpg'])
while True:
if not trapped and droid.bluetoothReadReady().result is True:
stdout.write(droid.bluetoothRead().result)
#print droid.bluetoothReadline().result
send_mail()
trapped = True
now_sms_count = droid.smsGetMessageCount(True).result
if now_sms_count != last_sms_count:
send_mail()
last_sms_count = now_sms_count
sleep(1)
counter += 1
print counter
droid.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment