user63496: For a larger sketch, I have separated a chunk of code in a separate .cpp file
#include "msg.h"
#include <Arduino.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv)
{


    String json = payload;

    // Serial.println(json); // enable to debug

    StaticJsonDocument<128> filter;

    JsonObject filter_current = filter.createNestedObject("current");
    filter_current["temp_c"] = true;
    filter_current["wind_mph"] = true;
    filter_current["pressure_mb"] = true;
    filter_current["precip_in"] = true;
    filter_current["humidity"] = true;
    filter_current["feelslike_c"] = true;
    filter_current["uv"] = true;

    StaticJsonDocument<256> doc;

    // Deseriliaze and display error description if there is any
    DeserializationError error = deserializeJson(doc, json, DeserializationOption::Filter(filter));

    if (error)
    {
        Serial.print("deserializeJson() failed: ");
        Serial.println(error.c_str());
        return;
    }

    JsonObject current = doc["current"];
    temp = current["temp_c"];          // 80
    wind = current["wind_mph"];        // 5.6
    pressure = current["pressure_mb"]; // 1005
    humid = current["humidity"];       // 93
    feel = current["feelslike_c"];     // 6.9
    uv = current["uv"];                // 1
}

together with its header file as below:
#ifndef MSG_H
#define MSG_H

void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);

#endif

I have included all the relevant libraries in the .cpp files. However, when I try to compile the code I get multiple errors such as
In file included from src/weatherapi.cpp:1:0:
include/weatherapi.h:4:17: error: variable or field 'getRequest' declared void
 void getRequest(String &payload);
                 ^
include/weatherapi.h:4:17: error: 'String' was not declared in this scope
include/weatherapi.h:4:25: error: 'payload' was not declared in this scope
 void getRequest(String &payload);
                         ^
Archiving .pio\build\lolin32\liba47\libPubSubClient.a
In file included from src/msg.cpp:1:0:
include/msg.h:4:20: error: variable or field 'parseResponse' declared void
 void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);
                    ^
include/msg.h:4:20: error: 'String' was not declared in this scope
include/msg.h:4:28: error: 'payload' was not declared in this scope
 void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);
                            ^
include/msg.h:4:37: error: expected primary-expression before 'float'
 void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);
                                     ^
include/msg.h:4:50: error: expected primary-expression before 'float'
 void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);
                                                  ^
include/msg.h:4:63: error: expected primary-expression before 'int'
 void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);
                                                               ^
include/msg.h:4:78: error: expected primary-expression before 'int'
 void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);
                                                                              ^
include/msg.h:4:90: error: expected primary-expression before 'float'
 void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);
                                                                                          ^
include/msg.h:4:103: error: expected primary-expression before 'int'
 void parseResponse(String &payload, float &temp, float &wind, int &pressure, int &humid, float &feel, int &uv);

The function parseResponse doesn't return anything so I don't know why it's complaining about being declared as void. Same is true for the function getRequest. Also, is there something wrong in the function prototype as I am passing references?
Edit: Here is the weatherapi.cpp & .h file
#include "weatherapi.h"
#include <HTTPClient.h>
#include <Arduino.h>

const char url[] = "http://api.weatherapi.com/v1/current.json?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

void getRequest(String &payload)
{

     HTTPClient getClient;

    getClient.begin(url);

   
    int httpCode = getClient.GET();

    //get response and check HTTP status code returned
    if (httpCode > 0)
    {
        payload = getClient.getString();
        Serial.print("HTTP Status: ");
        Serial.println(httpCode);
    }
    else
    {
        Serial.println("Error on HTTP request");
    }
   
    getClient.end();
} 

weatherapi.h file
#ifndef WEATHERAPI_H
#define WEATHERAPI_H

void getRequest(String &payload);
#endif

                                                                                             


user4143: In C order is important. Everything is parsed sequentially, and header file inclusions are replaced literally with the header contents at compile time.
Things must be defined before they can be used, and that includes anything that is defined in the Arudino.h header file - that file must be included before anything that uses it - and of course that means that it must come before any headers that use things from Arduino.h
To be safer it's good to include Arduino.h in every file that uses anything from it so you don't run into these problems in future.

63496: <p>For a larger sketch, I have separated a chunk of code in a separate .cpp file</p>
<pre><code>#include &quot;msg.h&quot;
#include &lt;Arduino.h&gt;
#include &lt;HTTPClient.h&gt;
#include &lt;ArduinoJson.h&gt;

void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv)
{


    String json = payload;

    // Serial.println(json); // enable to debug

    StaticJsonDocument&lt;128&gt; filter;

    JsonObject filter_current = filter.createNestedObject(&quot;current&quot;);
    filter_current[&quot;temp_c&quot;] = true;
    filter_current[&quot;wind_mph&quot;] = true;
    filter_current[&quot;pressure_mb&quot;] = true;
    filter_current[&quot;precip_in&quot;] = true;
    filter_current[&quot;humidity&quot;] = true;
    filter_current[&quot;feelslike_c&quot;] = true;
    filter_current[&quot;uv&quot;] = true;

    StaticJsonDocument&lt;256&gt; doc;

    // Deseriliaze and display error description if there is any
    DeserializationError error = deserializeJson(doc, json, DeserializationOption::Filter(filter));

    if (error)
    {
        Serial.print(&quot;deserializeJson() failed: &quot;);
        Serial.println(error.c_str());
        return;
    }

    JsonObject current = doc[&quot;current&quot;];
    temp = current[&quot;temp_c&quot;];          // 80
    wind = current[&quot;wind_mph&quot;];        // 5.6
    pressure = current[&quot;pressure_mb&quot;]; // 1005
    humid = current[&quot;humidity&quot;];       // 93
    feel = current[&quot;feelslike_c&quot;];     // 6.9
    uv = current[&quot;uv&quot;];                // 1
}
</code></pre>
<p>together with its header file as below:</p>
<pre><code>#ifndef MSG_H
#define MSG_H

void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);

#endif
</code></pre>
<p>I have included all the relevant libraries in the .cpp files. However, when I try to compile the code I get multiple errors such as</p>
<pre><code>In file included from src/weatherapi.cpp:1:0:
include/weatherapi.h:4:17: error: variable or field 'getRequest' declared void
 void getRequest(String &amp;payload);
                 ^
include/weatherapi.h:4:17: error: 'String' was not declared in this scope
include/weatherapi.h:4:25: error: 'payload' was not declared in this scope
 void getRequest(String &amp;payload);
                         ^
Archiving .pio\build\lolin32\liba47\libPubSubClient.a
In file included from src/msg.cpp:1:0:
include/msg.h:4:20: error: variable or field 'parseResponse' declared void
 void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);
                    ^
include/msg.h:4:20: error: 'String' was not declared in this scope
include/msg.h:4:28: error: 'payload' was not declared in this scope
 void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);
                            ^
include/msg.h:4:37: error: expected primary-expression before 'float'
 void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);
                                     ^
include/msg.h:4:50: error: expected primary-expression before 'float'
 void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);
                                                  ^
include/msg.h:4:63: error: expected primary-expression before 'int'
 void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);
                                                               ^
include/msg.h:4:78: error: expected primary-expression before 'int'
 void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);
                                                                              ^
include/msg.h:4:90: error: expected primary-expression before 'float'
 void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);
                                                                                          ^
include/msg.h:4:103: error: expected primary-expression before 'int'
 void parseResponse(String &amp;payload, float &amp;temp, float &amp;wind, int &amp;pressure, int &amp;humid, float &amp;feel, int &amp;uv);
</code></pre>
<p>The function parseResponse doesn't return anything so I don't know why it's complaining about being declared as void. Same is true for the function getRequest. Also, is there something wrong in the function prototype as I am passing references?</p>
<p>Edit: Here is the weatherapi.cpp &amp; .h file</p>
<pre><code>#include &quot;weatherapi.h&quot;
#include &lt;HTTPClient.h&gt;
#include &lt;Arduino.h&gt;

const char url[] = &quot;http://api.weatherapi.com/v1/current.json?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;;

void getRequest(String &amp;payload)
{

     HTTPClient getClient;

    getClient.begin(url);

   
    int httpCode = getClient.GET();

    //get response and check HTTP status code returned
    if (httpCode &gt; 0)
    {
        payload = getClient.getString();
        Serial.print(&quot;HTTP Status: &quot;);
        Serial.println(httpCode);
    }
    else
    {
        Serial.println(&quot;Error on HTTP request&quot;);
    }
   
    getClient.end();
} 
</code></pre>
<p>weatherapi.h file</p>
<pre><code>#ifndef WEATHERAPI_H
#define WEATHERAPI_H

void getRequest(String &amp;payload);
#endif

                                                                                             
</code></pre>
 4143: <p>In C order is important. Everything is parsed sequentially, and header file inclusions are replaced literally with the header contents at compile time.</p>
<p>Things <em>must</em> be defined before they can be used, and that includes anything that is defined in the <code>Arudino.h</code> header file - that file <em>must</em> be included <em>before</em> anything that uses it - and of course that means that it must come before any headers that use things from <code>Arduino.h</code></p>
<p>To be safer it's good to include <code>Arduino.h</code> in <em>every</em> file that uses anything from it so you don't run into these problems in future.</p>
