Esempio n. 1
0
	def authorize(self, subaddr):
		gsm.at_connect(self.PROXY_IP, self.USERNAME, self.PASSWORD)
		auth = get_auth(gsm.CNUM, "", b'26485001') # Retrieve a server nonce
		self.at_start_http_session()
		server_nonce = yield from self.http_action("GET", self.url(subaddr), time=self.timestamp(), auth=auth) # Retrieve servernonce
		auth = get_auth(gsm.CNUM, server_nonce, b'42849900')

		return auth
Esempio n. 2
0
	def configure(self):
		""" Daily configuration call. gsm.at_id() must be performed, as well as at_connect """

		gsm.at_connect(self.PROXY_IP, self.USERNAME, self.PASSWORD)
		auth = get_auth(gsm.CNUM, "", b'26485001') # Retrieve a server nonce
		# urc add event "CONNECT OK"
		self.at_start_http_session()
		server_nonce = yield from self.http_action("GET", self.url("conf"), time=self.timestamp(), auth=auth) # Retrieve servernonce

		auth = get_auth(gsm.CNUM, server_nonce, b'42849900')
		# urc event del and if everything worked out fine,
		# Obtain configuration
		conf = yield from self.http_action("GET", self.url("conf"), time=self.timestamp(), auth=auth)

		self.at_terminate_http_session() # TODO: folded with individual requests or like this?

		self.at_disconnect()

		self.track_location = parse_conf("track_location", conf)
		self.track_state = parse_conf("track_state", conf)
		self.measure_ms = parse_conf("measure_interval", conf)
		self.stream_ms = parse_conf("stream_interval", conf)
		self.fixed_state_track = = parse_conf("fixed_state_track", conf)
		self.verbose = parse_conf("verbose", conf)
Esempio n. 3
0
def configure():
	get_event_loop().run_until_complete(gsm.at_connect(PROXY_IP, USERNAME, PASSWORD))
	auth = get_auth(gsm.CNUM, "", b'26485001')
	get_event_loop().run_until_complete(gsm.start_http_session(PROXY_IP))
	server_nonce = yield from gsm.http_action("GET", url(server_url, port, "conf"), time=timestamp(), auth=auth)
	get_event_loop().run_until_complete(gsm.terminate_http_session())
	auth = get_auth(gsm.CNUM, server_nonce, b'42849900')

	get_event_loop().run_until_complete(gsm.start_http_session(PROXY_IP))
	conf = yield from gsm.http_action("GET", url(server_url, port, "conf"), time=timestamp(), auth=auth)

	get_event_loop().run_until_complete(gsm.terminate_http_session())
	get_event_loop().run_until_complete(gsm.at_disconnect())

	# Parse configuration settings
	if conf:
		track_location = parse_conf("track_location", conf)
		track_state = parse_conf("track_state", conf)
		measure_ms = parse_conf("measure_interval", conf)
		stream_ms = parse_conf("stream_interval", conf)
		fixed_state_track = parse_conf("fixed_state_track", conf)
		verbose = parse_conf("verbose", conf)
Esempio n. 4
0
def stream(stream_ms):
	while True:
		yield from sleep(stream_ms)
		print("Authorizing...")
		auth = get_auth(gsm.CNUM, "", b'26485001')
		get_event_loop().call_soon(gsm.at_connect(PROXY_IP, USERNAME, PASSWORD))
		print("Preauth: %s" %auth)
		print("Initializing HTTP session...")
		get_event_loop().call_soon(gsm.start_http_session(PROXY_IP))
		print("Retrieving server nonce...")
		get_event_loop().call_soon(gsm.start_http_session(PROXY_IP))
		server_nonce = yield from gsm.http_action("GET", url(server_url, port, "stream"), time=timestamp(), auth=auth)
		print("Possible server nonce: %s" %server_nonce[:])
		if server_nonce and not "CME" in server_nonce:
			print("Succesfully obtained server nonce %s" %server_nonce)
			auth = get_auth(gsm.CNUM, server_nonce, b'42849900')
		else:
			print("Unable to obtain server nonce")

		print("Stopping.")
		get_event_loop().call_soon(gsm.terminate_http_session())

		print("Running production authorization.")
		coords = "test"
		state = "test"
		data = '{"auth":%s, %s, ' %(auth, coords)
		if track_state:
			data += '"state":%s, ' %state
		data += '"time":%s}' %(timestamp())
		print(data)
		print("Posting location data...")

		get_event_loop().call_soon(gsm.start_http_session(PROXY_IP))
		post = yield from gsm.http_action("POST", url(server_url, port, "stream"), data=data)
		get_event_loop().call_soon(gsm.terminate_http_session())
		get_event_loop().call_soon(gsm.at_disconnect())