Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download new Iridium packets #6

Open
zacharyburnett opened this issue Sep 26, 2020 · 4 comments · May be fixed by #77
Open

download new Iridium packets #6

zacharyburnett opened this issue Sep 26, 2020 · 4 comments · May be fixed by #77
Labels
enhancement New feature or request

Comments

@zacharyburnett
Copy link
Member

zacharyburnett commented Sep 26, 2020

@jtmolter here's a place where we can collate info / links on the Iridium API, so it doesn't get deleted on Slack

@zacharyburnett zacharyburnett added the enhancement New feature or request label Sep 26, 2020
@zacharyburnett
Copy link
Member Author

zacharyburnett commented Aug 9, 2021

https://docs.rockblock.rock7.com/reference#testinput

When a message is sent by your RockBLOCK, we will open an HTTP connection to your application URL.

Your application must respond promptly (within 3 seconds) with an HTTP status 200, to indicate that you have successfully handled the message.

@zacharyburnett
Copy link
Member Author

I've drafted up a rudimentary interface with which to connect to RockBLOCK and receive packets, I just need to find the format that the packets come in so I can parse them

class RockBLOCK(PacketSource, NetworkConnection):
interval = timedelta(seconds=10)
def __init__(self, imei: str, username: str = None, password: str = None):
"""
connect to RockBLOCK API
:param imei: IMEI of RockBLOCK
:param username: RockBLOCK username
:param password: RockBLOCK password
"""
url = 'https://rockblock.rock7.com/rockblock/MT'
super().__init__(url)
if username is None or username == '':
configuration = read_configuration(CREDENTIALS_FILENAME)
if 'RockBLOCK' in configuration:
username = configuration['RockBLOCK']['username']
else:
raise ConnectionError(f'no RockBLOCK username specified')
if password is None or password == '':
configuration = read_configuration(CREDENTIALS_FILENAME)
if 'RockBLOCK' in configuration:
password = configuration['RockBLOCK']['password']
else:
raise ConnectionError(f'no RockBLOCK password specified')
if not self.connected:
raise ConnectionError(f'no network connection')
self.imei = imei
self.username = username
self.password = password
self.__last_access_time = None
@property
def packets(self) -> [LocationPacket]:
if self.__last_access_time is not None and self.interval is not None:
interval = datetime.now() - self.__last_access_time
if interval < self.interval:
raise TimeIntervalError(
f'interval {interval} less than minimum interval {self.interval}'
)
query = {
'imei': self.imei,
'username': self.username,
'password': self.password,
}
query = '&'.join(f'{key}={value}' for key, value in query.items())
response = requests.get(f'{self.location}?{query}')
status, code, data = response.text.split(',')
if status == 'OK':
# TODO test this with RockBLOCK data
packets = data.split(',')
if len(packets) > 0:
# respond promptly with normal response code if received data
post_query = {
'username': self.username,
'password': self.password,
}
requests.post(
f'{self.location}?{post_query}', headers={'Accept': 'text/plain'}
)
# TODO write packet parsing code here
else:
if code == '10':
raise ConnectionError(data)
elif code in ['11', '12', '13']:
raise PermissionError(data)
elif code in ['14', '15']:
raise ValueError(data)
elif code == '16':
packets = []
else:
raise SystemError(data)
self.__last_access_time = datetime.now()
return packets
def close(self):
pass

@zacharyburnett
Copy link
Member Author

https://docs.rockblock.rock7.com/reference/receiving-mo-messages-via-http-webhook
^ this details the steps to set up a receiving node

@zacharyburnett
Copy link
Member Author

zacharyburnett commented Nov 7, 2021

it sounds like we will have to set up an active web socket that can accept POST requests from the RockBLOCK servers. We can do this with Flask (https://zetcode.com/python/getpostrequest/) but it would have to be a separately running application that passes packets to the server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant