Skip to content

Adding Weather driver for WeatherFlow#2258

Merged
knro merged 9 commits into
indilib:masterfrom
beettlle:tempest
Aug 2, 2025
Merged

Adding Weather driver for WeatherFlow#2258
knro merged 9 commits into
indilib:masterfrom
beettlle:tempest

Conversation

@beettlle

Copy link
Copy Markdown
Contributor

WeatherFlow makes some great weather devices. This adds WeatherFlow as a weather driver.

Comment thread drivers/weather/weatherflow.cpp Outdated
Comment thread drivers/weather/weatherflow.cpp Outdated
Comment thread drivers/weather/weatherflow.cpp Outdated
Comment on lines +131 to +134
char api_key[256] = {0};
IUGetConfigText(getDeviceName(), "WF_API_KEY", "API_KEY", api_key, 256);
wfAPIKeyTP[0].fill("API_KEY", "API Key", api_key);
wfAPIKeyTP.fill(getDeviceName(), "WF_API_KEY", "WeatherFlow", OPTIONS_TAB, IP_RW, 60, IPS_IDLE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the first two line and simply add after the wfAPIKeyTP.fill, this line:

wfAPIKeyTP.load();

This should load the config automatically.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread drivers/weather/weatherflow.cpp Outdated
Comment on lines +137 to +140
char station_id[256] = {0};
IUGetConfigText(getDeviceName(), "WF_STATION_ID", "STATION_ID", station_id, 256);
wfStationIDTP[0].fill("STATION_ID", "Station ID", station_id);
wfStationIDTP.fill(getDeviceName(), "WF_STATION_ID", "WeatherFlow", OPTIONS_TAB, IP_RW, 60, IPS_IDLE);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Comment thread drivers/weather/weatherflow.cpp Outdated
Comment on lines +428 to +443
CURL *curl = curl_easy_init();
if (!curl)
{
LOG_ERROR("Failed to initialize CURL.");
return false;
}

std::string url = API_BASE_URL + endpoint;
char errorBuffer[CURL_ERROR_SIZE] = {0};

curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, static_cast<long>(wfSettingsNP[WF_CONNECTION_TIMEOUT].getValue()));
curl_easy_setopt(curl, CURLOPT_USERAGENT, "INDI-WeatherFlow/1.0");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for using CURL? In INDI, we typically used httplib::Client to handle API requests. You can checkout DragonLight driver for an example implementation. It's much cleaner than using CURL directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't look at the codebase enough so I did what I knew, my mistake.

@knro

knro commented Aug 1, 2025

Copy link
Copy Markdown
Contributor

@beettlle I tried to fix a couple of errors on my own, but there are more now. Please try to fix the rest.

@beettlle

beettlle commented Aug 2, 2025

Copy link
Copy Markdown
Contributor Author

Sorted my setup and it's not compiling without any errors:

% make -C build/drivers/weather indi_weatherflow_weather
[  0%] Built target hid
[ 10%] Built target indicore
[ 21%] Built target indidevice
[ 21%] Built target eventloop
[ 31%] Built target dsp
[ 36%] Built target fpack
[ 94%] Built target indidriver_OBJECT
[ 94%] Built target indidriver
[ 94%] Building CXX object drivers/weather/CMakeFiles/indi_weatherflow_weather.dir/weatherflow.cpp.o
[100%] Linking CXX executable indi_weatherflow_weather
[100%] Built target indi_weatherflow_weather

Also found a small omission in the Docker README

@knro knro merged commit bb9eae4 into indilib:master Aug 2, 2025
11 checks passed
knro added a commit to knro/indi that referenced this pull request Aug 25, 2025
* Adding Weather driver for WeatherFlow

* Fixing per @knro comments

* Refactor authorization header construction in WeatherFlow API request for improved clarity and consistency

* Removed CURL and fixed some functions

* Update weatherflow.cpp

* Update weatherflow.h

* Update Docker README for clarity and fix authorization header construction in WeatherFlow API request

---------

Co-authored-by: Jasem Mutlaq <mutlaqja@ikarustech.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants