Getting Data From Open Meteo with a Webhook

Table of contents

  1. Getting Started
  2. Setting up a webhook - Getting the Weather
  3. Requesting Weather Information

In this tutorial, we’re going to setup a webhook called get-forecast that will get information from Open Meteo - an online platform that specializes in weather forecasting.

When we’re finished, we’ll have set up a webhook that will ask for one bit of information - the latitude and longitude for the place you want weather info on - and it sends back four things:

  1. a descriptive label for the current weather in that location (e.g. cloudy, rain, etc.)
  2. the temperature
  3. the weather code (indicating if it’s clear skies, foggy, drizzly, etc.)
  4. the windspeed
  5. the wind direction

We’ll connect this into our code, have it look up weather information for Pittsburgh (lat: 40.4406, long: -79.9959), and collect the response!

Getting Started

To get started you’ll need to register for a DarkSky account.

  1. Visit and move through the URL builder

    • Add the coordinates for the city you’d like weather for.
    • Under Settings, enable ‘current weather with temperature and set the units to your preferred measures.
    • Click Preview Chart to update the URL
  2. Once you’ve once you’ve done, this, you’ll see an API URL that looks like This is the URL we’ll use as part of our Webhook to request information. You’ll see it contains a) the latitude and longitude of the location you want to get weather predictions about and b) the parameters you’ve configured in the settings section. If you visit the link you’ll see a big detailed response like:


This is known as a JSON (or javascript object notation) formatted response. It’s a common format for sharing raw data through API or web service calls. Particle webhooks require the web resource you want information from to respond with a JSON reply. If it doesn’t send information in this way - it might not work with a webhook.

You’ll also notice the volume of information this web response contains. It’s a lot. More information than our particle device can handle; and this explains why we can’t just have our Particle microcontroller directly request the information.

Using a service like JSONPrettyPrint, you can reformat the response into something more organized and readable. I recommend doing this as you experiment with webhooks. After doing this, the data will look more like this:

  "latitude": 52.52,
  "longitude": 13.419,
  "elevation": 44.812,
  "generationtime_ms": 2.2119,
  "utc_offset_seconds": 0,
  "timezone": "Europe/Berlin",
  "timezone_abbreviation": "CEST",
  "hourly": {
    "time": ["2022-07-01T00:00", "2022-07-01T01:00", "2022-07-01T02:00", ...],
    "temperature_2m": [13, 12.7, 12.7, 12.5, 12.5, 12.8, 13, 12.9, 13.3, ...]
  "hourly_units": {
    "temperature_2m": "°C"
  "current_weather": {
    "time": "2022-07-01T09:00",
    "temperature": 13.3,
    "weathercode": 3,
    "windspeed": 10.3,
    "winddirection": 262

Great. Now you can see exactly what it contains. A lot. For this scenario, however, I really only care about the current weather. And I can see that this is contained in a object called current_weather. current_weather has a lot of child elements including time and temperature which is 13.3. We can use this nested structure to specify what information you want to include in your webhook response and filter it down. This is done with a simple templating language

For example, if I only only want the current temperature I could access this by using `` or the wind speed by using . We’ll get back to this later.

For now you’re set up, your API key is working and you have a URL that you can use to request information as part of your webhook. Now, let’s create the webhook.

Setting up a webhook - Getting the Weather

Go to the Particle Console and sign in. On the left hand side there’s a small icon bar, you’ll find an option for ‘Integrations’.

Click it and choose the option to add a new integration. You’ll get four options like this. Choose the webhook.

You’ll then be asked to add the info for your webhook.

Add the following:

  • Event Name: get-forecast
  • URL:
  • Request Type: GET
  • Request Format: Query Parameters
  • Device: Any

Select the Advanced Options:

  • Under Response Template, add the following:

{{current_weather.temperature}}~{{ current_weather.weathercode }}~{{ current_weather.windspeed }}

This is your response template. It will filter out the current temperature, precipitation and icon. Each will be separated by a ~

Then create the WebHook!

Requesting Weather Information

We’re going to add two pieces of code to help get data on the weather in Pittsburgh Copy and paste the following into the end of your code file

void getData()
	// Publish an event to trigger the webhook
  Particle.publish( "get-forecast" );

// This function will handle data received back from the webhook
void handleForecastReceived(const char *event, const char *data) {
  // Handle the integration response

  String receivedStr =  String( data );
  int loc1 = 0;
  int loc2 = 0;

  loc1 = receivedStr.indexOf("~");

  temperature = receivedStr.substring(0,loc1);

  loc2 = receivedStr.indexOf("~",loc1+1);
  weatherCode = (double) String(receivedStr.substring(loc1+1,loc2)).toFloat();

  windSpeed = (double) String(receivedStr.substring(loc2+1)).toFloat();


The following codde will break up the string based on the position of the ~ and extract the bits of information we care about. Finally it converts the right information to numbers where appropriate.

Making progress.

Now you also need to tell your Particle to listen for the response to the webhook. To do this, add this line of code to the end of your setup()

Particle.subscribe("hook-response/get-forecast", handleForecastReceived );

This registers for the webhook response and maps it into the function we just added…

Now one last thing, we need to publish the event and trigger the webhook. Let’s do this when the device first starts. To do this, add the following line right before the end of the setup()’s last curly bracket.


You know the drill. Save your code. Flash your code. Fingers crossed. It’ll appear on your Particle! To know if it worked, open up the console ( and you should see something like this when the device restarts

Nice work!

Table of contents