Have you ever wondered how long it will take to get an Uber in your location? This project uses ThingSpeak to log the ETA for an Uber service based on your latitude and longitude. We will use ThingSpeak's MATLAB Analysis and TimeControl apps to track the ETA over time.
We will use a ThingSpeak Channel to store data collected from the Uber API.
- Create a new ThingSpeak Channel
- Name: Uber Ride Estimate Data
- Field 1: ETA
- Click "Save Channel"
After the channel is created note the following data:
- Channel ID
- Write API Key
ThingHTTP will allow our project to authenticate to the Uber API, send a command, and parse the response.
- Create a new ThingHTTP
- Name: Uber Ride Estimate
- URL: https://api.uber.com/v1/requests/estimate
- Method: POST
- Content Type: application/json
- HTTP Version: 1.1
- Headers:
- Name: Authorization
- Value: Bearer XXX
- Body: {"product_id":"XXX","start_latitude":"42.300080","start_longitude":"-71.350349"}
- Parse String: pickup_estimate
- Click "Save ThingHTTP"
We will use the MATLAB Analysis app on ThingSpeak to read the data from the Uber API and store it in a ThingSpeak Channel. We will also schedule this to run every 5 minutes using TimeControl.
- Create a new MATLAB Analysis
- Select "Custom (no starter code)"
- Click "Create"
Enter the following code in the MATLAB Code Editor and click "Run and Save":
% Read the ThingHTTP for 'Uber Ride Estimate'
data = webread('https://api.thingspeak.com/apps/thinghttp/send_request?api_key=XXX')
% Convert the response to a number
eta = str2num(data);
% Write the data to the 'Uber Ride Estimate Data' ThingSpeak Channel
thingSpeakWrite(<Channel ID>,eta,'WriteKey','XXX');
If the MATLAB code works, you will see a response from the Uber API. The data is the estimated time of arrival (ETA) of an Uber car to your location.
To schedule this code to run every 5 minutes, click TimeControl under "Schedule Actions".
Time Control Settings
- Name: Scheduled Uber Analysis
- Select Recurring
- Select Minute
- Click "Save TimeControl"
Return to the Private Channel view of the "Uber Ride Estimate Data" channel to see the data on the field1 chart.
Comments