-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
39 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,42 @@ | ||
import requests | ||
import os | ||
import json | ||
import socket | ||
import time | ||
from cryptography.fernet import Fernet | ||
|
||
class WearableDevice: | ||
def __init__(self, device_id, device_token): | ||
self.device_id = device_id | ||
self.device_token = device_token | ||
class Wearable: | ||
def __init__(self, wearable_id, wearable_secret, home_id, home_secret): | ||
self.wearable_id = wearable_id | ||
self.wearable_secret = wearable_secret | ||
self.home_id = home_id | ||
self.home_secret = home_secret | ||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
self.socket.connect(('localhost', 8080)) | ||
|
||
def authenticate_transaction(self, transaction_id): | ||
# Make a request to the wearable API to authenticate the transaction | ||
response = requests.get(f'https://wearable-api.com/transactions/{transaction_id}', headers={'Authorization': f'Bearer {self.device_token}'}) | ||
return response.json() | ||
def send_data(self, data): | ||
self.socket.send(data.encode()) | ||
|
||
def get_user_data(self): | ||
# Make a request to the wearable API to retrieve user data | ||
response = requests.get(f'https://wearable-api.com/users/{self.device_id}', headers={'Authorization': f'Bearer {self.device_token}'}) | ||
return response.json() | ||
def receive_command(self): | ||
command = self.socket.recv(1024) | ||
return command.decode() | ||
|
||
def authenticate(self): | ||
cipher_suite = Fernet(self.wearable_secret) | ||
encrypted_home_secret = cipher_suite.encrypt(self.home_secret.encode()) | ||
self.socket.send(self.wearable_id.encode()) | ||
self.socket.send(encrypted_home_secret) | ||
|
||
def start(self): | ||
self.authenticate() | ||
while True: | ||
data = 'Heart rate: 100 bpm' | ||
self.send_data(data) | ||
time.sleep(1) | ||
|
||
if __name__ == '__main__': | ||
wearable_id = 'wearable123' | ||
wearable_secret = 'secret123' | ||
home_id = 'home123' | ||
home_secret = 'secret123' | ||
wearable = Wearable(wearable_id, wearable_secret, home_id, home_secret) | ||
wearable.start() |