Checking connectivity status
The Device Status feature allows querying and reporting information on several aspects of data connectivity for a device, so you can monitor its status updates, such as when it goes online or offline.
Getting device connectivity status
The SDK below allows you to subscribe client devices to Device Status connectivity events.
It also creates a Network as Code client using an application key accessible from your Dashboard and identifies a mobile network device in multiple ways (IP addresses, port, etc). Learn more about the client and device objects.
import network_as_code as nac
from datetime import datetime, timedelta, timezone
from network_as_code.models.device import Device, DeviceIpv4Addr
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>"
)
# Create a device object for the mobile device we want to use
my_device = client.devices.get(
"device@testcsp.net",
ipv4_address=DeviceIpv4Addr(
public_address="192.0.2.3",
private_address="192.0.2.204",
public_port=80
),
ipv6_address="2001:db8:1234:5678:9abc:def0:fedc:ba98",
# The phone number accepts the "+" sign, but not spaces or "()" marks
phone_number="36721601234567"
)
# Simply change the event_type to
# "org.camaraproject.device-status.v0.roaming-status" whenever needed.
my_subscription = client.connectivity.subscribe(
event_type="org.camaraproject.device-status.v0.connectivity-data",
device=my_device,
# You can tell when the subscription is supposed to expire
# with a date-time object
subscription_expire_time=datetime.now(timezone.utc) + timedelta(days=1),
# Use HTTPS to send notifications
notification_url="https://example.com/notifications",
notification_auth_token="replace-with-your-auth-token"
)
# Use this to show the roaming subscription status
print(my_subscription)
# Or check when your subscription starts/expires:
print(my_subscription.starts_at)
print(my_subscription.expires_at)
NOTE: The subscription expire time can be defined with an ISO 8601 formatted date string, for example
"2024-03-28T12:40:20.398Z"
, or simply create a date-time object as shown in the code snippet examples above.
Connectivity subscription parameters
Above, we created a Subscription
object for connectivity status
and supplied the necessary parameters to the
connectivity-subscription method. The parameters table below
describes which data each parameter expects to receive.
Parameters | Description |
---|---|
event_type | The status type you want to check, which can be connectivity or roaming. |
device | Device ID callback parameter. |
max_num_of_reports | How many reports will be sent to the endpoint. |
notification_url | The recipient's HTTP endpoint, which is a web server configured to receive POST requests. |
notification_auth_token | A password used to identify the sender of the notification. |
subscription_expire_time | The expiry time of the subscription. Either a date-time object or ISO 8601 formatted date string. |
Last updated on July 25, 2024