33 *
44 * Author: Rossen Gerogiev
55 * Requires: jQuery
6+ *
7+ * Updated to SondeHub v2 by Mark Jessop
68 */
79
810ChaseCar = {
9- db_uri : "https://tracker.habhub.org/" , // db address
10- uuidsRequested : false , // used in .request() to track whenever it has requested uuids
11- _uuids : [ ] , // array with uuids
12- ucount : 20 , // number of uuids in the _uuids array (determines how many uuids are request at a time)
13- uused : 0 , // how many have been used for requests
14- queue : [ ] // request queue, incase we dont have uuids
11+ db_uri : "https://api.v2.sondehub.org/listeners" , // Sondehub API
1512} ;
16- ChaseCar . uused = ChaseCar . ucount ; // we start without any uuids
1713
18- // get some uuids for us to use
19- ChaseCar . getUUIDS = function ( callback ) {
20- $ . getJSON ( ChaseCar . db_uri + "_uuids?count=" + ChaseCar . ucount , function ( data ) {
21- ChaseCar . _uuids = data . uuids ; // load the new uuids
22- ChaseCar . uused = 0 ; // reset counter
23- if ( callback ) callback ( ) ;
24- } ) ;
25- } ;
26- // handles request and uuid management
27- // @doc JSONobject
28- ChaseCar . request = function ( doc ) {
29- if ( doc ) { ChaseCar . queue . push ( doc ) ; }
30-
31- var i = ChaseCar . queue . length ;
32- while ( i -- ) {
33- if ( ChaseCar . ucount == ChaseCar . uused && ! ChaseCar . uuidsRequested ) {
34- ChaseCar . uuidsRequested = true ; // blocks further uuids request until the current one completes
35- ChaseCar . getUUIDS ( function ( ) {
36- ChaseCar . uuidsRequested = false ;
37- ChaseCar . request ( ) ;
38- } ) ;
39- return ;
40- } else {
41- ChaseCar . uused ++ ;
42- // get one uuid and one doc from the queue and push to habitat
43- var uuid = ChaseCar . _uuids . shift ( ) ;
44- doc = ChaseCar . queue . shift ( ) ;
45-
46- // update doc with uuids and time of upload
47- doc . _id = uuid ;
48- doc . time_uploaded = ( new Date ( ) ) . toISOString ( ) ;
49-
50- // push the doc to habitat
51- $ . ajax ( {
52- type : "POST" ,
53- url : ChaseCar . db_uri + "habitat/" ,
54- contentType : "application/json; charset=utf-8" ,
55- dataType : "json" ,
56- data : JSON . stringify ( doc ) ,
57- } ) ;
58- }
59- }
60- } ;
61- // run once at start,
62- // @callsign string
63- ChaseCar . putListenerInfo = function ( callsign ) {
64- if ( ! callsign ) return ;
65-
66- ChaseCar . request ( {
67- 'type' : "listener_information" ,
68- 'time_created' : ( new Date ( ) ) . toISOString ( ) ,
69- 'data' : { 'callsign' : callsign }
70- } ) ;
71- } ;
72- // run every time the location has changed
14+ // Updated SondeHub position upload function.
15+ // Refer PUT listeners API here: https://generator.swagger.io/?url=https://raw.githubusercontent.com/projecthorus/sondehub-infra/main/swagger.yaml
7316// @callsign string
7417// @position object (geolocation position object)
7518ChaseCar . updatePosition = function ( callsign , position ) {
7619 if ( ! position || ! position . coords ) return ;
7720
78- ChaseCar . request ( {
79- 'type' : "listener_telemetry" ,
80- 'time_created' : ( new Date ( ) ) . toISOString ( ) ,
81- 'data' : {
82- 'callsign' : callsign ,
83- 'chase' : true ,
84- 'latitude' : position . coords . latitude ,
85- 'longitude' : position . coords . longitude ,
86- 'altitude' : ( ( ! ! position . coords . altitude ) ? position . coords . altitude : 0 ) ,
87- 'speed' : ( ( ! ! position . coords . speed ) ? position . coords . speed : 0 ) ,
88- 'client' : {
89- 'name' : 'Habitat Mobile Tracker' ,
90- 'version' : '{VER}' ,
91- 'agent' : navigator . userAgent
92- }
93- }
94- } ) ;
95- } ;
21+ // Set altitude to zero if not provided.
22+ _position_alt = ( ( ! ! position . coords . altitude ) ? position . coords . altitude : 0 ) ;
23+
24+ var _doc = {
25+ "software_name" : "SondeHub Tracker" ,
26+ "software_version" : "{VER}" ,
27+ "uploader_callsign" : callsign ,
28+ "uploader_position" : [ position . coords . latitude , position . coords . longitude , _position_alt ] ,
29+ "uploader_antenna" : "Mobile Station" ,
30+ "uploader_contact_email" :
"[email protected] " , 31+ "mobile" : true
32+ } ;
33+
34+ // push the doc to sondehub
35+ $ . ajax ( {
36+ type : "PUT" ,
37+ url : ChaseCar . db_uri ,
38+ contentType : "application/json; charset=utf-8" ,
39+ dataType : "json" ,
40+ data : JSON . stringify ( _doc ) ,
41+ } ) ;
42+ } ;
0 commit comments