Fill all dummy sensor entries in one json

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Fill all dummy sensor entries in one json

#1 Post by mackowiakp » 24 Sep 2020, 17:57

Is it possible to fill all entries in quad dummy sensor in one json HTTP call from server to ESP instead fill it one by one (4 singe jason calls).

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

Re: Fill all dummy sensor entries in one json

#2 Post by TD-er » 24 Sep 2020, 18:27

Not jet.
What exact call do you make right now to fill each value?

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#3 Post by mackowiakp » 24 Sep 2020, 18:35

Code: Select all

http://<ip>/control?cmd=TaskValueSet,<sensor_number>,<position_number>,<value>

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

Re: Fill all dummy sensor entries in one json

#4 Post by TD-er » 24 Sep 2020, 19:00

OK, this isn't a JSON call, just a simple HTTP GET url.
Still doesn't make it possible to set multiple values in one call, but at least I now know what you're talking about as I really couldn't imagine how you were sending JSON via HTTP to fill the dummy values.

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#5 Post by mackowiakp » 24 Sep 2020, 20:48

OK. THX If it is impossible, then it is impossible...

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

Re: Fill all dummy sensor entries in one json

#6 Post by TD-er » 24 Sep 2020, 22:51

I just thought of a way that could make it possible.

You could send an event and the event can have upto 4 eventvalues.
Such an event will then be dealt with in the rules and in there you can split the eventvalues into 4 separate commands to set the values to a dummy task.

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#7 Post by mackowiakp » 26 Sep 2020, 13:25

I think that it is not solution of my problem.
In my case, ESP sends to Domoticz SendToHTTP request. This cause "push" of virtual button. LUA script associated with this button takes from Domoticz DB 8 parameters and sends one by one (via WGET HTTP) to ESP, placing them in the individual positions of two dummy sensors.
These parameters are displayed on a 20x4 LCD in the form of "pages" switched with the button.
So ESP has to handle 9 HTTP calls in a short amount of time.
However, the HTTP calls seems to be taking a long time of CPU. And if accidentally the moment of pressing the button coincides with the HTTP calls series, the device reacts either with a significant delay or (because I also use the double click function) it reacts incorrectly.
Hence, I would like to reduce the number of HTTP calls.

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

Re: Fill all dummy sensor entries in one json

#8 Post by TD-er » 26 Sep 2020, 14:05

Have you tried it?

So in the GET url you send an event like this:

Code: Select all

AsyncEvent,eventname=1,2,3,4
And in the rules you must then act on the "eventname" like this:

Code: Select all

on eventname do
  LogEntry,'Values %eventvalue1% %eventvalue2% %eventvalue3% %eventvalue4%'
endon

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#9 Post by mackowiakp » 26 Sep 2020, 14:40

OK, THX. Will try. Is it new feature? I ask because I use ESPEasy_mega-20191208.

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

Re: Fill all dummy sensor entries in one json

#10 Post by TD-er » 26 Sep 2020, 18:50

Asyncevent is new, but "event" isn't.
So if asyncevent is not working, then event can be used.

I used "asyncevent" in my suggestion as it is not blocking and you experience delays when sending multiple calls.

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#11 Post by mackowiakp » 26 Sep 2020, 19:03

Yes, "event" works. "Asyncevent" will try tomorrow.

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#12 Post by mackowiakp » 27 Sep 2020, 13:16

Asyncevent works properly in mega-20191208. For test needs I created two simple events:

Code: Select all

On display_off do
 LCDCMD,off
endon

On display_on do
 LCDCMD,on
endon
than, I run it from server using commands:

Code: Select all

wget -O - "http://<ESP_IP>/control?cmd=asyncevent,display_off"
and
wget -O - "http://<ESP_IP>/control?cmd=asyncevent,display_on"
And as expected, LCD backlight could be turn off/on remotely. Of course LCD commands could be trigger directly from server but this is only test.
I digged a little bit in docu, but can not understand syntax of Your proposal. Probably because of my age (64 years) - sorry...
So, if I want to assign remotely value of variables or content of dummy sensor in ESP using script containing command:

Code: Select all

wget -O - "http://<ESP_IP>/control?cmd=AsyncEvent,parameters=$val1,$val2,$val3,$val4"
where $val1, $val2, $val3,$val4 are values calculated by script running on server.
and on ESP site something like this:

Code: Select all

