diff --git a/chasemapper/__init__.py b/chasemapper/__init__.py index 4b1ddad..03e9cb7 100644 --- a/chasemapper/__init__.py +++ b/chasemapper/__init__.py @@ -8,4 +8,4 @@ # Now using Semantic Versioning (https://semver.org/) MAJOR.MINOR.PATCH -__version__ = "1.3.0" +__version__ = "1.3.1" diff --git a/horusmapper.py b/horusmapper.py index 22c6591..6c153ff 100644 --- a/horusmapper.py +++ b/horusmapper.py @@ -707,6 +707,8 @@ def mark_payload_recovered(data): """ Mark a payload as recovered, by uploading a station position """ global online_uploader + print(data) + _serial = data["payload_call"] _callsign = data["my_call"] _lat = data["last_pos"][0] diff --git a/static/js/sondehub.js b/static/js/sondehub.js index cd403e4..459dee2 100644 --- a/static/js/sondehub.js +++ b/static/js/sondehub.js @@ -30,3 +30,80 @@ function get_sondehub_vehicles(){ } +/* Habitat ChaseCar lib (copied from SondeHub Tracker) + * Uploads geolocation for chase cars to habitat + * + * Author: Rossen Gerogiev / Mark Jessop + * Requires: jQuery + * + * Updated to SondeHub v2 by Mark Jessop + */ + +ChaseCar = { + db_uri: "https://api.v2.sondehub.org/listeners", // Sondehub API + recovery_uri: "https://api.v2.sondehub.org/recovered", +}; + +// Updated SondeHub position upload function. +// Refer PUT listeners API here: https://generator.swagger.io/?url=https://raw.githubusercontent.com/projecthorus/sondehub-infra/main/swagger.yaml +// @callsign string +// @position object (geolocation position object) +ChaseCar.updatePosition = function(callsign, position) { + if(!position || !position.coords) return; + + // Set altitude to zero if not provided. + _position_alt = ((!!position.coords.altitude) ? position.coords.altitude : 0); + + var _doc = { + "software_name": "SondeHub Tracker", + "software_version": "{VER}", + "uploader_callsign": callsign, + "uploader_position": [position.coords.latitude, position.coords.longitude, _position_alt], + "uploader_antenna": "Mobile Station", + "uploader_contact_email": "none@none.com", + "mobile": true + }; + + // push the doc to sondehub + $.ajax({ + type: "PUT", + url: ChaseCar.db_uri, + contentType: "application/json; charset=utf-8", + dataType: "json", + data: JSON.stringify(_doc), + }); +}; + + +ChaseCar.markRecovered = function(serial, lat, lon, recovered, callsign, notes){ + + var _doc = { + "serial": serial, + "lat": lat, + "lon": lon, + "alt": 0.0, + "recovered": recovered, + "recovered_by": callsign, + "description": notes + }; + + $.ajax({ + type: "PUT", + url: ChaseCar.recovery_uri, + contentType: "application/json; charset=utf-8", + dataType: "json", + data: JSON.stringify(_doc), + }).done(function(data) { + console.log(data); + alert("Recovery Reported OK!"); + }) + .fail(function(jqXHR, textStatus, error) { + try { + _fail_resp = JSON.parse(jqXHR.responseText); + alert("Error Submitting Recovery Report: " + _fail_resp.message); + } catch(err) { + alert("Error Submitting Recovery Report."); + } + }) + +} \ No newline at end of file diff --git a/static/js/tables.js b/static/js/tables.js index 213fbf9..8b7179a 100644 --- a/static/js/tables.js +++ b/static/js/tables.js @@ -79,7 +79,14 @@ function markPayloadRecovered(callsign){ _recovery_data.last_pos = chase_car_position.latest_data; } - socket.emit('mark_recovered', _recovery_data); + if (chase_config.profiles[chase_config.selected_profile].online_tracker === "sondehub"){ + // For sondehub recoveries, do the request in-browser. + ChaseCar.markRecovered(_recovery_data.payload_call, _recovery_data.last_pos[0], _recovery_data.last_pos[1], _recovery_data.recovered, _recovery_data.my_call, _recovery_data.message); + } else { + // Habitat 'recoveries' are a bit more involved, so do these in the backend. + socket.emit('mark_recovered', _recovery_data); + } + }, Cancel: function() { $( this ).dialog( "close" );