~~boss~~
09/08/2025, 4:05 AM~~boss~~
09/08/2025, 4:06 AM~~boss~~
09/08/2025, 4:08 AM// Copyright (C) 2022 Toitware ApS.
// Use of this source code is governed by a Zero-Clause BSD license that can
// be found in the EXAMPLES_LICENSE file.
import dhtxx
import gpio
GPIO-PIN-NUM ::= 32
main:
pin := gpio.Pin GPIO-PIN-NUM
driver := dhtxx.Dht22 pin
// On some versions of Toit/ESP-IDF it is necessary to sleep a bit before
// reading the sensor for the first time.
sleep --ms=300
(Duration --s=1).periodic:
print driver.readfloitsch
09/08/2025, 7:38 AM~~boss~~
09/11/2025, 4:00 PM~~boss~~
09/11/2025, 4:02 PM~~boss~~
09/11/2025, 4:22 PM~~boss~~
09/11/2025, 4:24 PMfloitsch
09/11/2025, 7:49 PMwhile true:
read new temperature
signal to others
sleep 5s
--
in parallel:
- wait for new values, and upload each one to datacake
- blink led. If current value is below, blink fast otherwise slow
- ....
I'm pretty sure my example is not what you try to do, but if you provide your pseudo code I can probably figure out what you should use~~boss~~
09/12/2025, 2:16 AM~~boss~~
09/12/2025, 2:17 AM~~boss~~
09/12/2025, 2:18 AM~~boss~~
09/12/2025, 2:23 AMimport datacake
import dhtxx
import gpio
import monitor
latch := monitor.Latch
sensor ::= 18
main:
task:: producer-task-code
task:: consumer-task-code
producer-task-code:
client := datacake.connect
pin := gpio.Pin sensor
driver := dhtxx.Dht22 pin
sleep --ms=3000
result := driver.read-temperature
temperature := datacake.Float "TEMPERATURE" --precision=1
temperature.publish client result
print "task one finished"
latch.set result
consumer-task-code:
temp := latch.get
if temp == 21: print "led 1 on"
if temp > 21:
print "led 2 on"floitsch
09/12/2025, 7:25 AM~~boss~~
09/12/2025, 7:26 AM~~boss~~
09/12/2025, 7:31 AM~~boss~~
09/12/2025, 7:32 AM~~boss~~
09/12/2025, 7:33 AMsutida@MacBook-Air-khxng-pleng src % jag container install datacake service.toit -D datacake.api.token=f206ee24cf21ca04429ee472b1dbbe6054110822 -D datacake.device.id=esp32 -D datacake.product.slug=esp32-34
Installing container 'datacake' from 'service.toit' on 'wizardly-company' ...
/Users/sutida/Desktop/python main/project/.packages/github.com/kasperl/toit-datacake/0.1.2/package.lock:7:10: error: Package 'github.com/toitware/mqtt-2.1.1' not found
url: github.com/toitware/mqtt
^~~~~~~~~~~~~~~~~~~~~~~~
/Users/sutida/Desktop/python main/project/.packages/github.com/kasperl/toit-datacake/0.1.2/package.lock:11:10: error: Package 'github.com/toitware/toit-cert-roots-1.4.0' not found
url: github.com/toitware/toit-cert-roots
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
service.toit:11:8: error: Package 'toit-cert-roots' for prefix 'certificate-roots' not found
import certificate_roots
^~~~~~~~~~~~~~~~~
service.toit:12:8: error: Package 'mqtt' for prefix 'mqtt' not found
import mqtt
^~~~
service.toit:13:8: error: Package 'mqtt' for prefix 'mqtt' not found
import mqtt.packets as mqtt
^~~~
Compilation failedfloitsch
09/12/2025, 7:36 AM~~boss~~
09/12/2025, 7:36 AMfloitsch
09/12/2025, 7:36 AMfloitsch
09/12/2025, 7:36 AMfloitsch
09/12/2025, 7:38 AM~~boss~~
09/12/2025, 7:39 AMfloitsch
09/12/2025, 7:40 AM/Users/sutida/Desktop/python main/project/.packages/github.com/kasperl/toit-datacake/0.1.2/src~~boss~~
09/12/2025, 7:40 AMfloitsch
09/12/2025, 7:40 AM.packages directory is where the packages for your project are.floitsch
09/12/2025, 7:41 AMfloitsch
09/12/2025, 7:42 AM/Users/sutida/Desktop/python main/project.
with the following content:
import datacake.service
main:
service.main
Then run that instead.floitsch
09/12/2025, 7:43 AMfloitsch
09/12/2025, 7:44 AM.packages directory, it will think that the .packages/github.com/kasperl/toit-datacake/0.1.2/ is its own project (which it fundamentally is). And that project isn't set up yet as nobody ran a pkg install there.floitsch
09/12/2025, 7:44 AMdatacake.toit with the same defines as you wrote above.floitsch
09/12/2025, 7:45 AM~~boss~~
09/12/2025, 7:48 AMjag container install datacake datacake.toit -D datacake.api.token=f206ee24cf21ca04429ee472b1dbbe6054110822 -D datacake.device.id=esp32 -D datacake.product.slug=esp32-34
Installing container 'datacake' from 'datacake.toit' on 'wizardly-company' ...
<pkg:toit-datacake>/service.toit:69:7: error: Missing implementations for interface methods
class DatacakeServiceProvider extends ServiceProvider implements ServiceHandler:
^~~~~~~~~~~~~~~~~~~~~~~
<sdk>/system/services.toit:315:3: note: Missing implementation for 'handle'
handle index/int arguments/any --gid/int --client/int -> any
^~~~~~
Compilation failed~~boss~~
09/12/2025, 7:49 AMfloitsch
09/12/2025, 7:50 AMfloitsch
09/12/2025, 7:51 AMfloitsch
09/12/2025, 7:53 AMfloitsch
09/12/2025, 7:57 AMgit clone https://github.com/kasperl/toit-datacake.git
cd toit-datacake
jag pkg install
jag container install datacake src/service.toit -D ...
cd ..
In theory that would install the service from the latest sources. (Note that we can use the service.toit file directly this time, as we created a separate directory and did pkg install in it).~~boss~~
09/12/2025, 8:11 AMfloitsch
09/12/2025, 8:14 AM~~boss~~
09/12/2025, 8:14 AMfloitsch
09/12/2025, 8:15 AM~~boss~~
09/12/2025, 8:15 AMfloitsch
09/12/2025, 8:15 AMfloitsch
09/12/2025, 8:15 AMfloitsch
09/12/2025, 8:15 AMfloitsch
09/12/2025, 8:16 AM~~boss~~
09/12/2025, 8:17 AM~~boss~~
09/12/2025, 8:17 AMfloitsch
09/12/2025, 8:17 AMfloitsch
09/12/2025, 8:18 AM~~boss~~
09/12/2025, 10:37 AM~~boss~~
09/12/2025, 10:37 AMfloitsch
09/12/2025, 10:38 AMsheet.appendRow([new Date(data.timestamp), data.temperature, data.humidity]);floitsch
09/12/2025, 10:38 AMappendRow should add new rows.~~boss~~
09/12/2025, 10:40 AM~~boss~~
09/12/2025, 1:28 PMesp.toit:4:8: error: Package for prefix 'certificate-roots' not found
import certificate_rootsfloitsch
09/12/2025, 1:31 PMjag pkg install github.com/toitware/toit-cert-roots@v1~~boss~~
09/13/2025, 3:30 PM~~boss~~
09/13/2025, 3:31 PMfloitsch
09/13/2025, 3:31 PM~~boss~~
09/13/2025, 3:33 PMEXCEPTION error.
insufficient signals from DHT
0: Driver.read-data-no-catch_ <pkg:toit-dhtxx>/driver_.toit:128:7
1: Driver.read-data_.<block>.<block>.<block>.<block> <pkg:toit-dhtxx>/driver_.toit:91:20
2: Driver.read-data_.<block>.<block>.<block> <pkg:toit-dhtxx>/driver_.toit:89:32
3: Task_.with-deadline_.<block> <sdk>/core/task.toit:223:16
4: Task_.with-deadline_ <sdk>/core/task.toit:217:3
5: with-timeout <sdk>/core/utils.toit:189:24
6: with-timeout <sdk>/core/utils.toit:181:10
7: Driver.read-data_.<block>.<block> <pkg:toit-dhtxx>/driver_.toit:89:9
8: catch.<block> <sdk>/core/exceptions.toit:124:10
9: catch <sdk>/core/exceptions.toit:122:1
10: catch <sdk>/core/exceptions.toit:73:10
11: Driver.read-data_.<block> <pkg:toit-dhtxx>/driver_.toit:88:7
12: SmallInteger_.repeat <sdk>/core/numbers.toit:1288:3
13: Driver.read-data_ <pkg:toit-dhtxx>/driver_.toit:87:14
14: Driver.read-temperature <pkg:toit-dhtxx>/driver_.toit:63:31
15: main.<block> test.toit:19:18
16: Duration.of <sdk>/core/time.toit:221:10
17: Duration.periodic <sdk>/core/time.toit:276:19
18: main test.toit:17:20
****************~~boss~~
09/13/2025, 3:34 PMfloitsch
09/13/2025, 3:34 PMfloitsch
09/13/2025, 3:34 PM~~boss~~
09/13/2025, 3:34 PMfloitsch
09/13/2025, 3:34 PMfloitsch
09/13/2025, 3:34 PM~~boss~~
09/13/2025, 3:34 PMfloitsch
09/13/2025, 3:36 PMread. That gives you a DhtResult which contains both values.~~boss~~
09/13/2025, 3:36 PM~~boss~~
09/13/2025, 3:36 PMfloitsch
09/13/2025, 3:36 PMfloitsch
09/13/2025, 3:37 PMread (instead of read-temperature and read-humidity) to get both at the same time. Then you don't need any sleep.~~boss~~
09/13/2025, 3:38 PMfloitsch
09/13/2025, 3:38 PMresult := sensor.read
temperature := result.temperature
humidity := result.humidity~~boss~~
09/13/2025, 3:38 PM~~boss~~
09/13/2025, 3:48 PMfloitsch
09/13/2025, 3:50 PM~~boss~~
09/13/2025, 3:51 PM~~boss~~
09/13/2025, 3:52 PMfloitsch
09/13/2025, 3:52 PMto-string --fixed?
Unfortunately that's not implemented yet.
A bit embarrassing, since I published a paper on how to do it efficiently...floitsch
09/13/2025, 3:54 PM(x * 100).to-int or .round and then insert the dot. (Paying attention to the 0)floitsch
09/13/2025, 3:55 PM~~boss~~
09/13/2025, 4:25 PMfloitsch
09/13/2025, 4:26 PM~~boss~~
09/13/2025, 4:28 PMtemp := driver.read-temperature
temp2 := ((temp*10000).round)
sleep --ms=500
humid:= driver.read-humidity
humid2 := ((humid*10000).round)
print "$((temp2/10000).to-float) $((humid2/10000).to-float)"~~boss~~
09/13/2025, 4:28 PM~~boss~~
09/13/2025, 4:28 PMfloitsch
09/13/2025, 4:28 PMfloitsch
09/13/2025, 4:29 PMtemp2/10000.0.floitsch
09/13/2025, 4:29 PMfloitsch
09/13/2025, 4:30 PM~~boss~~
09/13/2025, 4:31 PMfloitsch
09/13/2025, 4:31 PM~~boss~~
09/13/2025, 4:32 PMfloitsch
09/13/2025, 4:33 PMtemp2 := (temp * 100).round
str := temp2.to-string
if temp2 != 0:
str = "$(str[..str.size - 2]).$str[str.size - 2..]"floitsch
09/13/2025, 4:33 PM~~boss~~
09/13/2025, 4:35 PM~~boss~~
09/14/2025, 4:31 AM~~boss~~
09/14/2025, 4:31 AMimport http
import dhtxx
import gpio
import net
import certificate-roots
sensor ::= 18
relay-pump ::= 4
relay-fan ::= 5
URL ::= "https://script.google.com/macros/s/AKfycbzGpAen9NMdYgqbyilihGGVSC6IfYVyuz0mc-dlelItSFaq8DwnfSLUGZucXEEUdPFttw/exec"
main:
pin := gpio.Pin sensor --output
pump := gpio.Pin relay-pump --output
fan := gpio.Pin relay-fan --output
driver := dhtxx.Dht22 pin
network := net.open
client := http.Client.tls network
certificate-roots.install-common-trusted-roots
while true:
sleep --ms=500
temp := driver.read-temperature
sleep --ms=500
humid:= driver.read-humidity
response := client.post-json --no-follow-redirects --uri=URL {"timestamp": Time.now.utc.to-iso8601-string,"temperature": temp,"humidity": humid,}
if humid > 50:
fan.set 1
pump.set 0
sleep --ms=11000
if humid < 40 and temp > 29.4:
pump.set 1
fan.set 1
sleep --ms=11000
else:
pump.set 0
fan.set 0
sleep --ms=11000~~boss~~
09/14/2025, 4:31 AMfloitsch
09/15/2025, 8:38 AMelse if for the humid < 40 part?
Currently, if the humid > 50 you set the fan and sleep 10s. Then if checks for humid < 40 which it isn't, and therefore enters the else branch, stopping the fan for 10s.