Using HTTP and MQTT

Although Particle.publish() makes it very easy to send data to the Particle Cloud, you need to know how to send data from devices in other ways. This is the case when you are not using a Particle device or when you want to send data directly to your cloud back end (e.g. Azure IoT Hub). Although there are many different ways to send data, you will often use either HTTP or MQTT.

HTTP or Hypertext Transfer Protocol is the protocol that drives the web and it is used by your web browser when it talks to web servers on the Internet. An IoT device can also use that protocol to send data and Azure IoT Hub supports this. In this chapter, we will send data to an Azure Function to illustrate the use of HTTP from the Particle. The Photon will perform an HTTP POST to the Azure Function and receive the response:

MQTT or Message Queue Telemetry Transport is designed as a very lightweight, publish/subscribe (PubSub) messaging protocol that has proven itself particularly useful in machine-to-machine or IoT scenarios. Many IoT platforms use MQTT and it should come as no surprise that Azure IoT Hub supports it as well. In this chapter though, we will see how to talk to generic MQTT servers that support both unencrypted and encrypted communication.

You will discover that communication using HTTP and MQTT without encryption is very easy to do. Encrypting the communications channel with TLS, on the other hand, is complicated due to the performance and memory overhead that comes with encryption. For HTTPS, Particle has a simple solution with Webhooks via the Particle Cloud. In addition, there are some community libraries available but they are not guaranteed to work and should not be used in production.

results matching ""

    No results matching ""