VL53L0X webrequest on certain values?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
pege36
New user
Posts: 3
Joined: 23 Jan 2023, 13:57

VL53L0X webrequest on certain values?

#1 Post by pege36 » 23 Jan 2023, 16:21

Hi All

If I would like VL53L0X to send a webrequest on certain values I guess that should be done in Rules.
But how would a script like that be done?

It was no problems to get the VL53L0X up and running and Webrequest seems pretty easy, but Rules that's a another ballpark for me:)

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

Re: VL53L0X webrequest on certain values?

#2 Post by Ath » 23 Jan 2023, 16:32

Assuming you have already enabled the Rules option in Tools/Advanced, that could be something like this:

Code: Select all

On Vl53l0x#Distance do
  If %eventvalue1% < 100
    // Too close
    SendToHTTP,host,80,/url/to/send?value=%eventvalue1%&level=TooClose
  Elseif %eventvalue1% < 500
    // Close enough
    SendToHTTP,host,80,/url/to/send?value=%eventvalue1%&level=Good
  Else
    // Too far away
    SendToHTTP,host,80,/url/to/send?value=%eventvalue1%&level=TooFar
  Endif
Endon
Instead of SendToHTTP, using a GET request, you can, when using a very recent build (not released yet), use the PostToHTTP command, with user-defined headers and a post-body, that can also contain the value.
Both SendToHTTP and PostToHTTP support user:password@host authentication, if needed, and PostToHTTP can use alternative authentications by providing the required header arguments.

Edit: Fixed small typo in the code.
/Ton (PayPal.me)

pege36
New user
Posts: 3
Joined: 23 Jan 2023, 13:57

Re: VL53L0X webrequest on certain values?

#3 Post by pege36 » 23 Jan 2023, 22:13

THANK YOU Ath, that worked like a charm!
Can I have a follow up question, is it possible to set a fixed value so the SendToHTTP is only triggered on for example the value 100?

//Per

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

Re: VL53L0X webrequest on certain values?

#4 Post by Ath » 23 Jan 2023, 22:53

pege36 wrote: 23 Jan 2023, 22:13 THANK YOU Ath, that worked like a charm!
You're welcome :)
pege36 wrote: 23 Jan 2023, 22:13 is it possible to set a fixed value so the SendToHTTP is only triggered on for example the value 100?
Sure, just a different value comparison:

Code: Select all

On Vl53l0x#Distance do
  If %eventvalue1% = 100
    // Just right
    SendToHTTP,host,80,/url/to/send?value=%eventvalue1%&level=SpotOn
  Endif
Endon
The syntax isn't very hard, please read the fine documentation & examples for Rules, so you can extend/modify the code yourself :idea:
/Ton (PayPal.me)

pege36
New user
Posts: 3
Joined: 23 Jan 2023, 13:57

Re: VL53L0X webrequest on certain values?

#5 Post by pege36 » 24 Jan 2023, 10:12

Ath wrote: 23 Jan 2023, 22:53
Sure, just a different value comparison:

Code: Select all

On Vl53l0x#Distance do
  If %eventvalue1% = 100
    // Just right
    SendToHTTP,host,80,/url/to/send?value=%eventvalue1%&level=SpotOn
  Endif
Endon
The syntax isn't very hard, please read the fine documentation & examples for Rules, so you can extend/modify the code yourself :idea:
You are so right, I could have discovered that by my self in 5 min :oops: but I was so excited that it worked soI didn't think before i wrote, sorry, but never less a big thank you Ath for you help and I owe you a beer:)

Post Reply

Who is online

Users browsing this forum: No registered users and 27 guests