Hello!
I am trying to integrate the lorawan gateway with a python code to harvest data from the nodes.
Compelted all the setup, and i can read the datas from chirpstack and postman wss connection without any problem. But when i try to make an application for it i cannot connect and get data from it. Tried various library but cannot find any solution. Some of examples gives SSL error and some of them i cannot pass the jwt token.
import requests
from requests.auth import HTTPDigestAuth
import warnings
import os
import sys
import grpc
import websocket
from websocket import create_connection
import websockets
import asyncio
import pathlib
import ssl
from chirpstack_api.as_pb.external import api
warnings.simplefilter("ignore")
url = "https://192.168.20.100:8080/api/internal/login"
data ={
"email": "admin@mciot.com",
"password": "Batw1ngs-Adm1n1!"
}
response = requests.post(url, json=data, verify=False)
print("Status Code:", response.status_code)
jwt = str(response.json())
jwt = jwt.split("'")[3]
token=jwt
#HIGHLY INSECURE
ssl_context = ssl.SSLContext()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
#HIGHLY INSECURE
#todo kluge
uri = "wss://@192.168.20.100:8080/api/devices/0000000000000003/events"
header=("Sec-WebSocket-Protocol: Bearer,")
created = ("\n"+token)
list1 = ["Sec-WebSocket-Protocol", created]
async def hello():
## async with websockets.connect(uri, ssl=ssl_context) as websocket:
async with websockets.connect(
"wss://admin@mciot.com:Batw1ngs-Adm1n1!@192.168.20.100:8080/api/devices/0000000000000003/events",
ssl=ssl_context,
extra_headers={"Bearer,": f"token"}
) as websocket:
greeting = await websocket.recv()
print(f"< {greeting}")
asyncio.get_event_loop().run_until_complete(hello())
Please help.
Thanks in advance.