Hey Im trying to work on something that helps me creating routes to collect the trash
I have a arduino that reads the volume and creates a JSON file with the id, volume and coordinates (example: Bin_001/ 75%/ 38.7278772678994, -9.138106466624363)
My problem now is that im not being able to create the routes, maybe i have something wrong
-CODE-
import requests
import json
from openrouteservice import client
# This code gets the list of bins that need to be picked up.
bins = ["a", "b", "c"]
needs_pick = []
coordinates = []
API_KEY = 'YOUR_ORS_API_KEY'
for x in bins:
# This gets the information about the bin, including its ID, volume, and location.
target_url = "http://192.168.1.7/" + x
resp = requests.get(target_url)
bin_id = resp.json()["Bin"]["id"]
volume = 100 - resp.json()["Bin"]["Free_Volume"]
location = resp.json()["Bin"]["Location"]
coordinates.append(location)
# If the bin is more than 75% full, it needs to be picked up.
if volume > 75:
needs_pick.append(bin_id)
# Print the information about the bin.
print("ID: " + bin_id + "\nVolume: " + str(volume) + "%\nLocation: " + str(location) + "\n")
print("---------------------\n")
print("Bins needed to be picked:")
for x in needs_pick:
print("\t->" + x)
# This generates the route using Openrouteservice.
client = client.Client(api_key=API_KEY)
route = client.directions(coordinates[0], coordinates[-1], profile="driving")
# If the route was generated successfully, print the URL of the route.
if route:
print("\nRoute URL: https://www.openrouteservice.org/directions/v2/driving/" + route["coordinates"])
else:
print("Route generation failed.")