GoogleCloudPlatform / node-red-contrib-google-cloud

Node-RED nodes for Google Cloud Platform
Apache License 2.0
90 stars 57 forks source link

Add a "Message hub" for bidirectionnal IOT communication #124

Closed chenav closed 1 year ago

chenav commented 1 year ago

Hello,

The 'telemetry send' node is a simple "sender". It contains a connection opener, without any subscriptions to the standard 'config' and 'commands' topics. Then, the iot features lack interactions coming from the cloud.

I implemented a "message hub" node, which allows bidirectionnal message and guarantees the availability of the connection (in case of timeout or loss of the connection). It works exactly the same for emission as the previous 'telemetry send' node. But, on reception of message from the cloud, it sends to the flow a message containing:

I isolated the communication functions in iot-utils.js, to clarify the code of the actual node and make the connectivity features more readable. The class IotUtils follows the pattern of a connection pool, allowing a centralized management for several "mqttClient" / devices.

Also, the iot-utils features ensure the right order of the connection steps through a Promise and takes advantages from the 'connected' boolean attribute of the mqqt client, to ensure that the connection is open OR to reconnect the device if needed.

A diagram of usage could be this one:

message-hub

I did not remove the telemetry send node, even if such a new node could make it 'deprecated'

C.

google-cla[bot] commented 1 year ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.