Project punching bag

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
garnold
Normal user
Posts: 90
Joined: 17 Jun 2019, 03:59

Project punching bag

#1 Post by garnold » 13 Jul 2021, 22:03

I need to build this project. I will have an accelerometer placed inside of a punching bag. I need to capture and send via MQTT how hard someone hits the bag. This would not be that hard except I also need to be able to capture the person's name and send that with the data. Here are my thoughts and I would love some input on whether this is a good approach.

Use a variable to hold the person's name
Create a rule that updates this variable
Call the rule and pass it the person's name
The rule updates the variable with the person's name
Now when the person hits the bag that name is used in the MQTT call

How does this sound?

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project punching bag

#2 Post by TD-er » 13 Jul 2021, 22:20

How do you switch user?
Using RF-ID tags?

You can use the RF-ID tag also in topic when publishing as we now support a lot more bits in variables in rules. (52 bits, as we store it as double)

So each time a new tag is scanned, you store it in a variable.
This variable is used for every publish in the topic.

User avatar
Ath
Normal user
Posts: 958
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Project punching bag

#3 Post by Ath » 13 Jul 2021, 22:20

First real hurdle to tackle is that ESPEasy doesn't support strings in any variable type...
/Ton

garnold
Normal user
Posts: 90
Joined: 17 Jun 2019, 03:59

Re: Project punching bag

#4 Post by garnold » 13 Jul 2021, 22:34

The way I was planning to switch users was via a web interface. I was hoping to be able to update a variable inside of ESPEasy via a command call. I can set the dummy device from a command call so I was hoping I could set a var this way as well. So when a new fighter steps up to the bag I would just enter their name into a simple webpage on my laptop that would call an ESPEasy HTTP command that would take a name and update a var. Now when the accelerometer is triggered it would fire a rule that would take the accelerometer data and the value of the var and send that all up to MQTT. That was the hope anyway.

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project punching bag

#5 Post by TD-er » 13 Jul 2021, 22:50

I think you can call the 'let' command via HTTP too, so that's still an option. But it must be a numerical value, not a string.
But maybe it is more practical to have the authentication sensor/reader also running on the same ESPEasy node instead of relying on another node/computer to process the "login" and let it sync hopefully.

I still think an RF-id tag is the simplest way here as the same tag can be used on several exercise equipment as you also have in a lot of gyms.

Triggering on a sensor receiving new data and using a variable when sending it is very simple to do.
You can even configure the variable in the MQTT topic of a controller, so you don't even need rules to process that measurement.

garnold
Normal user
Posts: 90
Joined: 17 Jun 2019, 03:59

Re: Project punching bag

#6 Post by garnold » 13 Jul 2021, 23:04

In most cases I would really agree with you TD-er but I'm building this for a trade show for work. So I can't use the RF-ID option and people want to put in their own funny names like "Slugger" or "Big Bad Billy". I would really rather not have to build this via code on an Arduino and tend to always look towards ESPEasy for my answers first. I guess I could create some random number generator on the ESPEasy and store that in a database with a fighter's name but this is just going to over complicate what should be a simple project.

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project punching bag

#7 Post by TD-er » 13 Jul 2021, 23:10

You can also do the other way around.
Just let them add their name and generate an unique ID for it and send that to ESPEasy as the "user"
Then store it in a variable and use that variable in the MQTT topic.
So you have the name and ID in the database, so you can also use it the other way around to decode the MQTT topic.

garnold
Normal user
Posts: 90
Joined: 17 Jun 2019, 03:59

Re: Project punching bag

#8 Post by garnold » 13 Jul 2021, 23:44

Could I please get an example of how I would update a customer var via command? Also, possibly an example of using that same var inside of a call? Odds are I would be making a REST call so I would need to update a URL parameter. Thank you!

TD-er
Core team member
Posts: 5094
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Project punching bag

#9 Post by TD-er » 14 Jul 2021, 23:22

The best way to try HTTP calls, is to enter commands via the command field on the Tools page.
After sending it, the page will reload and the URL with the command is shown.

So I guess what is the simplest is to give a command like this:

Code: Select all

let,1,12345678
This will set [var#1] to the new value.
Since it is an integer, you can also refer to it as [int#1]
Another format to refer to variables is %v1%

This is exactly the syntax you need to refer to the value of this variable.
So in the publish topic you can use variables.
When you add the OpenHAB MQTT controller, you can see an example of a topic where you can see a reference to the task name and the taskvalue name.
So if you insert the %v1% somewhere in the MQTT publish topic, you can differentiate between the users. (it is 0 when not set)

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests