IoT device communications
As we saw in Chapter 9, Getting the Information You Need, our Pi can ask for information from the internet using HTTP requests. But what if we want regular data sent to the Pi in real-time? What if we want a swarm of devices chatting with each other, data sent back and forth as necessary? Let's take a look at a few ways this can be accomplished with web technologies.
Long polling
Long polling involves asking for information via HTTP requests at certain intervals. If this sounds familiar, it's because that's precisely what we did in our weather dashboard project in Chapter 9, Getting the information you need; we poll the OpenWeather API every 60 seconds. This approach is best when there aren't other options; some REST APIs do not have a way to hold a connection open or establish two-way communication, and long polling is the way to go in these situations.
But there are newer ways of establishing two-way connections that can be left open, including the Websocket.