-
Notifications
You must be signed in to change notification settings - Fork 0
/
moondistance.py
64 lines (40 loc) · 1.87 KB
/
moondistance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import socket
from skyfield.api import load, Topos
from datetime import datetime, timezone
def calculate_moon_gps_distance(latitude, longitude, elevation_meters):
# Load the necessary data from Skyfield's data files
data = load('de421.bsp')
earth, moon = data['earth'], data['moon']
# Create a Topos object for the GPS location
gps_location = Topos(latitude_degrees=latitude, longitude_degrees=longitude, elevation_m=elevation_meters)
# Get the current time in UTC
current_time = datetime.now(timezone.utc)
# Convert the datetime object to Skyfield's UTC timescale
ts = load.timescale()
current_time_utc = ts.utc(current_time)
# Compute the positions of the Moon and the GPS location at the given time
moon_position = (moon - earth).at(current_time_utc)
gps_position = gps_location.at(current_time_utc)
# Calculate the distance between the Moon and the GPS location
distance_km = (moon_position - gps_position).distance().km
return distance_km
# GPS location coordinates (latitude, longitude, elevation in degrees and meters)
gps_latitude = 28.6372
gps_longitude = -96.459
gps_elevation_meters = 1 # Elevation above sea level in meters
# Calculate the distance using the function
distance_to_moon_km = calculate_moon_gps_distance(28.6372, -96.459, gps_elevation_meters)
# InfluxDB server information
influxdb_host = 'bi.pancamo.com'
influxdb_port = 8089
# Temperature data
measurement = 'wu.KTXOLIVI.moon.distance.km'
# Construct the InfluxDB line protocol format
influxdb_data = f'{measurement} value={distance_to_moon_km}'
# Create a UDP socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Send data to InfluxDB server using UDP
client_socket.sendto(influxdb_data.encode(), (influxdb_host, influxdb_port))
# Close the socket
client_socket.close()
print("Data sent to InfluxDB using UDP: ", influxdb_data)