On parameters do
 // dont know what to do
 Let,10,<dont_know_what> 
 Let,11,<dont_know_what> 
 Let,12,<dont_know_what> 
 Let,13,<dont_know_what> 
 // dont know what to do
endon
Be so kind to inspect the code above and correct one.

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

Re: Fill all dummy sensor entries in one json

#13 Post by TD-er » 27 Sep 2020, 13:27

Just like this:

Code: Select all

On parameters do
 Let,10,%eventvalue1%
 Let,11,%eventvalue2%
 Let,12,%eventvalue3%
 Let,13,%eventvalue4%
endon

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#14 Post by mackowiakp » 27 Sep 2020, 13:41

THX. Will try when my grandson allows :D

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

Re: Fill all dummy sensor entries in one json

#15 Post by TD-er » 27 Sep 2020, 14:04

mackowiakp wrote: 27 Sep 2020, 13:41 THX. Will try when my grandson allows :D
Just let him do it :)
(minimal age for operating ESPEasy appears to be roughly 6 yrs old)

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#16 Post by mackowiakp » 27 Sep 2020, 14:29

:D :D :D
One more question.What is the limitation of amount parameters that could be passed in single asyncevent request? Eight is not too much?

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

Re: Fill all dummy sensor entries in one json

#17 Post by Ath » 27 Sep 2020, 14:44

Only the first 4 arguments will be passed on to the event, so only %eventvalue1% to eventvalue4% are available. Please note that %eventvalue% (as seen in many documentation examples) is the alias for %eventvalue1%.
And, as noted earlier, only numerical values can be passed (to event and asyncevent).
/Ton

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#18 Post by mackowiakp » 27 Sep 2020, 14:57

Once thanks for very helpful infos !

Ruprecht
Normal user
Posts: 11
Joined: 04 Nov 2016, 10:02
Location: im Süden von DE

Re: Fill all dummy sensor entries in one json

#19 Post by Ruprecht » 27 Sep 2020, 18:23

mackowiakp wrote: 26 Sep 2020, 13:25 I think that it is not solution of my problem.
In my case, ESP sends to Domoticz SendToHTTP request. This cause "push" of virtual button. LUA script associated with this button takes from Domoticz DB 8 parameters and sends one by one (via WGET HTTP) to ESP, placing them in the individual positions of two dummy sensors.
I would also like to transfer values ​​from Domoticz to EspEasy. The purpose is to request EspEasy for the last temperature settings from Domoticz when restarting and then save them into dummy variables. The process is clear for me, but I am missing this corresponding LUA-script for Domoticz.

mackowiakp
Normal user
Posts: 251
Joined: 07 Jun 2018, 06:47
Location: Gdynia/Poland

Re: Fill all dummy sensor entries in one json

#20 Post by mackowiakp » 27 Sep 2020, 18:56

In fact, I use LUA script to call BASH script. Why? Because I not so clever in LUA.
So LUA script looks like:

Code: Select all

local sensor = '<name_of_virt_switch>'

commandArray = {}

if (devicechanged[sensor] == 'On') then
os.execute ("/home/pi/Pobrane/get_temp1")
os.execute ("/usr/bin/wget -q -O - http://localhost:8080/json.htm?type=command&param=switchlight&idx=,<idx_of_virt_switch>&switchcmd=Off")

end

return commandArray
And BASH script (part of them) named /home/pi/Pobrane/get_temp1 for downloading parameters to ESP quad dummy sensor:

Code: Select all

wyn1=`wget -q -O - "http://localhost:8080/json.htm?type=devices&rid=$idx_dallas_no_1" |grep Data|/usr/bin/awk '{print $3}'|/bin/sed 's/"//'`
wyn2=`wget -q -O - "http://localhost:8080/json.htm?type=devices&rid=$idx_dallas_no_2" |grep Data|/usr/bin/awk '{print $3}'|/bin/sed 's/"//'`
wyn3=`wget -q -O - "http://localhost:8080/json.htm?type=devices&rid=$idx_DTH22" |grep Data|/usr/bin/awk '{print $3}'|/bin/sed 's/"//'` # returns temperature
wyn4=`wget -q -O - "http://localhost:8080/json.htm?type=devices&rid=$idx_DTH22" |grep Data|/usr/bin/awk '{print $5}'` # returns humidity
wget -q -O - "http://<ESP_IP>/control?cmd=AsyncEvent,Parameters2=$wyn1,$wyn2,$wyn3,$wyn4"

Post Reply

Who is online

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