Get an Uber ride just by pressing a button!
IntroductionIn this tutorial, we will be using the Sigfox network localization service (which can, for now, give at most a 1km radius position precision) in order to get a the closest position to a specified address and request an Uber ride accordingly. Therefore, we do not need a device with GPS.
We will use a Sens'it but any device able to send a message over Sigfox can be used to accomplish this tutorial successfully.
Have a look here if you wish to have more details regarding Sigfox makers.
Hardware- A Sens'it (or any other device able to send a Sigfox message)
We will be automating the ordering process of a ride request by calling Uber API endpoints.
In order to understand how this is possible, please make sure to check out the node module I developed for usage simplicity and clarity purposes. You will need an access token to the Uber API for it to work. The proceedure of how to get this token can be found on this GitHub page.
Prerequisites- An Uber valid account
- Your Uber API access token (check above for how to get it)
- An activated device on the Sigfox Backend (follow this link for the Sens'it activation). You will need the device ID and PAC.
In app.js
, two addresses structures will be created as follow (with values defined in environment variables):
const address_1 = {
'name': process.env.ADDRESS_1_NAME,
'lat': process.env.ADDRESS_1_LAT,
'lng': process.env.ADDRESS_1_LNG
};
const address_2 = {
'name': process.env.ADDRESS_2_NAME,
'lat': process.env.ADDRESS_2_LAT,
'lng': process.env.ADDRESS_2_LNG
};
These addresses will be used to specify the pick-up and drop-off locations. We will set them later.
If the Sens'it device sends its geo-localized position nearest to address #1, then address #1 is set as pick-up and address #2 is set as drop-off for the ride request. And so on for the reverse...
If the Sigfox Backend geo-location service returns a precision radius bigger than the distance between the two addresses, the Uber request will not be executed (as the arrival destination can not be determined).
Deploy on HerokuI wrote an app using NodeJS to automate the ordering process. Click the button below to automatically deploy it on Heroku.
An alternative way to get it running at Heroku is to install the Heroku Cli and follow these steps:
$ git clone https://github.com/AntoinedeChassey/sigfox_uber.git
$ cd sigfox_uber
$ heroku apps:create
$ git push heroku master
Now, head over to the settings
tab of your Heroku app (https://dashboard.heroku.com/apps/<YOUR_APP_NAME>/settings) in order to set the environment variables. Set the following variables (make sure to set the addresses you wish):
ACCESS_TOKEN | <YOUR_UBER_ACCESS_TOKEN>
ADDRESS_1_LAT | 49.009698
ADDRESS_1_LNG | 2.547882
ADDRESS_1_NAME | airport
ADDRESS_2_LAT | 48.876579
ADDRESS_2_LNG | 2.330618
ADDRESS_2_NAME | office
The endpoint ".../request/:device/:lat/:lng/:radius" will be called each time a message is sent to the Sigfox Backend (see below how to configure it). By using the Sigfox geolocalization service, the server will receive the Sens'it approximated position. This will then order an UberX with the determined pick-up and drop-off addresses.
To check if the app is running, go to its URL. You should see "App is running..." on your browser. You can also check the logs for more details.
[Optional] Free SMS notifications with a french mobile operator (named Free)If you have a french Free mobile operator subscription, you can use their free SMS notification API in order to get notifications on your phone. To make this work, simply activate the service in your subscriber area and refer the following environment variables in the settings tab of your Heroku app:
FREE_USER | <YOUR_FREE_USER>
FREE_PASS | <YOUR_FREE_PASS>
You will now be able to receive SMS alerts concerning your UberX requests.
Configure the Sigfox Backend Callback- Log in here
- Go to https://backend.sigfox.com/devicetype/list, click left on your device row and select "Edit"
- Now go to the "CALLBACKS" section on the left, select "new" on the top right, select "Custom Callback"
- Type:
SERVICE
|GEOLOC
- Channel
URL
- Url pattern:
https://<YOUR_APP_NAME>.herokuapp.com/request/{device}/{lat}/{lng}/{radius}
- Use HTTP Method:
GET
- Select "OK" to validate
By default, the sandbox
variable is set to true
. This will fake Uber ride requests so your bank account does not get affected by unintentional manipulations π.
Press the Sens'it button twice to send a message over Sigfox. Make sure the messages are well received on the Sigfox Backend. Log in, go to the DEVICE section and click left on your device Id. You can than go the MESSAGES section to see the payloads.
Order a real Uber rideNow set the sandbox
environment variable to false
if you wish to request a real Uber driver.
SANDBOX | false
- The Sens'it button will call the path
.../request/:device/:lat/:lng/:radius
and trigger the Uber ride request!
- You can also see the current request status on
.../request/current
.
- To cancel an order, this path can be used:
.../request/cancel
.
Let's drive!
Have fun ordering your Ubers! π π
Antoine de Chassey
Comments