Page 1 of 1
VL53L0X webrequest on certain values?
Posted: 23 Jan 2023, 16:21
by pege36
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:)
Re: VL53L0X webrequest on certain values?
Posted: 23 Jan 2023, 16:32
by Ath
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.
Re: VL53L0X webrequest on certain values?
Posted: 23 Jan 2023, 22:13
by pege36
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
Re: VL53L0X webrequest on certain values?
Posted: 23 Jan 2023, 22:53
by Ath
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
Re: VL53L0X webrequest on certain values?
Posted: 24 Jan 2023, 10:12
by pege36
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
You are so right, I could have discovered that by my self in 5 min
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:)