I am building a wifi PIR system. When the PIR is triggered it will send the positive value to a site served on the esp32 server.
I have thought of 2 ways for this to work
1) Use a websocket to constantly trasmit data of PIR status (HIGH or LOW)
2) Build the HTML page served by the esp32 server and use javascript setInterval to constantly send http request to esp32 webserver to check the PIR status.
I built both and tested both. They both work as intended function wise. However which way is better ? There are some factors that i cant test such as which consumes more power etc etc..
is websocket better or setInterval http request better?
is websocket better or setInterval http request better?
Last edited by esplover on Wed Sep 22, 2021 2:41 am, edited 1 time in total.
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: is websocket better or setInterval http request better?
What's your use case? Do you simply want to have a browser open looking at the webpage, or do you have further automation in mind? Any other things?
Generally, sending the status continuously is a bit wasteful... you can't really do anything else if you use Javascript to refresh a page, but if you use Websockets, you theoretically only need to send a new value when something changes.
Generally, sending the status continuously is a bit wasteful... you can't really do anything else if you use Javascript to refresh a page, but if you use Websockets, you theoretically only need to send a new value when something changes.
Re: is websocket better or setInterval http request better?
PIR door camera.ESP_Sprite wrote: ↑Wed Sep 22, 2021 12:54 amWhat's your use case? Do you simply want to have a browser open looking at the webpage, or do you have further automation in mind? Any other things?
Generally, sending the status continuously is a bit wasteful... you can't really do anything else if you use Javascript to refresh a page, but if you use Websockets, you theoretically only need to send a new value when something changes.
I want to know when someone stands in front of my house door and have a camera that i can turn on and see who is it or whether its just a cat. lol
So i combined esp32CAM with PIR.
-
- Posts: 9730
- Joined: Thu Nov 26, 2015 4:08 am
Re: is websocket better or setInterval http request better?
I'd use websckets as a communication mechanism then; that should also allow you to push the images at whatever speed the sensor can generate them.
Who is online
Users browsing this forum: No registered users and 81 guests