Best Practices - Which is better (PUSH or PULL)

Looking for best practices advice.

I am currently running a NodeMCU in my garage with various sensors and relays on it. Each sensor can be polled via the wifi web server I set up on the NodeMCU's ESP8266 chip. This works well, yet I've noticed that it's slow now that I have a bunch of functions that all take place through the web server that its running.

The tasks it performs are:

  • Reading and reporting Garage Temperature and Humidity
  • Reading and reporting fireplace temperature (and will control fan of fireplace if temp in certain range)
  • Ability to override and turn on or off the fireplace fan
  • Outside temperature reading
  • Check if the garage door is closed
  • Close or open the garage door (activate the motor switch momentarily)

All of this data is fed into a raspberry pi I have running home bridge which then interfaces with my apple products.

Everything works really well. The only thing is, readings are very slow. This is obviously because the NodeMCU can only answer to one web request at a time and home bridge often polls everything at once.

So in order to combat this, I set up a second web server to answer the questions regarding temperature and humidity from homebridge, then a cron job to poll those values from the NodeMCU periodically. This leaves me with a cached value of about 2 minutes per reading, but home bridge thinks it's getting immediate results (which is fine).

Reading from the garage door and fireplace fan switch are still going directly to the NodeMCU and still seem slow, but not as bad.

My question is, is this best practice? Would it be more efficient to PUSH the data from the NodeMCU out to a web server rather than having it be polled? If I did this, I could essentially leave the web server up to activate the garage door or fireplace fan and all other readings would get sent out to a web server on my network.

Any advice?

With PUSH only there is no way to detect a dead node.

My suspicion is your code needs more state machine.