Device connectivity
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.
Subscribe to Connectivity Status events
The SDK below allows you to subscribe client devices to Device Status connectivity events.
import network_as_code as nac
from network_as_code.models.device_status import EventType
from datetime import datetime, timedelta, timezone
# We begin by creating a Network as Code client
client = nac.NetworkAsCodeClient(
token="<your-application-key-here>"
)
# Then, we create an object for the mobile device we want to use
my_device = client.devices.get(
# The phone number does not accept spaces or parentheses
phone_number="+99999991000"
)
# Then we subscribe your device to connectivity events.
my_subscription = client.connectivity.subscribe(
event_type=EventType.CONNECTIVITY_DATA,
device=my_device,
# You can tell when the subscription is supposed to expire with datetime
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 connectivity subscription status
print(my_subscription)Connectivity subscription parameters
| Parameters | Type | Description | Mandatory or Optional |
|---|---|---|---|
event_type | object/string | The status type you want to check. For example EventType.CONNECTIVITY_DATA or org.camaraproject.device-status.v0.connectivity-data. | Mandatory |
device | object | The device object previously created for the mobile device we want to use. | Mandatory |
notification_url | string | The recipient's HTTP endpoint, which is a web server configured to receive POST requests. | Mandatory |
notification_auth_token | string | A password used to identify the sender of the notification. | Optional |
subscription_expire_time | object/string | When the subscription should expire. Can be either a date-time object or ISO 8601 formatted date string, for example "2025-08-28T12:40:20.398Z". | Optional |
Connectivity event types
| Event type | Type | Description |
|---|---|---|
connectivity-data | object/string | EventType.CONNECTIVITY_DATA or org.camaraproject.device-status.v0.connectivity-data - Used for checking if the device is connected to the network for data usage. |
connectivity-sms | object/string | EventType.CONNECTIVITY_SMS or org.camaraproject.device-status.v0.connectivity-sms - Used for checking if the device is connected to the network for SMS usage. |
connectivity-disconnected | object/string | EventType.CONNECTIVITY_DISCONNECTED or org.camaraproject.device-status.v0.connectivity-disconnected - Used for checking that the device is not connected to the network. |
Simulated Device Connectivity scenarios
The Network as Code simulators have been configured to provide specific device connectivity results for specific simulated devices based on their device identifier. This will be helpful in testing your code against the different responses, including possible errors, by simply substituting the device identifier in your code.
The device identifiers and their responses can be found in the following table:
| Device Identifier Type | Device Identifier | HTTP Status Code | HTTP Status Code Description | Reponse Body |
|---|---|---|---|---|
| Phone Number | +99999991000 | 200 | Success | Device is connected to SMS |
| Phone Number | +99999991001 | 200 | Success | Device has a data connection |
| Phone Number | +99999991002 | 200 | Success | Device has lost connectivity |
| Phone Number | +99999990400 | 400 | Bad Request | |
| Phone Number | +99999990404 | 404 | Not found | |
| Phone Number | +99999990422 | 422 | Unprocessable Content | |
| Phone Number | +99999990500 | 500 | Internal Server Error | |
| Phone Number | +99999990502 | 502 | Bad Gateway | |
| Phone Number | +99999990503 | 503 | Service Unavailable | |
| Phone Number | +99999990504 | 504 | Gateway Timeout |
Getting a device connectivity status
You can check the device connectivity status like so:
print(my_device.get_connectivity())Getting device connectivity status responses
| Response | Type | Description |
|---|---|---|
CONNECTED_DATA | string | Indicates, that the device is connected to the network via data usage. |
CONNECTED_SMS | string | Indicates, that the device is connected to the network via SMS usage. |
NOT_CONNECTED | string | Indicates, that the device is not connected to the network. |
Getting connectivity notifications
The code snippet below will set up an HTTP server with a POST endpoint. This will allow receiving device connectivity status updates. For example, you can learn if a device is available (connected to the network) or not. Learn more about the notification URL/auth token and how to create an HTTP server with a POST endpoint for connectivity notifications.
Connectivity notification handler
# status_handler.py for CONNECTIVITY
# run with: uvicorn status_handler:app
from fastapi import FastAPI, Header
from pydantic import BaseModel
from typing_extensions import Annotated
from typing import Union, Optional
app = FastAPI()
class Device(BaseModel):
phoneNumber: Optional[str] | None
networkAccessIdentifier: Optional[str] | None
ipv4Address: Optional[str] | None
ipv6Address: Optional[str] | None
class ConnectivityEventDetail(BaseModel):
device: Device
subscriptionId: str
deviceStatus: str
terminationReason: str
class Event(BaseModel):
eventType: str
eventTime: str
eventDetail: ConnectivityEventDetail
class Data(BaseModel):
device: Device
subscriptionId: str
terminationReason: str
class Notification(BaseModel):
id: str
source: str
type: str
specversion: str
datacontenttype: str
time: str
eventSubscriptionId: str
event: Event
data: Data
@app.post("/notifications")
def receive_notification(
notification: Notification,
authorization: Annotated[Union[str, None], Header]
):
if authorization == "Bearer my-token":
# We can now react to the notifications
# based on the Notification object
print(notification)Connectivity notification details
This notification JSON schema is used for notifications about device connectivity.
Remember that the string values represented below are just examples that can be used. So, they should contain your real device-status values.
{
"id": "9884b8d2-5392-4ed7-8cde-0ce25bf58df3",
"source": "/device-status/v0/subscriptions/83b1eaae-4533-4bff-a0af-e805cb8a2940",
"type": "org.camaraproject.device-status.v0.connectivity-data",
"specversion": "1.0",
"datacontenttype": "application/json",
"time": "2026-04-17T07:31:01.416474Z",
"data": {
"device": {
"phoneNumber": "+99999991000",
"networkAccessIdentifier": "[email protected]",
"ipv4Address": {
"publicAddress": "233.252.0.2",
"privateAddress": "192.0.2.25",
"publicPort": 80
},
"ipv6Address": "2001:db8:1234:5678:9abc:def0:fedc:ba98"
},
"subscriptionId": "83b1eaae-4533-4bff-a0af-e805cb8a2940"
}
}
Shared-keyword values
Check the table below for further information on mandatory, optional values and their types.
The values described here are common to all the Device-Status notification JSON schemas:
| Keyword values | Type | Description |
|---|---|---|
subscriptionId | string | The event subscription identifier. |
source | string | Identifies the source where the event happened. It contains the Network as Code API implementation and subscription ID. |
type | string | The status type being checked and returned by the API. For example connectivity-sms. |
specversion | string | Representing the specification version. |
datacontenttype | string | Indicates the media type for the event payload encoding. It must be "application/json" in the context of CAMARA APIs. |
time | string | The time the event occurred. Date and time are specified in ISO 8601 format, e.g.: "2023-08-20T21:01:02.345Z". |
Device identifiers
| Keyword values | Type | Description | Mandatory or Optional |
|---|---|---|---|
data | object | Object that will contain other objects or strings. Contains multiple device status data, e.g. the subscription id. | Mandatory |
device | object | Object that will contain other objects or strings. Contains multiple device identifiers, e.g. the devices phone number. | Mandatory |
phoneNumber | string | Phone number of the device, with a pattern that matches "^[+]?[0-9]{5,15}$" or a null value. | Optional |
networkAccessIdentifier | string | An email-like external identifier for a device (or subscriber) into the network, with a pattern that matches "^[+]?[0-9]{5,15}$" or a null value. If both the networkAccessIdentifier and phoneNumber are included, phoneNumber will be dropped and networkAccessIdentifier will be retained. | Optional |
ipv4Address | object | Contains an object for IPv4 address values or a null value. It refers to the IPv4 address of the device. An IP address is needed for some flow-oriented services, such as QoD. | Optional |
publicAddress | string | Either the device's public IPv4 address, the Network Address Translation (NAT) behind it or a null value. Learn more about NAT. | Optional |
privateAddress | string | The device's private IPv4 address if it is behind NAT or a null value. | Optional |
publicPort | integer | The public port used by the device or a null value. A port is necessary, as private address ranges overlap, and public port is used to extend the range for Carrier-grade NAT (CGNAT), a type of large-scale NAT. | Optional |
ipv6Address | integer | Contains the device's IPv6 address or a null value. An IP address is needed for some flow-oriented services, such as QoD. | Optional |
Last updated November 05, 2025