Skip to content

Commit

Permalink
feat: update car script to match new GAPP api specification
Browse files Browse the repository at this point in the history
  • Loading branch information
VilemRaska committed Feb 6, 2025
1 parent 204b107 commit 5e9396c
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions car/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#
##povolit seriovku
#sudo raspi-config
#
#
##spustit
##MAVLINK20=1 python3 mavlink.py
##MAVLINK20=1 python3 mavlink.py

from pymavlink.dialects.v20 import common as mavlink2
from pymavlink import mavutil
Expand All @@ -19,10 +19,10 @@
import requests

carID="car2"
cdpAddres="https://public.crreat.eu"
cdpAddres="https://fik.crreat.eu/api"
#cdpAddres="http://127.0.0.1:8000"
hbEndPoint="/post/car/hb"
dataEndPoint="/post/car/data"
hbEndPoint="/telemetry/car"
dataEndPoint="/telemetry/vessel"


try:
Expand Down Expand Up @@ -59,9 +59,9 @@
state["latitude"]=""
state["longitude"]=""
state["altitude"]=""
state["tmp"]=""
state["car_id"]=carID
state["balloon_id"]="fik_SiK"
state["received_at"]=""
# state["car_id"]=carID
state["cellsign"]="fik_SiK"
sended=True

lastHB=datetime.datetime(1990,1,1,0,0,0)
Expand All @@ -85,20 +85,19 @@
#print(msg)
#print(type(msg))
#print(msg.lat)
state["tmp"]=str(datetime.datetime.utcnow())
state["received_at"]=str(datetime.datetime.utcnow())
state["latitude"]=float(msg.lat)/10000000.0
state["longitude"]=float(msg.lon)/10000000.0
state["altitude"]=float(msg.alt)/1000.0
print(state["tmp"]," ",state["latitude"]," ",state["longitude"]," ",state["altitude"])
print(state["received_at"]," ",state["latitude"]," ",state["longitude"]," ",state["altitude"])
sended=False

if (datetime.datetime.utcnow()-lastHB).total_seconds()>15:
#send hardbeat
print("Sending HB to CDP")
if (datetime.datetime.utcnow()-lastHB).total_seconds()>15:
#send car location
print("Sending car location to GAPP")
carPos = gpsd.get_current()
hbMsg={}
hbMsg['car_id']=carID
hbMsg['car_heartbeat_value']=str(datetime.datetime.utcnow())
hbMsg['callsign']=carID
hbMsg['latitude']=carPos.lat
hbMsg['longitude']=carPos.lon
hbMsg['altitude']=carPos.alt
Expand All @@ -107,10 +106,10 @@
print(response)
lastHB=datetime.datetime.utcnow()
except Exception as e:
print("Error couldnt send HB to CDP",e)
print("Error couldnt send position to GAPP",e)

if sended==False and (datetime.datetime.utcnow()-lastData).total_seconds()>5:
#try send
#try send
try:
print("Sending Data to CDP")
print(state)
Expand Down

0 comments on commit 5e9396c

Please sign in to comment.