URL Encoded System Variable

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Dexamenos
New user
Posts: 7
Joined: 19 Jul 2021, 13:51

URL Encoded System Variable

#1 Post by Dexamenos » 19 Jul 2021, 13:57

Hey

I'm new to ESP Easy and currently struggling with the use of System Variables in a Rule.

My Unit Name (%sysname%) contains a space char and I want to use it in a rule within a sendToHTTP request.

Is there a kind of modifier available to automatically URL-encode SysVars? I'm wondering, because in the Tools > System Variables page, also the URL-encoded value is listed for every SysVar

This is part of my rule

Code: Select all

SendToHTTP 1.2.3.4,5000,/?gpio=5&val=1&sysname=%sysname%

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

Re: URL Encoded System Variable

#2 Post by TD-er » 19 Jul 2021, 14:50

Have you tried wrapping the last command argument in quotes?

Code: Select all

SendToHTTP 1.2.3.4,5000,"/?gpio=5&val=1&sysname=%sysname%"

Dexamenos
New user
Posts: 7
Joined: 19 Jul 2021, 13:51

Re: URL Encoded System Variable

#3 Post by Dexamenos » 19 Jul 2021, 17:09

Sadly, this does not work, as there still is a space in URL (as there is a space in %sysname%)

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

Re: URL Encoded System Variable

#4 Post by Ath » 19 Jul 2021, 19:28

Can you replace that space by an underscore (_)? Spaces in that kind of settings is not endorsed.
/Ton (PayPal.me)

Dexamenos
New user
Posts: 7
Joined: 19 Jul 2021, 13:51

Re: URL Encoded System Variable

#5 Post by Dexamenos » 20 Jul 2021, 08:01

Sure can I replace spaces in the unit name (%sysname%) with underscores. However, my question is more general. You will run into the same problem with e.g. %dns% or %sysbuild_date%).

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

Re: URL Encoded System Variable

#6 Post by Ath » 20 Jul 2021, 08:30

Closest I can think of is to add url encoding on arguments for that type of commands, but I'd think that was there already, as this question shouldn't be new. I'll investigate what's there and see if it's generally fixable.
/Ton (PayPal.me)

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

Re: URL Encoded System Variable

#7 Post by Ath » 20 Jul 2021, 08:33

Dexamenos wrote: 20 Jul 2021, 08:01 You will run into the same problem with e.g. %dns% ...
Hm, don't think %dns% should have a space in the name, it's either an ip address or a hostname/url, and that can't have spaces
/Ton (PayPal.me)

Dexamenos
New user
Posts: 7
Joined: 19 Jul 2021, 13:51

Re: URL Encoded System Variable

#8 Post by Dexamenos » 20 Jul 2021, 09:36

Thanks for frequent answering.

Again, this is more like a general question out of curiosity. I will be able to live without URL-encoded SysVars. However, I was "guided" to ask, as there is the URL encoded version already given in "Tools > System Variables".

To respond to your question regarding DNS, mine has spaces.

This is a copy/excerpt of my ESP Easy System Variables Table in the WebUI

Code: Select all

System Variables        Normal                                         URL encoded 
---------------------------------------------------------------------------------------------------------------------
%dns%                   192.168.0.1 / (IP unset)                       192.168.0.1%20%2f%20%28IP%20unset%29
%ssid%                  My WiFi                                        My%20WiFi                                        
%sysbuild_time%         10:25:30                                       10%3a25%3a30
%sysbuild_filename%     ESP_Easy_mega_20210615_normal_ESP8266_4M1M     ESP_Easy_mega_20210615_normal_ESP8266_4M1M

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

Re: URL Encoded System Variable

#9 Post by Ath » 20 Jul 2021, 10:01

Ah, I never used that %dns% variable, and hadn't looked close enough to see it has spaces :oops:

I'll surely have a look at url encoding for commands that would benefit from it, like sendtohttp. And maybe add a function for that.
/Ton (PayPal.me)

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

Re: URL Encoded System Variable

#10 Post by TD-er » 20 Jul 2021, 15:30

That DNS value can probably be split into %dns1% and %dns2%.
For sure it needs to be an IP-address, as that simply can't be a domain name for obvious reasons ;)

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

Re: URL Encoded System Variable

#11 Post by Ath » 22 Jul 2021, 09:25

I'm working on fixes for these issues, adding both system variables for %dns1% and %dns2%, and a string function {urlencode:"stuff to/encode"} -> "stuff%20to%2fencode". Still have to update the documentation and will then create a PR for that, later today.
/Ton (PayPal.me)

Dexamenos
New user
Posts: 7
Joined: 19 Jul 2021, 13:51

Re: URL Encoded System Variable

#12 Post by Dexamenos » 22 Jul 2021, 10:02

I can only say thanks for picking up this topic :)

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

Re: URL Encoded System Variable

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

Created the pull request here: #3712
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests