I know that there are a lot of articles about controlling Raspberry Pi outputs via web interfaces, but there is nothing about doing the opposite. I would like to control web interfaces that runs on Raspberry Pi with GPIO inputs. For example, if I press the button connected to the Pi then the button in the web interface would be pressed too. I just want to understand tha concept that should be used to get a bi-direcrectional communication. Thanks!
1 Answer
What you would need to do is utilise a socket. A socket allows a server and client to communicate directly with an ongoing connection.
The advantage of this is fairly high. Let's say you want a user interface on the Raspberry Pi, you'll find most interfaces are fairly lacking. Except on of course: HTML. This pretty much sounds like what you want. You have a server which presents a UI, as well as a socket that can communicate directly with the pages. Then you can even allow the pages to give feedback to the server, or simply allow the server to react to physical elements like a button push and then inform the sockets of a state change.
-
The node.js based Socket.IO might seem a misleading and poor choice of terms since a network socket is a fundamental entity of all networking (read: you cannot do anything on a computer network without the use of a socket), although it is abstracted away at the web programming level. Anyway, it is based on WebSockets (see here) which is the more general (i.e., not confined to node.js) approach used in contemporary web programming.– goldilocks ♦Commented Oct 3, 2017 at 13:54
-
That's why I gave you a link in my explanation. It's probably also why 2 other people have +1'd this answer. Commented Oct 3, 2017 at 13:57
-
No, the link in the answer obfuscates this -- it makes it sound like this is a special thing not used for normal http stuff. That's true of websockets, it is not true of "sockets". Really that module should have been called Websocket.IO. I'm just pointing this out lest someone down the road become confused and believe that normal web stuff and all other forms of network communication are not socket based. So it would make more sense to say "a socket allows a server and client to communicate", period, no qualifications, if it were not for the poor choice of names ("Socket.IO").– goldilocks ♦Commented Oct 3, 2017 at 14:01
-
Put another way, this is not really a problem of your answer but one derived from the Socket.IO docs.– goldilocks ♦Commented Oct 3, 2017 at 14:02