How to include credentials with SendToHTTP?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

How to include credentials with SendToHTTP?

#1 Post by ThomasB » 18 Jul 2022, 22:25

I would like to send commands to my Dahua IP Cameras. The camera API requires credentials. For example, here is the command that applies a text overlay on the camera image (user is "admin" and password is "cam123X#"):

Code: Select all

http://admin:cam123X%23@192.168.1.240/cgi-bin/configManager.cgi?action=setConfig&VideoWidget[0].CustomTitle[1].Text=DOOR%20IS%20LOCKED
This command works correctly when it is entered as the URL in a browser.
Note: The "#" in the password has been replaced with %23 due to URL encoding requirements.

But I cannot get it to work with ESPEasy. I have a rule that sends the http command as follows:

Code: Select all

SendToHTTP,admin:cam123X#@192.168.1.240,80,/cgi-bin/configManager.cgi?action=setConfig&VideoWidget[0].CustomTitle[1].Text=DOOR%20IS%20LOCKED
Note: Changing the "#" in the password to %23 does not help.

Serial log shows this:

Code: Select all

2025659 : Info   : ACT  : SendToHTTP,admin:cam123X#@192.168.1.240,80,/cgi-bin/configManager.cgi?action=setConfig&VideoWidget[0].CustomTitle[1].Text=DOOR%20IS%20LOCKED
2029838 : Error  : SendToHTTP connection failed
I've experimented with the http options in Tools->Advanced Rules Settings. No joy.

I'm running ESPEasy ESP_Easy_mega_20220616_normal_ESP8266_4M1M on a Wemos D1 mini. There are no plugins or controllers, just some rules to send the http command on a repeating timer. The camera and ESPEasy device are on the same subnet.

Looking for advice on getting it to work.

- Thomas

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: How to include credentials with SendToHTTP?

#2 Post by ThomasB » 18 Jul 2022, 22:47

Here's a rule example used in the testing:

Code: Select all

on WiFi#Connected do
  timerSet,1,5
  SendToHTTP,admin:cam123X%23@192.168.1.240,80,/cgi-bin/configManager.cgi?action=setConfig&VideoWidget[0].CustomTitle[1].EncodeBlend=true
endon

on Rules#Timer=1 do
  timerSet,2,15
  SendToHTTP,admin:cam123X%23@192.168.1.240,80,/cgi-bin/configManager.cgi?action=setConfig&VideoWidget[0].CustomTitle[1].Text=DOOR%20IS%20LOCKED
endon

on Rules#Timer=2 do
  timerSet,1,15
  SendToHTTP,admin:cam123X%23@192.168.1.240,80,/cgi-bin/configManager.cgi?action=setConfig&VideoWidget[0].CustomTitle[1].Text=DOOR%20IS%20UNLOCKED
endon
And yes, the displayed password has been altered in the examples for my privacy.

- Thomas

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

Re: How to include credentials with SendToHTTP?

#3 Post by Ath » 18 Jul 2022, 22:51

Have you tried adding quotes around the separate arguments for SendToHTTP?

Code: Select all

SendToHTTP,"admin:cam123X%23@192.168.1.240",80,"/cgi-bin/configManager.cgi?action=setConfig&VideoWidget[0].CustomTitle[1].EncodeBlend=true"
/Ton (PayPal.me)

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: How to include credentials with SendToHTTP?

#4 Post by ThomasB » 18 Jul 2022, 23:05

I indeed tried quotes around the command args. Did not help. In case I missed something I just tried it again, still no joy.

- Thomas

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

Re: How to include credentials with SendToHTTP?

#5 Post by TD-er » 18 Jul 2022, 23:31

And have you also tried using one of the HTTP controllers?

Not sure what you want to send here, but maybe you can form an URL using system variables and just trigger a send by attaching the controller to a dummy task and calling taskrun on that task to force flushing something to the controller.

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: How to include credentials with SendToHTTP?

#6 Post by ThomasB » 18 Jul 2022, 23:51

have you also tried using one of the HTTP controllers?
Unfortunately there's a couple dozen different cameras, each with their own IP. So that is not a practical solution.

- Thomas

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: How to include credentials with SendToHTTP?

#7 Post by ThomasB » 19 Jul 2022, 00:55

While watching the serial log I noticed that the first arg was converted to lowercase. That is to say, the cam123X# password was shown as cam123x#.

As a test I changed the test device's password to be all lower case. It did not solve the problem, but thought I should mention this suspicious quirk. In the meantime I've restored the original password on the device (it's back to using the uppercase char).

- Thomas

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

Re: How to include credentials with SendToHTTP?

#8 Post by TD-er » 19 Jul 2022, 13:13

I think it is parsing it as a hostname and hostnames always are case-insensitive.
For username and password this does obviously not apply.

I will now have a look at the sendToHttp code to see what I can do.


User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: How to include credentials with SendToHTTP?

#10 Post by ThomasB » 19 Jul 2022, 18:49

Thank you for the PR. It didn't solve the problem, but it made some progress. I've reported my findings at Github.

- Thomas

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests