How to Access the ChirpStack API | Python

 

ChirpStack is an open-source LoRaWAN Network Server (LNS) that enables the deployment and management of LoRaWAN networks. LoRaWAN (Long Range Wide Area Network) is a low-power, wide-area network technology designed for the Internet of Things (IoT) and allows for long-range communication between IoT devices and a centralized network server. ChirpStack is a popular choice among IoT developers and organizations for building and managing LoRaWAN networks due to its flexibility and robust feature set.


ChirpStack offers a built-in API accessible at http://localhost:8080/api. If your server is live and running, you can substitute "localhost" with your server's address.



This Python script showcases the interaction with ChirpStack's API, which is a key component for managing and monitoring IoT devices in a LoRaWAN network. It begins by authenticating with the ChirpStack server using user-provided credentials, followed by obtaining a JWT token for secure authorization. With this token in hand, the script fetches essential device information by making a GET request to the /api/devices?limit=1 endpoint. The retrieved device details are then displayed on the console. This example serves as a practical introduction to leveraging ChirpStack's API for effectively managing IoT devices within your network.

To access the API, you need to authenticate with a token. The token can be generated using your Chirpstack login credentials. To obtain a token from Chirpstack, make a request to the API endpoint "/api/internal/login" and include your Chirpstack credentials. If the credentials are valid, the system will return a JWT token. You can then use this token for future authentications. To retrieve device information, you can call the endpoint "/api/devices" and include the token in the header for authentication.



Here is the server's response.

[
  {
    'devEUI': 'v9404182f184df79',
    'name': '10',
    'applicationID': '17',
    'description': 'temperature,humidity',
    'deviceProfileID': '6ddd08ba-3dt7-4ej2-r44c-rg2245eab194',
    'deviceProfileName': 'Temp_Hum_Sensor',
    'deviceStatusBattery': 255,
    'deviceStatusMargin': 256,
    'deviceStatusExternalPowerSource': False,
    'deviceStatusBatteryLevelUnavailable': True,
    'deviceStatusBatteryLevel': 0,
    'lastSeenAt': '2023-09-11T07:55:53.057358Z'
  }
]




Comments

Popular Posts