isEpochExisting($tracker_id, $epoch)) { $result = $sql->addLocation( $accuracy, $altitude, $battery_level, $heading, $description, $event, $latitude, $longitude, $radius, $trig, $tracker_id, $epoch, $vertical_accuracy, $velocity, $pressure, $connection ); if ($result) { http_response_code(200); _log('Insert OK'); } else { http_response_code(500); $response_msg = 'Can\'t write to database'; _log('Insert KO - Can\'t write to database.'); } } else { _log('Duplicate location found for epoc ' . $epoch . ' / tid ' . $tracker_id . ' - no insert'); $response_msg = 'Duplicate location found for epoch. Ignoring.'; } } else { http_response_code(204); _log('OK type is not location: ' . $data['_type']); } $response = array(); // Build list of buddies' last locations $buddies = $sql->getAllLatestMarkers(); foreach ($buddies as $buddy) { $loc = array( '_type' => 'location', 'acc' => $buddy['accuracy'], 'alt' => $buddy['altitude'], 'batt' => $buddy['battery_level'], 'cog' => $buddy['heading'], 'lat' => $buddy['latitude'], 'lon' => $buddy['longitude'], 'rad' => $buddy['radius'], 't' => $buddy['trig'], 'tid' => strval($buddy['tracker_id']), 'tst' => $buddy['epoch'], 'vac' => $buddy['vertical_accuracy'], 'vel' => $buddy['velocity'], 'p' => $buddy['pressure'], 'conn' => $buddy['connection'], ); $response[] = $loc; } if (!is_null($response_msg)) { // Add status message to return object (to be shown in app) $response[] = array( '_type' => 'cmd', 'action' => 'action', 'content' => $response_msg, ); } print json_encode($response);