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, when a device is REACHABLE
, you will be notified that it is available.
The same happens when the device is UNREACHABLE
or not available.
Device-Status notifications 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
app = FastAPI()
class ConnectivityEventDetail(BaseModel):
deviceStatus: str
class Event(BaseModel):
eventType: str
eventTime: str
eventDetail: ConnectivityEventDetail
class Notification(BaseModel):
eventSubscriptionId: str
event: Event
@app.post("/notifications")
def receive_notification(notification: Notification):
if notification.event.eventDetail.deviceStatus == "REACHABLE":
print("Device is available")
elif notification.event.eventDetail.deviceStatus == "UNREACHABLE":
print("Device is not available")
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.