From 19c7a424ba0286f2ad61e702dfce0b5929a08682 Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Fri, 4 Sep 2026 14:19:17 +0200 Subject: [PATCH] Update BME280 and MQTT tutorials --- docs/tutorials/hardware/bme280.mdx | 14 +++++++------- docs/tutorials/mqtt/index.mdx | 8 ++++++-- tools/package.lock | 7 +++++++ tools/package.yaml | 3 +++ tools/run_snippets.toit | 1 + tutorial_code/bme280/bme280.toit | 10 +++++----- tutorial_code/bme280/bme280_alt.toit | 10 +++++----- tutorial_code/bme280/package.lock | 10 +++++----- tutorial_code/bme280/package.yaml | 6 +++--- tutorial_code/mqtt_mosquitto/mqtt_v2.toit | 3 ++- 10 files changed, 44 insertions(+), 28 deletions(-) diff --git a/docs/tutorials/hardware/bme280.mdx b/docs/tutorials/hardware/bme280.mdx index fd6f40df..39ce6039 100644 --- a/docs/tutorials/hardware/bme280.mdx +++ b/docs/tutorials/hardware/bme280.mdx @@ -38,16 +38,16 @@ The driver for the BME280 is not part of the standard Toit distribution, but must be downloaded as package. See the [packages](../../setup/packages) tutorial for details. -We are using the [bme280](https://pkg.toit.io/package/github.com%2Ftoitware%2Fbme280-driver@v1) +We are using the [bmx280](https://pkg.toit.io/package/github.com%2Ftoit-pkg%2Ftoit-bmx280@v1) package. To install it, run the following command in your project directory: ```bash -jag pkg install github.com/toitware/bme280-driver@v1 +jag pkg install github.com/toit-pkg/toit-bmx280@v1 ``` -You can probably just write `jag pkg install bme280`, but the full ID together +You can probably just write `jag pkg install bmx280`, but the full ID together with the version is more explicit, and will make sure you get the right package. @@ -58,7 +58,7 @@ the program whenever you save. ```toit import i2c -import bme280 +import bmx280 main: bus := i2c.Bus @@ -67,9 +67,9 @@ main: // Use 'I2C-ADDRESS' if your device has address 0x76 (118). // Use 'I2C-ADDRESS-ALT' if your device has address 0x77 (119). - device := bus.device bme280.I2C-ADDRESS + device := bus.device bmx280.I2C-ADDRESS - driver := bme280.Driver device + driver := bmx280.Driver device print "$driver.read-temperature C" print "$driver.read-pressure Pa" @@ -81,7 +81,7 @@ main: The program first instantiates an I2C bus object, which it uses to get a handle to the device with the BME280 address. It then passes -this device to the BME280 driver. At that point the driver +this device to the BMX280 driver. At that point the driver configures the sensor. When `read-temperature`, `read-pressure` and `read-huminity` diff --git a/docs/tutorials/mqtt/index.mdx b/docs/tutorials/mqtt/index.mdx index 58ef54d6..a7257439 100644 --- a/docs/tutorials/mqtt/index.mdx +++ b/docs/tutorials/mqtt/index.mdx @@ -289,7 +289,10 @@ In some cases, the certificate might be given by the server and should be pasted the sources. Once we have the root certificates, the client can be created with the `tls` -named constructor as follows: +named constructor. The default TLS port, 8883, uses a certificate signed by +Mosquitto's own certificate authority. Port 8886 uses a certificate issued by +Let's Encrypt that can be verified with the common trusted roots, so we select +that port explicitly: ```toit import mqtt @@ -298,6 +301,7 @@ import encoding.json CLIENT-ID ::= "toit-tutorial-ID-2023-07-06" HOST ::= "test.mosquitto.org" +PORT ::= 8886 TOPIC ::= "toit-mqtt/tutorial" main: @@ -308,7 +312,7 @@ main: decoded := json.decode payload print "Received value on '$topic': $decoded" } - client := mqtt.Client.tls --host=HOST --routes=routes + client := mqtt.Client.tls --host=HOST --port=PORT --routes=routes client.start --client-id=CLIENT-ID while true: diff --git a/tools/package.lock b/tools/package.lock index b85777b8..58af9c1c 100644 --- a/tools/package.lock +++ b/tools/package.lock @@ -1,6 +1,7 @@ sdk: ^2.0.0-alpha.196 prefixes: bme280: github.com/toitware/bme280-driver-1 + bmx280: github.com/toit-pkg/toit-bmx280-1 cellular: github.com/toitware/cellular-2 certificate_roots: github.com/toitware/toit-cert-roots-1 cli: github.com/toitlang/pkg-cli-2 @@ -44,6 +45,12 @@ packages: sensors: github.com/toitware/toit-sensors-1 url: github.com/lask/toit-hc-sr04 version: 2.3.0 + github.com/toit-pkg/toit-bmx280-1: + hash: d1de0a840c125769f28b6ddaa8d446a1dc4b1f22 + prefixes: + sensors: github.com/toitware/toit-sensors-1 + url: github.com/toit-pkg/toit-bmx280 + version: 1.0.0 github.com/toitlang/pkg-cli-2: hash: 8f58b041d55440916a2527899df505f6c6259b20 prefixes: diff --git a/tools/package.yaml b/tools/package.yaml index da8396c4..9905a4a6 100644 --- a/tools/package.yaml +++ b/tools/package.yaml @@ -2,6 +2,9 @@ dependencies: bme280: url: github.com/toitware/bme280-driver version: ^1.2.0 + bmx280: + url: github.com/toit-pkg/toit-bmx280 + version: ^1.0.0 cellular: url: github.com/toitware/cellular version: ^2.8.0 diff --git a/tools/run_snippets.toit b/tools/run_snippets.toit index 80a2fa50..13594767 100644 --- a/tools/run_snippets.toit +++ b/tools/run_snippets.toit @@ -34,6 +34,7 @@ DEFAULT-OUTPUT ::= "snippet.toit" THINGS-THAT-WONT-RUN-ON-SERVER ::= [ "import bme280", + "import bmx280", "import dhtxx", "import ds18b20", "import gpio", diff --git a/tutorial_code/bme280/bme280.toit b/tutorial_code/bme280/bme280.toit index de9379b9..4ed6ed48 100644 --- a/tutorial_code/bme280/bme280.toit +++ b/tutorial_code/bme280/bme280.toit @@ -3,18 +3,18 @@ // be found in the LICENSE_BSD0 file. import i2c -import bme280 +import bmx280 main: bus := i2c.Bus --sda=25 --scl=26 - // Use 'I2C_ADDRESS' if your device has address 0x76 (118). - // Use 'I2C_ADDRESS_ALT' if your device has address 0x77 (119). - device := bus.device bme280.I2C-ADDRESS + // Use 'I2C-ADDRESS' if your device has address 0x76 (118). + // Use 'I2C-ADDRESS-ALT' if your device has address 0x77 (119). + device := bus.device bmx280.I2C-ADDRESS - driver := bme280.Driver device + driver := bmx280.Driver device print "$driver.read-temperature C" print "$driver.read-pressure Pa" diff --git a/tutorial_code/bme280/bme280_alt.toit b/tutorial_code/bme280/bme280_alt.toit index 20db545b..90acbb73 100644 --- a/tutorial_code/bme280/bme280_alt.toit +++ b/tutorial_code/bme280/bme280_alt.toit @@ -3,18 +3,18 @@ // be found in the LICENSE_BSD0 file. import i2c -import bme280 +import bmx280 main: bus := i2c.Bus --sda=26 --scl=25 - // Use 'I2C_ADDRESS' if your device has address 0x76 (118). - // Use 'I2C_ADDRESS_ALT' if your device has address 0x77 (119). - device := bus.device bme280.I2C-ADDRESS-ALT + // Use 'I2C-ADDRESS' if your device has address 0x76 (118). + // Use 'I2C-ADDRESS-ALT' if your device has address 0x77 (119). + device := bus.device bmx280.I2C-ADDRESS-ALT - driver := bme280.Driver device + driver := bmx280.Driver device print "$driver.read-temperature C" print "$driver.read-pressure Pa" diff --git a/tutorial_code/bme280/package.lock b/tutorial_code/bme280/package.lock index 49b97de9..e44e094b 100644 --- a/tutorial_code/bme280/package.lock +++ b/tutorial_code/bme280/package.lock @@ -1,13 +1,13 @@ sdk: ^2.0.0-alpha.196 prefixes: - bme280: github.com/toitware/bme280-driver-1 + bmx280: github.com/toit-pkg/toit-bmx280-1 packages: - github.com/toitware/bme280-driver-1: - hash: ca9c6451532139d506299fba8c0915cd3001982e + github.com/toit-pkg/toit-bmx280-1: + hash: d1de0a840c125769f28b6ddaa8d446a1dc4b1f22 prefixes: sensors: github.com/toitware/toit-sensors-1 - url: github.com/toitware/bme280-driver - version: 1.2.0 + url: github.com/toit-pkg/toit-bmx280 + version: 1.0.0 github.com/toitware/toit-sensors-1: hash: f9f5662a0f21016259ff6907419e54d00223714a url: github.com/toitware/toit-sensors diff --git a/tutorial_code/bme280/package.yaml b/tutorial_code/bme280/package.yaml index 1526e2bd..f1932b8d 100644 --- a/tutorial_code/bme280/package.yaml +++ b/tutorial_code/bme280/package.yaml @@ -1,4 +1,4 @@ dependencies: - bme280: - url: github.com/toitware/bme280-driver - version: ^1.2.0 + bmx280: + url: github.com/toit-pkg/toit-bmx280 + version: ^1.0.0 diff --git a/tutorial_code/mqtt_mosquitto/mqtt_v2.toit b/tutorial_code/mqtt_mosquitto/mqtt_v2.toit index ec2d84bd..63519915 100644 --- a/tutorial_code/mqtt_mosquitto/mqtt_v2.toit +++ b/tutorial_code/mqtt_mosquitto/mqtt_v2.toit @@ -8,6 +8,7 @@ import encoding.json CLIENT-ID ::= "toit-tutorial-ID-2023-07-06" HOST ::= "test.mosquitto.org" +PORT ::= 8886 TOPIC ::= "toit-mqtt/tutorial" main: @@ -18,7 +19,7 @@ main: decoded := json.decode payload print "Received value on '$topic': $decoded" } - client := mqtt.Client.tls --host=HOST --routes=routes + client := mqtt.Client.tls --host=HOST --port=PORT --routes=routes client.start --client-id=CLIENT-ID while true: