An IoT Kickstart is a Scaleway instance providing an application for a typical IoT use case.
Scaleway will spawn, install and configure the instance for you with the required software so messages flowing through your IoT Hub end up in the application.
The function as a service Kickstart provides a FaaS engine to trigger functions upon receiving messages on your IoT Hub.
It will setup and configure Nuclio on a Scaleway instance.
First go to the Kickstarts page in your Scaleway console and click the
+ button, then :
A first example function will be pre-configured for you. It sends a message to a topic named
events when triggered and is configured to be triggered when a message is published to any topic under
please/react/to/ on your IoT Hub.
You can test it pretty easily :
mosquitto_sub -h ENDPOINT -i ID_A -t events.
mosquitto_pub -h ENDPOINT -i ID_B -t please/react/to/hello/world -m "Hi there.".
You should have received a message on device A with the following payload:
Received a message on please/react/to/hello/world (length: 9). This message was generated by the example function running in Nuclio.
That’s it ! You’re done creating and using the Kickstart. Next we’ll see how to tweak Kickstart to betted fit your needs.
Now you’ve seen how to use IoT function as a service Kickstart, here is how to go further.
The function which will handle your messages will receive 2 arguments:
events.url: the topic the message was published to
events.body: the message payload
When the function is done processing the message, it may return a message to be published using the following parameters:
X-MQTT-Topic: the topic to publish message to (any valid topic string)
X-MQTT-Retain: whether to set the retain flag on the message (boolean value) (optional, default: false)
Nuclio connects a MQTT client to the IoT Hub and subscribes to a topic. When a message is received, it runs the function against it and, if requested by the function, publishes back a message on the IoT Hub.
Because of the way triggers are implemented in Nuclio, it spawns one MQTT client per function. This means you need to add an IoT Device to your IoT Hub for each function.
To create the trigger for your function:
iot.fr-par.scw.cloud:1883as URL (this may vary, refer to the IoT Hub overview page in your Scaleway console)