Cloud Scenario

Finally we want to also receive data from the cloud, to do so we will use HTTP GET requests.

We will create a new Node-RED flow that periodically sends request to the server and acts on the received data.

The video above uses an inject node that sends an empty message every five seconds to trigger a request to the server.

The response is then formatted using function block containing the following code:

var values = msg.payload['values'];
var last = values[values.length - 1];
var value = last['value'];

var out = { 'payload' : value };

return out;

Task: Replicate the flow setup shown in the video. Replace the endpoint configured in the http request node by the one corresponding to your device name.

Task: By reading the sourcecode and experimenting find out what the flow does and what the output of the “Formatter” function node is.

Task: Control a microcontroller based on the output of the “Formatter” block. E.g. turn on a light after a certain number of button presses.

Group phase

Step 1: Choose a sensor you would like to use and, using the microcontroller, MQTT, Node-RED and HTTP build a complete chain to send sensor readings to the cloud.

Step 2: Fetch sensor readings from another group from the cloud and control an actuator of your liking based on the values you get.

Example: One group builds a thermometer that publishes temperatures to the cloud. You take the readings from that sensor and, once it gets too hot, use a servo motor and a piece of paper to fan air.