How the socket thermostat works

I want to create a device based on a Raspberry Pi (RPi), similar to a Thermostat socket, except that I want to control the light switches. I know that I could easily encode a Node.js script into RPi, and then just connect it to a local router and manage it using a PC connected to one router.

But I want to make it look more like a nest. I want to be able to control 20 (or more) RP addresses on different subnets through a cloud provider such as Heroku.

The Nest thermostat does not require the user to open a port on their router so that the Nest server can communicate with it.

How can Nest control client thermostats over the Internet without enabling port forwarding in the client router?

+4
source share
3 answers

Blog post Node socket thermostat API using Node The JS and Nest API update discusses the API between the thermostat and the breeding lab servers. In particular:

The API uses mostly formatted JSON data sent to their web servers.

So there is your answer. By periodically sending POST data to socket web servers using HTTPS, Nest may not open any ports on its router to the user.


For what it's worth, the unofficial API (in node.js!) From a blog post is available on github: Unofficial Nest API on Node .
+5
source

I think the thermostat periodically places a request with the serial number of the thermostat in the socket. It can have timeouts in the http headers set to infinity or, most likely, the socket server just closes the connection after a minute or so, if there was no command for this device in it. Whenever the socket closes the connection, the thermostat opens a new one. When a command request arrives with a serial number, search it quickly to find the stream that is currently connected to this thermostat. The command is sent in the payload of the current thermostat request, which is being executed, the connection is closed, and the thermostat opens a new request for the socket.

0
source

Take a look at eventSource in the HTML 5 standard. It does whatever it takes.

0
source

All Articles