Number to hex string conversion in rules

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
abial
New user
Posts: 4
Joined: 26 Jan 2017, 18:57

Number to hex string conversion in rules

#1 Post by abial » 06 Oct 2020, 21:07

Hi,

I'm using a dummy device to manage a counter of events. I also need to send this count to an external endpoint using SendToHTTP - BUT it needs to be encoded as a hexadecimal number... I can't find any way to do it in rules.

In a sense, I need the reverse of 'strtol' or at least the reverse of 'ord' :)

Any help appreciated!

--
Andrzej

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

Re: Number to hex string conversion in rules

#2 Post by TD-er » 06 Oct 2020, 22:53

Hmm the other way around is already present, but I can only think of very elaborate ways to convert to hex.

So unless you want to create very elaborate (thus slow) rules, I guess it is a nice feature request.

abial
New user
Posts: 4
Joined: 26 Jan 2017, 18:57

Re: Number to hex string conversion in rules

#3 Post by abial » 07 Oct 2020, 13:44

I was afraid you would say so ... :(
I'm thinking about maybe using substring creatively - if it's possible to declare a string literal (var) somewhere, like "01234567890ABCDEF" and to concatenate substrings (or chars), then I could do some math juggling to create the hex strings piecemeal - but I suspect that's not possible either?

--
Andrzej

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

Re: Number to hex string conversion in rules

#4 Post by TD-er » 07 Oct 2020, 13:46

That's what I meant with "very elaborate rules"

I think a new feature supporting this should be something like the other "Standard Conversions" (See System Variables page)

I will see what I can think of...

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

Re: Number to hex string conversion in rules

#5 Post by TD-er » 07 Oct 2020, 14:36

It was really easy to do, most of the needed time was in updating the system variables documentation.

See: https://github.com/letscontrolit/ESPEasy/pull/3296

abial
New user
Posts: 4
Joined: 26 Jan 2017, 18:57

Re: Number to hex string conversion in rules

#6 Post by abial » 08 Oct 2020, 14:17

Ah, this is great! it saves me a lot of trouble going the micropython route (python irq handling and button debouncing is not trivial).

Thank you!

--
Andrzej

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 111 guests