NADC MQTT Helper Library
Project description
NADC MQTT Helper
This library encapsulates MQTT client tools for communication and data exchange between telescopes and the NADC platform.
Installation
pip install nadc-mqtt-helper
Main Features
- Subscribe: Platform broadcasts alert information to telescopes, corresponding to the topic "TDIC/Alert/Followup"
- Subscribe: Platform sends private alert information to specific telescopes, corresponding to the topic "TDIC/Alert//Followup", used for sending non-public EP SVOM alerts to specific telescopes
- Subscribe: Platform sends observation planning information to telescopes, corresponding to the topic "GWOPS//schedule", currently mainly for gravitational wave event observation planning
- Publish: Telescopes send status information to the platform, corresponding to the topic "GWOPS//status_update"
- Publish: Telescopes send observation status information to the platform, corresponding to the topic "GWOPS//observed"
- Publish: Telescopes provide observation data to the platform, corresponding to the topic "GWOPS//data"
Basic Usage
Create and Connect Client
from nadc_mqtt_helper.xdb_message_hub import TelescopeClient
from nadc_mqtt_helper.models import TelescopeStatusInfo, ObservationData
# Create client connection
client = TelescopeClient(
tid="your_telescope_id",
password="your_password",
host="mqtt.example.com",
port=1883
)
# Connect to MQTT server
client.connect()
# Disconnect when finished
client.disconnect()
Subscribe to Messages
# Subscribe to public alerts
def handle_public_alert(payload):
print(f"Received public alert, processing: {payload}")
client.subscribe_to_public_alerts(handle_public_alert)
# Subscribe to private alerts
def handle_private_alert(payload):
print(f"Received private alert, processing: {payload}")
client.subscribe_to_private_alerts(handle_private_alert)
# Subscribe to scheduling information
def handle_schedule(payload):
print(f"Received scheduling information, processing: {payload}")
client.subscribe_to_schedule(handle_schedule)
Publish Telescope Status
from nadc_mqtt_helper.models import EnvironmentData, TelescopeStatus, TelescopeStatusInfo
from datetime import datetime
# Create environment data
env_data = EnvironmentData(
time=datetime.now(),
temperature=15.5,
humidity=45.0,
dewtemperature=5.2,
pressure=1013.0,
height=100.0,
windspeed=5.0,
windspeed_2=6.0,
windspeed_10=7.0,
windDirection=270,
Rainfall=0.0,
Rainfall_all=10.0,
pm25=15.0,
pm10=30.0,
voltage=220.0,
TimeStamp=datetime.now()
)
# Create telescope status
telescope_status = TelescopeStatus(
telescope="2.4m",
instrument="CCD",
observation_assistant="someone",
assistant_telephone="12345678901",
status="observing",
is_observable=True,
daytime="night",
too_observing="available",
date=datetime.now()
)
# Create telescope status information
status_info = TelescopeStatusInfo(
environment=[env_data],
telescope_status=telescope_status
)
# Publish status
client.publish_status(status_info)
Publish Observation Data
from nadc_mqtt_helper.models import ObservationData
from datetime import datetime, timedelta
# Create observation data
now = datetime.now()
observation = ObservationData(
telescope="2.4m",
Instrument="YFOSC",
pointing_ra=83.8221,
pointing_dec=-5.3911,
start_time=now,
end_time=now + timedelta(minutes=30),
duration=30.0,
event_name="M42",
observer="someone",
obs_type="science",
comment="for testing",
update_time=now
)
# Publish observation data
client.publish_observation(observation)
Data Models
The library provides the following main data models:
EnvironmentData: Environmental data model, containing environmental parameters such as temperature, humidity, pressure, etc.TelescopeStatus: Telescope status model, containing the current working status of the telescopeTelescopeStatusInfo: Telescope information model, containing environmental data and telescope statusObservationData: Observation data model, recording observation details
Data Model Field Details
EnvironmentData Model
| Field | Type | Example | Description |
|---|---|---|---|
| time | datetime | 2023-05-20T18:30:00 | Data recording time |
| temperature | float | 15.5 | Temperature (°C) |
| humidity | float | 45.0 | Humidity (%) |
| dewtemperature | float | 5.2 | Dew point temperature (°C) |
| pressure | float | 1013.0 | Atmospheric pressure (hPa) |
| height | float | 100.0 | Height (m) |
| windspeed | float | 5.0 | Wind speed (m/s) |
| windspeed_2 | float | 6.0 | Wind speed at 2m height (m/s) |
| windspeed_10 | float | 7.0 | Wind speed at 10m height (m/s) |
| windDirection | int | 270 | Wind direction (degrees) |
| Rainfall | float | 0.0 | Rainfall (mm) |
| Rainfall_all | float | 10.0 | Total rainfall (mm) |
| pm25 | float | 15.0 | PM2.5 concentration (μg/m³) |
| pm10 | float | 30.0 | PM10 concentration (μg/m³) |
| voltage | float | 220.0 | Voltage (V) |
| TimeStamp | datetime | 2023-05-20T18:30:00 | Timestamp |
TelescopeStatus Model
| Field | Type | Example | Description |
|---|---|---|---|
| telescope | string | "2.4m" | Telescope identifier |
| instrument | string | "CCD" | Instrument in use |
| observation_assistant | string | "John Doe" | Name of observation assistant |
| assistant_telephone | string | "12345678901" | Assistant's contact phone |
| status | string | "observing" | Current telescope status |
| is_observable | bool | true | Whether observation is possible |
| daytime | string | "night" | Day/night status |
| too_observing | string | "available" | TOO observation status |
| date | datetime | 2023-05-20T18:30:00 | Record date |
TelescopeStatusInfo Model
| Field | Type | Description |
|---|---|---|
| environment | List[EnvironmentData] | List of environmental data |
| telescope_status | TelescopeStatus | Telescope status information |
ObservationData Model
| Field | Type | Example | Description |
|---|---|---|---|
| telescope | string | "2.4m" | Telescope identifier |
| Instrument | string | "YFOSC" | Instrument in use |
| pointing_ra | float | 83.8221 | Right ascension (degrees) |
| pointing_dec | float | -5.3911 | Declination (degrees) |
| start_time | datetime | 2023-05-20T20:00:00 | Observation start time |
| end_time | datetime | 2023-05-20T20:30:00 | Observation end time |
| duration | float | 30.0 | Observation duration (minutes) |
| event_name | string | "M42" | Target name |
| observer | string | "Jane Smith" | Observer name |
| obs_type | string | "science" | Observation type |
| comment | string | "Orion Nebula observation" | Observation notes |
| update_time | datetime | 2023-05-20T20:30:00 | Data update time |
Client Example
Refer to the xdb_message_client.py file for a complete client example code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nadc_mqtt_helper-0.1.2.tar.gz.
File metadata
- Download URL: nadc_mqtt_helper-0.1.2.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecbc958c151f377144281b5ab179259c670694ee1e26d18eb55dc77021def503
|
|
| MD5 |
458d5dde621e78c3d21f77977ae0d821
|
|
| BLAKE2b-256 |
5480349e9f2a10993f53bb2c8b8b6231f2aa6d70a942492196e8b2e47edadc7e
|
File details
Details for the file nadc_mqtt_helper-0.1.2-py3-none-any.whl.
File metadata
- Download URL: nadc_mqtt_helper-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16b6d4b6c4c81b9efae079bd68075d300c9b83690d76fd98f4073728f51d11af
|
|
| MD5 |
261cd7936dfecd60584de41f358ef8c5
|
|
| BLAKE2b-256 |
458f1eedf31825faf1e8f31582ab32512f6d747f02c7e543a5544bdd29fc0b2f
|