diff --git a/examples/LTE modem/README.md b/examples/LTE modem/README.md new file mode 100644 index 00000000..0871330f --- /dev/null +++ b/examples/LTE modem/README.md @@ -0,0 +1,77 @@ +# LTE modem HUAWEI K5161H + Serial Studio Example + +## Overview + +This project demonstrates how to use Serial Studio and MQTT to visualize data from a **LTE modem HUAWEI K5161H**. + +## Using in this example + +- OS **Archlinux** +- **Mosquitto**: MQTT broker +- **Python** +- **paho**: Python client library for MQTT + +## Step-by-Step Guide + +### 1. MQTT broker Mosquitto +To install MQTT Broker **Mosquitto** run in terminal: +`sudo pacman -S mosquitto` + +To run MQTT Broker **Mosquitto** with default settings run in terminal: +`mosquitto --verbose` + +### 2. Parse data from LTE modem API +For simple cases, you can send data frame to MQTT from terminal, e.g.: +`mosquitto_pub -m "100,50,75,89" -t "lte"` + +For complex situations, you can use Python (or another language for your choice) to retrieve and form the data frame. +An example script is contained in the file [lte_mqtt.py](lte_mqtt.py) + +Install **paho** - Python client library for MQTT: +`sudo pacman -S python-paho-mqtt` + +Run in terminal: +`python lte_mqtt.py` + +Data frame will send to MQTT every 5 seconds. + + +### 3. Serial Studio Configuration +1. **Download and Install Serial Studio**: + + Visit [Serial Studio's official website](https://serial-studio.github.io/) to download and install the software. + +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 + - Click **Connect** +![Serial Studio Quick Plot](doc/mqtt_setup.png) + +3. After get first frame of data Serial-Studio will automatic open dashboard with plots. + +![LTE modem signal](doc/screenshot.png) + +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) diff --git a/examples/LTE modem/doc/mqtt_setup.png b/examples/LTE modem/doc/mqtt_setup.png new file mode 100644 index 00000000..80943096 Binary files /dev/null and b/examples/LTE modem/doc/mqtt_setup.png differ diff --git a/examples/LTE modem/doc/project_editor.png b/examples/LTE modem/doc/project_editor.png new file mode 100644 index 00000000..cec173c4 Binary files /dev/null and b/examples/LTE modem/doc/project_editor.png differ diff --git a/examples/LTE modem/doc/screenshot.png b/examples/LTE modem/doc/screenshot.png new file mode 100644 index 00000000..e9830f06 Binary files /dev/null and b/examples/LTE modem/doc/screenshot.png differ diff --git a/examples/LTE modem/doc/udp.png b/examples/LTE modem/doc/udp.png new file mode 100644 index 00000000..1b822ff3 Binary files /dev/null and b/examples/LTE modem/doc/udp.png differ diff --git a/examples/LTE modem/lte_mqtt.py b/examples/LTE modem/lte_mqtt.py new file mode 100644 index 00000000..d253952a --- /dev/null +++ b/examples/LTE modem/lte_mqtt.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python + +import requests +import time +import datetime +import xml.etree.ElementTree as ET +import re +import paho.mqtt.client as paho + +# -------------------------- CONFIGURATION -------------------------------- + +url_api = 'http://192.168.9.1/api/device/signal' # Address modem API +cycle_time = 5 # Pause between data frame +mqtt_topic = 'lte' # MQTT topic +mqtt_broker_ip = '127.0.0.1' # MQTT broker local IP +mqtt_broker_port = 1883 # MQTT broker local 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 + +mqttc = paho.Client() +mqttc.connect(mqtt_broker_ip, mqtt_broker_port, 60) + +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) + mqttc.publish(mqtt_topic, data_frame) + + time.sleep(cycle_time) diff --git a/examples/LTE modem/lte_udp.py b/examples/LTE modem/lte_udp.py new file mode 100644 index 00000000..cf11ea19 --- /dev/null +++ b/examples/LTE modem/lte_udp.py @@ -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) diff --git a/examples/README.md b/examples/README.md index 6e0a7161..dd958f96 100644 --- a/examples/README.md +++ b/examples/README.md @@ -14,7 +14,14 @@ Some examples also include Serial Studio project files (`*.json`) to simplify th - **README.md**: Setup and usage instructions. - **Screenshot**: Example view in Serial Studio. -### 2. MPU6050 +### 2. LTE modem +- **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 or UDP Socket. + - **README.md**: Setup and usage instructions. + - **Screenshot**: Example view in Serial Studio. + +### 3. MPU6050 - **Description**: This example captures motion and orientation data from an MPU6050 accelerometer and gyroscope. Processed data is sent to Serial Studio for real-time visualization on widgets like a g-meter or attitude indicator. - **Contents**: - **MPU6050.ino**: Arduino code for capturing and transmitting MPU6050 data. @@ -22,14 +29,14 @@ Some examples also include Serial Studio project files (`*.json`) to simplify th - **README.md**: Detailed setup instructions, including Serial Studio configuration. - **Screenshots**: `project-setup.png` and `screenshot.png` provide visual references for Serial Studio setup and data visualization. -### 3. PulseSensor +### 4. PulseSensor - **Description**: This example filters and smooths pulse data from a heart rate sensor and visualizes it in Serial Studio using **quick plot mode**. The filtered pulse signal is transmitted for live monitoring and CSV logging. - **Contents**: - **PulseSensor.ino**: Arduino code for filtering and transmitting pulse data. - **README.md**: Step-by-step guide for setup and visualization in Serial Studio. - **Screenshots**: `csv.png` and `screenshot.png` for reference in CSV logging and Serial Studio visualization. -### 4. TinyGPS +### 5. TinyGPS - **Description**: This example reads GPS data (latitude, longitude, and altitude) from a GPS module and visualizes it on a map in Serial Studio. - **Contents**: - **TinyGPS.ino**: Arduino code for capturing and transmitting GPS data. @@ -37,7 +44,7 @@ Some examples also include Serial Studio project files (`*.json`) to simplify th - **README.md**: Comprehensive setup instructions for GPS configuration, including Serial Studio setup. - **Screenshots**: `project-setup.png` and `screenshot.png` for guidance on map visualization in Serial Studio. -### 5. UDP Function Generator +### 6. UDP Function Generator - **Description**: This example generates real-time waveforms (sine, triangle, sawtooth, and square) and transmits them over an UDP socket locally. It is designed to generate data that can be visualized in **Serial Studio**, where you can observe and analyze the generated signals in real-time. The program is versatile and can also be used to stress-test Serial Studio's performance under continuous, high-frequency data streams. - **Contents**: