Skip to content

Message Queue Return #3

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

Merged
merged 2 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions adafruit_azureiot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def _parse_http_status(status_code, status_reason):

# Cloud-to-Device Messaging
def get_hub_message(self):
"""Returns a message from a Microsoft Azure IoT Hub (Cloud-to-Device), or -1
if the message queue is empty.
"""Returns a message from a Microsoft Azure IoT Hub (Cloud-to-Device).
Returns None if the message queue is empty.
NOTE: HTTP Cloud-to-Device messages are throttled. Poll every 25+ minutes.
"""
reject_message = True
Expand All @@ -102,7 +102,7 @@ def get_hub_message(self):
AZ_API_VER)
data = self._get(path, is_c2d=True)
if data == 204: # device's message queue is empty
return -1
return None
etag = data[1]['etag']
if etag: # either complete or nack the message
reject_message = False
Expand All @@ -113,7 +113,7 @@ def get_hub_message(self):
del_status = self._delete(path_complete)
if del_status == 204:
return data[0]
return -1
return None

# Device-to-Cloud Messaging
def send_device_message(self, message):
Expand Down
2 changes: 1 addition & 1 deletion examples/azureiot_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
# Microsoft suggests a polling interval of the below code for every 25 minutes.
print('Receiving a message from an Azure IoT Hub...')
message = hub.get_hub_message()
if message == -1:
if message is None:
print('IoT Hub Message Queue is empty!')
else:
print(message)