Skip to content

Commit

Permalink
Adjust tutorials to match v3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Nov 12, 2024
1 parent 2b076e3 commit a818c83
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 deletions docs/pages/tutorials/arduino_style/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ Next, we'll create the SensESP application using the builder class. Add the foll
This will create a SensESP app with the hostname `sensesp-bme280`. You can change this to whatever you want, but make sure it's unique on your network. The builder class also allows you to set the WiFi SSID and password and other settings, if needed. See the [SensESPAppBuilder](/generated/docs/classsensesp_1_1_sens_e_s_p_app_builder.html) documentation for more information.
One more thing to do is to add the `app.tick();` command to the end of the `loop()` function. This call triggers execution of any ReactESP events that have been scheduled.
Now, let's start our program. Add the line `sensesp_app->start();` at the very end of the `setup()` function. This will start the SensESP app and connect to the WiFi network.
One more thing to do is to add the `event_loopU()->tick();` command to the end of the `loop()` function. This call triggers execution of any ReactESP events that have been scheduled.
We're almost ready to give it a go! There's one more thing that is unobvious but very important. Have a look at the current `loop()` function:
Expand All @@ -204,11 +202,11 @@ void loop() {
printValues();
delay(delayTime);
app.tick();
event_loop()->tick();
}
```

Every time it is run, after printing the values, the software will sleep for `delayTime` (1000) milliseconds, or one second. And only after that it calls the `app.tick()` function that is responsible for handling network connectivity, receiving and transmitting data, updating the web UI and a myriad of tasks. All these would only be called once every second, which is not even nearly enough for the software to work properly!
Every time it is run, after printing the values, the software will sleep for `delayTime` (1000) milliseconds, or one second. And only after that it calls the `event_loop()->tick()` function that is responsible for handling network connectivity, receiving and transmitting data, updating the web UI and a myriad of tasks. All these would only be called once every second, which is not even nearly enough for the software to work properly!

A major, fundamental rule in asynchronous programming (of which ReactESP is a simple example) is that you should never block the main loop. If you do, you'll block all the other tasks as well. So, let's remove the `delay(delayTime);` line from the `loop()` function.

Expand All @@ -223,7 +221,7 @@ void loop() {
last_run = millis();
}

app.tick();
event_loop()->tick();
}
```

Expand All @@ -243,7 +241,7 @@ SKOutput<float>* temperature_output;
SKOutput<float>* humidity_output;
```

And then, in `setup()`, let's create the `SKOutput` objects. Add the following lines to the `setup()` function, right before the `sensesp_app->start();` line:
And then, in `setup()`, let's create the `SKOutput` objects. Add the following lines to the end of `setup()` function:

```cpp
pressure_output = new SKOutput<float>(
Expand Down Expand Up @@ -357,8 +355,6 @@ void setup() {
"/sensors/bme280/humidity",
new SKMetadata("ratio", "Cabin relative humidity")
);

sensesp_app->start();
}

void loop() {
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/tutorials/bmp280.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ It lists two libraries:

```c++
lib_deps =
SignalK/SensESP @ ^2.0.0
SignalK/SensESP @ ^3.0.0
adafruit/Adafruit BMP280 Library @ ^2.5.0
```

Every SensESP project will include `Signalk/SensESP`, and depending on the version of SensESP being used, it may or may not include the `@ ^2.0.0`, or some variation of that.
Every SensESP project will include `Signalk/SensESP`, and depending on the version of SensESP being used, it may or may not include the `@ ^3.0.0`, or some variation of that.

This Tutorial reads a physical sensor that is read with a library that's not part of the SensESP core code - an Adafruit BMP280 Temperature and Pressure sensor.
So we have to add that library to the `lib_deps` section, so that PlatformIO will know to download it before attempting to build this project.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/tutorials/bmp280_part_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Look at the `lib_deps` section of the `platformio.ini`. It lists two libraries:

```c++
lib_deps =
SignalK/SensESP @ ^2.0.0
SignalK/SensESP @ ^3.0.0
adafruit/Adafruit BMP280 Library @ ^2.5.0
```

Expand Down

0 comments on commit a818c83

Please sign in to comment.