LTE modem - UDP

This commit is contained in:
tarman3 2024-11-17 12:07:22 +02:00
parent 92eef81ef4
commit 00ff060e63
No known key found for this signature in database
GPG Key ID: 44E226A52629FEEE
4 changed files with 70 additions and 2 deletions

View File

@ -44,6 +44,7 @@ Data frame will send to MQTT every 5 seconds.
2. **Open Serial Studio and configure MQTT**:
- Set the **Host**: 127.0.0.1
- Set the **Port**: 1883
- Set the **Topic**: lte
- Set the **Mode**: Subscriber
- Set the **Keep Alive**: 600
@ -57,3 +58,20 @@ Data frame will send to MQTT every 5 seconds.
4. Use **Project editor** to configure dashboard.
![Project Editor](doc/project_editor.png)
## UDP Socket
Solution with UDP Socket looks much simpler than MQTT.
Run in terminal:
`python lte_udp.py`
### Serial Studio Configuration for UDP Socket
- Set the **DEVICE SETUP**: I/O Interface: Network Socket
- Set the **Socket type**: UDP
- Set the **Remote address**: 127.0.0.1
- Set the **Local port**: 5005
- Set the **Ignore data delimeters**: True
- Click **Connect**
![Serial Studio Quick Plot](doc/udp.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

View File

@ -0,0 +1,50 @@
#!/usr/bin/env python
import requests
import time
import datetime
import xml.etree.ElementTree as ET
import re
import socket
# -------------------------- CONFIGURATION --------------------------------
url_api = 'http://192.168.9.1/api/device/signal' # Address modem API
cycle_time = 5 # Pause between data frame
udp_ip = '127.0.0.1' # UDP target IP
udp_port = 5005 # UDP target port
# -------------------------------------------------------------------------
def get_value(marker):
string = tree.find(marker).text
value = re.search(r'(\-|)(\d+)(\.?)(\d*)', string).group(0)
# print('string=', string, ' value=', value)
return value
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
while True:
xml_data = requests.get(url_api).text
tree = ET.XML(xml_data)
cell = str(get_value('cell_id'))
rsrq = int(float(get_value('rsrq')))
rsrp = int(get_value('rsrp'))
rssi = int(get_value('rssi'))
sinr = int(get_value('sinr'))
pci = int(get_value('pci'))
mode = int(get_value('mode'))
ulbandwidth = int(get_value('ulbandwidth'))
dlbandwidth = int(get_value('dlbandwidth'))
band = int(get_value('band'))
ulfrequency = int(get_value('ulfrequency'))
dlfrequency = int(get_value('dlfrequency'))
print(f'{datetime.datetime.now().strftime("%H-%M-%S")} CELL={cell} RSRQ={rsrq} RSRP={rsrp} RSSI={rssi} SINR={sinr}')
data_frame = f'{rsrq},{rsrp},{rssi},{sinr},{cell}'
# print(frame)
sock.sendto(data_frame.encode('utf-8'), (udp_ip, udp_port))
time.sleep(cycle_time)

View File

@ -15,9 +15,9 @@ Some examples also include Serial Studio project files (`*.json`) to simplify th
- **Screenshot**: Example view in Serial Studio.
### 2. LTE modem
- **Description**: This example reads data of signal from LTE modem and transmits it over MQTT.
- **Description**: This example reads data of signal from LTE modem and transmits it over MQTT or UDP Socket.
- **Contents**:
- **lte_mqtt.py**: Python script for parsing data of signal from LTE modem API and send it over MQTT.
- **lte_mqtt.py**: Python script for parsing data of signal from LTE modem API and send it over MQTT or UDP Socket.
- **README.md**: Setup and usage instructions.
- **Screenshot**: Example view in Serial Studio.