It is currently May 5th, 2024, 6:48 am

Passing result of WebParser into custom plugin

Get help with creating, editing & fixing problems with skins
spook
Posts: 7
Joined: September 9th, 2020, 2:07 pm

Passing result of WebParser into custom plugin

Post by spook »

Hi!

I wrote a custom plugin in pure C++ called JsonParser, which, surprise, parses JSON input. I'm accepting source and query; source should be JSON and query is in dot/array notation, such as:

member["member2"].member3[5].member4

I wrote a lot of unit tests, so I'm quite certain, that the plugin works correctly (moreover I tested it too in Rainmeter by passing raw JSON as source).

I'm trying to make my plugin work with WebParser and I'm having difficulties passing data from the latter to the former. Skin source looks more like following:

Code: Select all

[Rainmeter]
Update=1000

[Variables]
TextSize=24
TextForeground=0,0,0,255
BackgroundFrom=255,255,255,80
BackgroundTo=255,255,255,40

[TextStyle]
FontFace=Segoe UI Light
FontSize=#TextSize#
AntiAlias=1

[MeasureWeather]
Measure=WebParser
UpdateRate=60
URL=https://api.openweathermap.org/data/2.5/onecall?lat=51.10&lon=17.03&units=metric&appid=(API-KEY-HIDDEN)
RegExp=(?siU)^(.*)$
Debug=1

[MeasureWeather1]
Measure=WebParser
URL=[MeasureWeather]
StringIndex=1

[MeasureTemperature]
Measure=Plugin
Plugin=PluginJsonParser
Source=[MeasureWeather1]
Query=current.temp

[MeterBackground]
Meter=Shape
Shape=Rectangle 0,0,200,50,5,5 | Fill LinearGradient BackgroundGradient | Stroke Color 0,0,0,0
BackgroundGradient=90 | #BackgroundFrom# ; 0.0 | #BackgroundTo# ; 1.0

[MeterTemperature]
Meter=String
MeasureName=MeasureTemperature
MeterStyle=TextStyle
X=35
Y=3
FontColor=#TextForeground#
The problem is, that no JSON is passed to my plugin. When I switch MeterTemperature to display MeasureWeather1, it shows the JSON. But all I'm getting as source in my plugin is just "[MeasureWeather1]" (I'm outputting received source as logs).

So the question: why Rainmeter is not passing measure contents to my plugin? Or should I do something special to evaluate final string in the plugin? The plugin itself gets data in the following way:

Code: Select all

void Measure::reload(void* rm, double* maxValue)
{
	this->source = std::wstring(RmReadString(rm, L"Source", L"", FALSE));
	this->query = std::wstring(RmReadString(rm, L"Query", L"", FALSE));

	RmLog(rm, 0, this->source.c_str());
	RmLog(rm, 0, this->query.c_str());

	// Cache query result
	result = parse(source, query);

	// Try to convert result to double value
	try
	{
		this->numeric = std::stod(result);
	}
	catch (std::exception&)
	{
		this->numeric = 0.0;
	}
}
Logs show, what my plugin receives - this is copied directly from the rainmeter log window:

Code: Select all

[MeasureWeather1] (TestSkin\TestSkin.ini - [MeasureTemperature])
current.temp (TestSkin\TestSkin.ini - [MeasureTemperature])
User avatar
Brian
Developer
Posts: 2689
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Passing result of WebParser into custom plugin

Post by Brian »

Did you try DynamicVariables=1 on your [MeasureTemperature] measure?

Reload is only called when the skin is loaded or refreshed, and when the dynamic variables option is set. It is also called on demand when the !SetOption bang is used.

-Brian
spook
Posts: 7
Joined: September 9th, 2020, 2:07 pm

Re: Passing result of WebParser into custom plugin

Post by spook »

Hi!

Thanks for the reply. Following your guidelines, I forced refresh of the measure by using SetOption, like this:

Code: Select all

[MeasureWeather]
(...)
OnUpdateAction=[!SetOption MeasureTemperature Source [MeasureWeather1]]
This indeed passed data to the MeasureTemperature, but did not cause refresh to be called. Effectively I had to set DynamicVariables to 1 and force update in 1 second, so that value passed to the measure was actually accepted and processed.

What's weird, I tried to add bang [!UpdateMeasure MeasureTemperature] after the SetOption, but it didn't seem to work. I'm actually logging all activity in my plugin and I'm positive it did not get refreshed :(