Server App issues [Heroku]

Hello Drone Deploy Community

I got an issue with the Server App setup ( described at this link : https://dronedeploy.gitbooks.io/dronedeploy-apps/content/server_example.html)

I’m a user of heroku , if think it s fine , API Key from Google are ok.

But when i load the app in the browser , i got a 404 ERROR
https://stardrone-server.herokuapp.com

i think it’s the tornado module can’t GET , my console ask me this error :
WARNING:tornado.access:404 GET / (::1) 0.75ms

I think the issue is from the CORS ( HTTP control access) but i have no ideo how to fix it.

Anyone has managed to setup this server ?

thanks for help .

the python code :

import os

import requests
import tornado.ioloop
import tornado.web

GEOCODE_FMT = ‘https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={key}

class GeocodeHandler(tornado.web.RequestHandler):
“”“Proxy a call to the Google Maps geocode API”""

def set_default_headers(self):
    # allow cross-origin requests to be made from your app on DroneDeploy to your web server
    self.set_header("Access-Control-Allow-Origin", "https://www.dronedeploy.com")
    self.set_header("Access-Control-Allow-Headers", "x-requested-with")
    # add more allowed methods when adding more handlers (POST, PUT, etc.)
    self.set_header("Access-Control-Allow-Methods", "GET, OPTIONS")
def get(self):
    api_key = os.environ.get("**mykey**")
    address = self.get_query_argument("address")
    url = GEOCODE_FMT.format(address=address, key=api_key)
    # fetch results of the geocode from Google
    response = requests.get(url)
    # send the results back to the client
    self.write(response.content)
def options(self):
    # no body
    self.set_status(204)
    self.finish()

def main():
application = tornado.web.Application([
(r"/geocode/", GeocodeHandler)
])
port = int(os.environ.get(“PORT”, 5000))
application.listen(port)
tornado.ioloop.IOLoop.current().start()

if name == “main”:
main()

Any help are welcome , thank you

john

Hi @john_sinien one of our engineers says that your tornado routes aren’t being picked up by heroku.

$ curl -v -X OPTIONS "https://stardrone-server.herokuapp.com/geocode/address=1+Market+St,San+Francisco,CA" -H "Origin: https://www.dronedeploy.com"
*   Trying 54.225.133.127...
* TCP_NODELAY set
* Connected to stardrone-server.herokuapp.com (54.225.133.127) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.herokuapp.com
* Server certificate: DigiCert SHA2 High Assurance Server CA
* Server certificate: DigiCert High Assurance EV Root CA
> OPTIONS /geocode/address=1+Market+St,San+Francisco,CA HTTP/1.1
> Host: stardrone-server.herokuapp.com
> User-Agent: curl/7.51.0
> Accept: */*
> Origin: https://www.dronedeploy.com
> 
< HTTP/1.1 404 Not Found
< Connection: keep-alive
< Server: TornadoServer/4.4.2
< Content-Type: text/html; charset=UTF-8
< Content-Length: 69
< Date: Mon, 27 Mar 2017 22:25:47 GMT
< Via: 1.1 vegur
< 
* Curl_http_done: called premature == 0
* Connection #0 to host stardrone-server.herokuapp.com left intact
<html><title>404: Not Found</title><body>404: Not Found</body></html>

Hello Manu,

thanks for helping.
I try to found how to routes this … but it seems i didn’t manage to fix it.

Any idea ?

Hi @john_sinien,

Maybe not the answer you were looking for but here is how you can get that information with Javascript.

  1. Get your mapbox API Key here https://www.mapbox.com/studio/account/tokens/

  2. Replace <YOUR_API_KEY_HERE> with the above api key and run this code in your chrome console.

function getReadableAddressFromLatLng(latLng){
  return fetch(`https://api.mapbox.com/geocoding/v5/mapbox.places/${latLng.lng},${latLng.lat}.json?access_token=<YOUR_API_KEY_HERE>`)
    .then(function(res){
      return res.json();
    })
    .then(function(geoLocation){
      return geoLocation.features[0] && geoLocation.features[0].place_name
    });
}

function getLatLngFromAddress(address){
  return fetch(`https://api.mapbox.com/geocoding/v5/mapbox.places/${address}.json?access_token=<YOUR_API_KEY_HERE>`)
    .then(function(res){
      return res.json();
    })
    .then(function(geoLocation){
      var location = geoLocation.features[0];
      return location && ({lat: location.center[1], lng: location.center[0]})
    })
}


getReadableAddressFromLatLng({lat: 37.773972, lng: -122.431297})
  .then(function(locationName){
    console.log(locationName); // 712 Oak St, San Francisco, California 94117, United States
  });

getLatLngFromAddress('712 Oak St, San Francisco, California 94117, United States')
  .then(function(latLng){
    console.log(latLng); //  {lat: 37.774147, lng: -122.431287}
  });

Hope that helps,
Dan.

Hi Daniel ,

The MapBox script you gave me work fine in my JsConsole. But how i can implement it in order to communicate with the Drone Deploy APi ?

Hi @john_sinien,

Here is the source code for an app market app using the above functionality.
https://drive.google.com/file/d/0B8wMK91WLtD0M0hPLUJDTlNlNjg/view

You can test the above app by installing it and going to a map you’ve created.
https://www.dronedeploy.com/app2/applications/58e017eb54f7652ec13dc6de/install

Let me know if that answers your question. If you tell me more about your intended app, I might be able to help further.

Dan.

Hi Daniel ,

thanks for your help; and this source code.

i’m confuse now.

How i can install this server on a Map i created ? you mean a flight plan ? Sorry about this question.
Believe me i try to found the answer before asking.

I’m working on two project : on for detecting nest of hornets and another for mapping… the Sky.

Hi @john_sinien,

Have you looked at Cogniac? It’s a brand new app on the market that allows for object detection of anything.

For example if you want to automatically detect hornet nests. You’ll need to export a few maps containing hornet nests to cogniac via their integration. And then you will label the nest and then you’ll be able to automatically detect nests in the future.

Give it a try.
https://www.dronedeploy.com/app2/applications/tquxyohogwnriufokcin/install

If you train a model you should be able to work with their API to publish a standalone app to share your hornet detection app.

Would be interested in hearing more about your second idea.

Dan.

Hello ,

thanks for help and reply.

I’m still workin’ on the App. i will make a description soon.