SOLVED Sorry, non-Teensy question, but I need help getting data from a web server using ESP32

KrisKasprzak

Well-known member
All,

I realize this is purely an ESP32 question, and I apologize for asking it here, but this forum is too helpful for me to go elsewhere.

I have a working ESP32 can can ping the national weather service for data. I can also get stock data from yahoo. Passing a special URL and i get a JSON back--which I can parse.

I'm now trying to get data from Race Monitor https://www.race-monitor.com/. I have an account, a personal token ,and end point addresses--basically everything I need to ping their sever and get JSON data back. I have a test curl that works and returns data, so I know my token and end points are valid.

curl: curl https://api.race-monitor.com/v2/Common/CurrentRaces --data "apiToken=MY_PERSONAL_TOKEN"

curl_results.jpg


I'm trying to feed the url and token into the ESP like I do with other programs but I only get back a 403 error. I'm not sure how (or if I can send the curl using the web libraries for the ESP

The help documentation makes is sound easy, but i'm out of my area of expertise

api_01.jpg


Here's my code, I'm guessing the issue is how I use the POST method, but not sure. Any know what I can do? Race Monitor support will not assist debugging at this level.

Code:
#include <WiFi.h>        // Use in additional boards manager https://dl.espressif.com/dl/package_esp32_index.json
#include <WebServer.h>   // Use in additional boards manager https://dl.espressif.com/dl/package_esp32_index.json
#include <HTTPClient.h>  // Use in additional boards manager https://dl.espressif.com/dl/package_esp32_index.json


// enter your local intranet SSID and password
#define HOME_SSID "MY_HOME_SSID"
#define PASSWORD "MY_PASSWORD"


const char *token = "apiToken=MY_PERSONAL_TOKEN";
const char *serverName = "https://api.race-monitor.com/v2/Common/CurrentRaces/";

int httpResponseCode = 0;

IPAddress Actual_IP;
IPAddress PR_IP(192, 168, 1, 1);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress ip;

WebServer server(80);
HTTPClient http;

void setup() {

  Serial.begin(115200);
  Serial.println("Starting");

  WiFi.begin(HOME_SSID, PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Actual_IP = WiFi.localIP();

  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  http.setTimeout(6000);

  http.begin(serverName);

  httpResponseCode = http.POST(token);

  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);
 
  // if successful I can parse the JSON.
 
  // i get a 403
  //"You'll receive this message if your API Token isn't valid,
  // or if you're not allowed to access the requested data. Some data may
  // not be available via the API for varying reasons (e.g., race has forbidden
  // third party access).

  http.end();
}


void loop() {
}
 
Last edited:
Back
Top