Monday, 4 August 2014

Python Script for Location Updates

Below is a simple python script to automate location updates to the emulator.

# Karun Matharu (ksm113@imperial.ac.uk)
# Imperial College London
# A simple python telnet script to connect to the emulator on
# localhost 5554 and issue geo fix commands
import sys
import telnetlib
import getpass
import time
import random
HOST = "localhost"
PORT = 5554
TIMEOUT = 2
# Sleep time between each location update
TIME_GAP = 4
# Starting values for longitude and latitude
lon = 50.000000
lat = 50.000000
tn = telnetlib.Telnet(HOST, PORT, TIMEOUT)
print tn.read_some()
while (True):
a = random.random()
b = random.random()
lat = lat + a
lon = lon + b
s = "geo fix " + str(lon) + " " + str(lat) + "\n"
tn.write(s)
print(s)
time.sleep(TIME_GAP)
view raw gistfile1.py hosted with ❤ by GitHub

0 comments:

Post a Comment