Connectivity notifications

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.

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. Below, we'll set up a notification handler, so you can react based on status notifications.

Device-Status notification handler

# run with: uvicorn status_handler:app
from fastapi import FastAPI, Header
from pydantic import BaseModel
from typing_extensions import Annotated
from typing import Union
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"/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

What is a notification URL?

Learn more about the notification URL/auth token and how to create a web server for them.

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