Getting a Device-Status subscription

Here, we will show how to get a subscription using multiple methods. If you previously created a subscription and you need to modify or delete it, you can easily retrieve it by its ID.

You can also get a single active subscription or a list of them, check the connectivity or roaming status of devices. The connectivity status polling method returns whether a device is connected to a network or not. Now, besides returning if a device is roaming or not, the roaming status polling method shows the current country code and name.

import network_as_code as nac
 
from network_as_code.models.device import Device, DeviceIpv4Addr
 
client = nac.NetworkAsCodeClient(...)
 
# Create a subscription
connectivity_subscription = client.connectivity.subscribe(...)
 
# Get a subscription by its ID
subscription = client.connectivity.get_subscription(connectivity_subscription.id)
 
# Or retrieve list of active Device Status subscriptions
subscriptions = client.connectivity.get_subscriptions()
 
# Check the connectivity status of subscriptions
status = device.get_connectivity()
 
# Check the roaming status of subscriptions
status = device.get_connectivity()

Note that the snippet above assumes you have already created Device Status subscription before, which you can learn how to do here. And that you have also created a Network-as-Code client and identified your mobile network device previously.

Last updated on May 23, 2024

On this page