Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Both 'Heating' and 'Hot Water' symbols are lit when either pump is on #16

Closed
MrTimbones opened this issue Feb 23, 2022 · 10 comments
Closed

Comments

@MrTimbones
Copy link
Contributor

The top line of the app shows when the heat pump is active, by shading the 'Space Heating' and 'Hot Water' symbols in red based on their respective pump activity. However, on my system, both symbols are always lit when either pump is running.

For example, right now, WaterPump4Status (hot water) is high, and WaterPump2Status (heating) is low, and yet both of them are highlighted in red. Which is generally not possible for this model of heat pump.

image

image

@MrTimbones
Copy link
Contributor Author

It looks like it's because feedMeta.value is a string, and if (feedMeta.value) evaluates as true for both "1" and "0".

MrTimbones added a commit to MrTimbones/mmspheatpump that referenced this issue Feb 23, 2022
MrTimbones added a commit to MrTimbones/mmspheatpump that referenced this issue Feb 23, 2022
MyForest added a commit that referenced this issue Feb 23, 2022
Fixing issue #16 with status highlights
@MyForest
Copy link
Owner

I was pondering how you were getting a string.

In my "post to EmonCMS" code I have a thing like this to convert a boolean to 0 or 1 as an integer. It's pretty high tech:

b = bool(thing_being_posted)
v = 0
if b:
    v = 1
to_post = v

Are you posting it as a string? I didn't think you could post strings to EmonCMS. Is it possible that your setup is getting strings when you are requesting data from feed/data.json? Inquiring minds want to know.

@MrTimbones
Copy link
Contributor Author

I'm definitely posting numbers to EmonCMS, but when I look at ../feed/list.json that the MMSP app is requesting, all the values are represented as strings, no matter which storage engine has been used.

image

🤷‍♂️

@MyForest
Copy link
Owner

Hmm, that's pretty peculiar.

When I'm calling it I get a result including the pump data like this:

	"42": {
		"id": "493",
		"userid": "1",
		"name": "WaterPump1Status",
		"datatype": "1",
		"tag": "ecodan",
		"public": "",
		"size": "4584304",
		"engine": "5",
		"unit": "",
		"time": 1638686280,
		"value": 0,
		"start_time": 1569922020,
		"end_time": 1638686280,
		"interval": 60
	}

@MrTimbones
Copy link
Contributor Author

MrTimbones commented Feb 23, 2022

Do you have REDIS enabled? I never managed to get it to work, so I've been using EmonCMS without it.

That means the list of feeds and values are stored in MySQL, and it seems that when feed_model.php requests all the data with mysql_get_user_feeds, the values are strings, despite the schema of the table definitely storing value as a double.

This can be fixed by adding $row['value'] = floatval($row['value']) within the $row loop, but this shouldn't be necessary; mysqli usually returns data in the correct type, I thought.

@MyForest
Copy link
Owner

Yes @MrTimbones

I'm Docker-based for absolutely everything so you can imagine I'm running something like this:

MARIA_DB=$(docker run \
-d \
-v a:/var/lib/mysql/emoncms \
-v b:/etc/mysql/conf.d:ro \
-e MYSQL_ROOT_PASSWORD \
mariadb )

REDIS=$(docker run \
-d \
-v c:/data \
redis:5 )

echo "Setting up emoncms..."

docker run \
-d \
-e MYSQL_PASSWORD \
--link ${MARIA_DB}:db \
--link ${REDIS}:redis \
-v d:/var/opt/emoncms/phpfina/ \
-v e:/var/opt/emoncms/phptimeseries/ \
-P \
myforest/emoncms

@MrTimbones
Copy link
Contributor Author

mysqli usually returns data in the correct type, I thought.

I thought wrong. It turns out that mysqli is returning all fields as strings, regardless of how they are stored in the database.

I'm amazed that anything works at all, seeing as all numeric operations will have depended on PHP's own implicit conversion to real numbers.

@MyForest
Copy link
Owner

What shall we do about this @MrTimbones ?

Do you want to chase it with EmonCMS and close this issue or would you like to keep it open to track the outcome?

@MrTimbones
Copy link
Contributor Author

I'm happy that we now understand why this fix was necessary, and I've not had any issues elsewhere with EmonCMS, so I think we can close this issue.

@MyForest
Copy link
Owner

Thanks for your help @MrTimbones

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

No branches or pull requests

2 participants