From cb7fbe145a63fcb7d32bbb29540a0e5983d74bdf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karl=20S=C3=B6derby?=
<35461661+karlsoderby@users.noreply.github.com>
Date: Fri, 22 Sep 2023 14:54:10 +0200
Subject: [PATCH 1/4] draft
---
.../arduino-cloud-callbacks.md | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
create mode 100644 content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
diff --git a/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md b/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
new file mode 100644
index 0000000000..88a8337064
--- /dev/null
+++ b/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
@@ -0,0 +1,19 @@
+---
+title: 'IoT Cloud Event & Callbacks'
+description: 'Learn how to subscribe to events and add callback functions.'
+tags: [IoT Cloud, Variables]
+author: 'Karl Söderby'
+---
+
+The [Arduino IoT Cloud](https://create.arduino.cc/iot/) has support for events and callbacks. This can be used to trigger specific functionalities depending on what state your device is in.
+
+You can for example trigger a specific block of code whenever the board is in a connecting, synchronized or disconnected state. In this brief document, we will explore how to set it up, using an example from the [ArduinoIoTCloud](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino) library.
+
+## Full Example
+
+The example below demonstrates the available callback
+
+## Summary
+
+In this article, we have covered how to use variables in the Arduino IoT Cloud, and what variables are available.
+
From 4d10ebbb546f7ba1ef37c2dcf2fa73aab7f0bb94 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karl=20S=C3=B6derby?=
<35461661+karlsoderby@users.noreply.github.com>
Date: Fri, 22 Sep 2023 17:00:38 +0200
Subject: [PATCH 2/4] Update arduino-cloud-callbacks.md
---
.../arduino-cloud-callbacks.md | 37 ++++++++++++++++---
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md b/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
index 88a8337064..981d4f7c0d 100644
--- a/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
+++ b/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
@@ -1,19 +1,46 @@
---
title: 'IoT Cloud Event & Callbacks'
description: 'Learn how to subscribe to events and add callback functions.'
-tags: [IoT Cloud, Variables]
+tags: [IoT Cloud, Events, Callbacks]
author: 'Karl Söderby'
---
The [Arduino IoT Cloud](https://create.arduino.cc/iot/) has support for events and callbacks. This can be used to trigger specific functionalities depending on what state your device is in.
-You can for example trigger a specific block of code whenever the board is in a connecting, synchronized or disconnected state. In this brief document, we will explore how to set it up, using an example from the [ArduinoIoTCloud](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino) library.
+You can for example trigger a specific block of code whenever the board is in a **connecting**, **synchronized** or **disconnected** state. In this brief document, we will explore how to set it up, using an example from the [ArduinoIoTCloud](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino) library.
+
+## Events
+
+The `ArduinoIoTCloudEvent` enumeration class has three possible events:
+- `CONNECT` (0) - Board successfully connects to IoT Cloud.
+- `SYNC` (1) - Data is successfully synced between Board and IoT Cloud.
+- `DISCONNECT` (2) - Board has lost connection to IoT Cloud.
+
+The `CONNECT` and `DISCONNECT` events can occur even though no variable is created inside the Thing. However, `SYNC` requires a variable to be created, as this triggers whenever data is synchronized between the board and cloud.
+
+These events can be subscribed to using the `addCallback()` function, which is documented in the next section.
+
+## Callbacks
+
+Callbacks can be added for each event, and essentially triggers a custom function whenever the event occurs.
+
+Callbacks are added via the `addCallback()` method from the `ArduinoIoTCloud` class, where the **event** and **custom function** are added as parameters.
+
+```arduino
+ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect);
+```
+
+The above code will trigger the `doThisOnConnect()`
+function whenever the `CONNECT` event occurs.
+
+***Please note that callback functions should be added inside the `setup()` of your sketch.***
## Full Example
-The example below demonstrates the available callback
+The example below demonstrates how to use events & callbacks in the IoT Cloud.
-## Summary
+
-In this article, we have covered how to use variables in the Arduino IoT Cloud, and what variables are available.
+## Summary
+This document covers the use of events & callbacks using the [ArduinoIoTCloud](https://github.com/arduino-libraries/ArduinoIoTCloud) library.
\ No newline at end of file
From 4867c3976f556817bb28eaebe985264a2a1177e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karl=20S=C3=B6derby?=
<35461661+karlsoderby@users.noreply.github.com>
Date: Fri, 29 Sep 2023 15:50:34 +0200
Subject: [PATCH 3/4] Update arduino-cloud-callbacks.md
---
.../07.arduino-cloud-callbacks/arduino-cloud-callbacks.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md b/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
index 981d4f7c0d..e8afcc0d36 100644
--- a/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
+++ b/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
@@ -7,7 +7,7 @@ author: 'Karl Söderby'
The [Arduino IoT Cloud](https://create.arduino.cc/iot/) has support for events and callbacks. This can be used to trigger specific functionalities depending on what state your device is in.
-You can for example trigger a specific block of code whenever the board is in a **connecting**, **synchronized** or **disconnected** state. In this brief document, we will explore how to set it up, using an example from the [ArduinoIoTCloud](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino) library.
+You can for example trigger a specific block of code whenever the board is in a **connecting**, **synchronized** or **disconnected** state. In this document, we will explore how to set it up, using an example from the [ArduinoIoTCloud](https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino) library.
## Events
From 150f8c6a79493a7bbe39295f89ee7bdffae34b54 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Karl=20S=C3=B6derby?=
<35461661+karlsoderby@users.noreply.github.com>
Date: Fri, 29 Sep 2023 15:50:45 +0200
Subject: [PATCH 4/4] Update arduino-cloud-callbacks.md
---
.../07.arduino-cloud-callbacks/arduino-cloud-callbacks.md | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md b/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
index e8afcc0d36..49e91d6d79 100644
--- a/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
+++ b/content/arduino-cloud/01.getting-started/07.arduino-cloud-callbacks/arduino-cloud-callbacks.md
@@ -39,8 +39,4 @@ function whenever the `CONNECT` event occurs.
The example below demonstrates how to use events & callbacks in the IoT Cloud.
-
-
-## Summary
-
-This document covers the use of events & callbacks using the [ArduinoIoTCloud](https://github.com/arduino-libraries/ArduinoIoTCloud) library.
\ No newline at end of file
+
\ No newline at end of file