Shadi
06/08/2023, 2:25 PMfloitsch
06/08/2023, 2:28 PMfloitsch
06/08/2023, 2:28 PMread
.floitsch
06/08/2023, 2:29 PMfloitsch
06/08/2023, 2:29 PMShadi
06/08/2023, 2:30 PMShadi
06/08/2023, 2:30 PMfloitsch
06/08/2023, 2:32 PMfloitsch
06/08/2023, 2:33 PMfloitsch
06/08/2023, 2:33 PMShadi
06/08/2023, 2:34 PMfloitsch
06/08/2023, 2:34 PMfloitsch
06/08/2023, 2:35 PMfloitsch
06/08/2023, 2:39 PMsensor := scd30.Scd30 device
.
Then you might be able to change the measuring interval as follows
seconds := #[0x00, 0x10]
command := #[0x46, 0x00] + seconds + #[sensor.compute_crc8_ seconds]
sensor.device_.write command
floitsch
06/08/2023, 2:39 PMfloitsch
06/08/2023, 2:40 PMfloitsch
06/08/2023, 2:41 PMseconds
is initialized to 0x10 which is 16. So not a huge difference, but you can increase that to 0xFF (255), or even up to a total of 1800 in which case you also need to change the most-significant byte).Shadi
06/08/2023, 2:44 PMfloitsch
06/08/2023, 2:44 PMfloitsch
06/08/2023, 2:44 PMScd30
object.floitsch
06/08/2023, 2:44 PMsensor := scd30.Scd30 device
.floitsch
06/08/2023, 2:45 PMShadi
06/08/2023, 2:46 PMfloitsch
06/08/2023, 2:46 PMscd30
, so just replace my sensor
with scd30
.Shadi
06/08/2023, 2:47 PMShadi
06/08/2023, 2:47 PMfloitsch
06/08/2023, 2:48 PMfloitsch
06/08/2023, 2:48 PMShadi
06/08/2023, 2:50 PMfloitsch
06/08/2023, 2:52 PMdevice.close
and bus.close
just before the esp32.deep_sleep
. (You mentioned that the i2c was draining battery. Calling close
might solve this.)floitsch
06/08/2023, 2:58 PMsleep --ms=5_500
you could look at a pin and only go to deep-sleep if that pin is not grounded.
Something like:
run_jaguar_pin := gpio.Pin 32 --input --pull_up
if run_jaguar_pin == 0:
// The pin is pulled to ground.
// Don't call deep sleep.
exit 0
You can then install your program with
jag container install -D jag.disabled -D jag.timeout=2m scd30 scd30_program.toit
This makes it such that Jaguar isn't even trying to connect to WiFi if your program is running.
However, if you program terminates (and doesn't go to deep-sleep) Jaguar starts and you can update the program.
You then only need to pull pin 32 to ground (either with a button or with a wire) to start Jaguar.Shadi
06/08/2023, 3:00 PMfloitsch
06/08/2023, 3:01 PMfloitsch
06/08/2023, 3:02 PMjag run
it should store the snapshot with debug information in your cache directory.Shadi
06/08/2023, 3:02 PMShadi
06/08/2023, 3:03 PMfloitsch
06/08/2023, 3:04 PMjag run
?Shadi
06/08/2023, 3:04 PMfloitsch
06/08/2023, 3:04 PMjag container install
?Shadi
06/08/2023, 3:04 PMfloitsch
06/08/2023, 3:04 PMfloitsch
06/08/2023, 3:04 PMjag decode WyN...
does not work?Shadi
06/08/2023, 3:05 PMfloitsch
06/08/2023, 3:05 PMjag monitor
should do it for you.Shadi
06/08/2023, 3:06 PMfloitsch
06/08/2023, 3:06 PMfloitsch
06/08/2023, 3:06 PMfloitsch
06/08/2023, 3:06 PMShadi
06/08/2023, 3:08 PMShadi
06/08/2023, 3:17 PMShadi
06/08/2023, 3:17 PMfloitsch
06/08/2023, 3:18 PMfloitsch
06/08/2023, 3:19 PMfloitsch
06/08/2023, 3:22 PMfloitsch
06/08/2023, 3:22 PMfloitsch
06/08/2023, 3:23 PMwait_for_ready_
isn't waiting long enough.floitsch
06/08/2023, 3:24 PMShadi
06/08/2023, 3:25 PMfloitsch
06/08/2023, 3:25 PMfloitsch
06/08/2023, 3:25 PMfloitsch
06/08/2023, 3:25 PMfloitsch
06/08/2023, 3:26 PMfloitsch
06/08/2023, 3:26 PMfloitsch
06/08/2023, 3:26 PMfloitsch
06/08/2023, 3:26 PMis-data-ready
switches back to 0.floitsch
06/08/2023, 3:27 PMfloitsch
06/08/2023, 3:27 PMfloitsch
06/08/2023, 3:28 PMfloitsch
06/08/2023, 3:28 PMfloitsch
06/08/2023, 3:30 PMfloitsch
06/08/2023, 3:31 PMShadi
06/08/2023, 3:31 PMfloitsch
06/08/2023, 3:31 PMShadi
06/08/2023, 3:31 PMfloitsch
06/08/2023, 3:31 PMShadi
06/08/2023, 3:32 PMfloitsch
06/08/2023, 3:32 PMscd30.continuous_mode = false
floitsch
06/08/2023, 3:33 PMfloitsch
06/08/2023, 3:33 PMsleep --ms=5_000
or so before you can read the new measurement.Shadi
06/08/2023, 3:33 PMfloitsch
06/08/2023, 3:34 PMShadi
06/08/2023, 3:34 PMfloitsch
06/08/2023, 3:34 PMfloitsch
06/08/2023, 3:35 PMShadi
06/08/2023, 3:35 PMfloitsch
06/08/2023, 3:35 PMShadi
06/08/2023, 3:36 PMfloitsch
06/08/2023, 3:39 PMfloitsch
06/08/2023, 3:39 PMfloitsch
06/08/2023, 3:40 PMsleep
.floitsch
06/08/2023, 3:40 PMfloitsch
06/08/2023, 3:40 PMfloitsch
06/08/2023, 3:40 PMShadi
06/08/2023, 3:41 PMfloitsch
06/08/2023, 3:41 PMfloitsch
06/08/2023, 3:42 PMimport system.storage
to store a bit of information in RTC memory which survives deep sleep.
So you could store there whether you want to enable continuous mode, or whether you want to read a measurement.floitsch
06/08/2023, 3:43 PMdevice.close
?Shadi
06/08/2023, 3:43 PMfloitsch
06/08/2023, 3:44 PMfloitsch
06/08/2023, 3:45 PMfloitsch
06/08/2023, 3:46 PMShadi
06/08/2023, 3:46 PMADAFRUIT_IO_FEEDNAME_1 ::= "Humidity New"
ADAFRUIT_IO_FEEDNAME_2 ::= "Co2"
HOST ::= "io.adafruit.com"
co2_level := 0.0
main:
network := net.open
print "I am trying to connect"
transport := mqtt.TcpTransport.tls network --host=HOST
--root_certificates=[ certificate_roots.DIGICERT_GLOBAL_ROOT_CA ]
/**
// Alternatively, you can also connect without TLS, by using the
// following transport:
transport := mqtt.TcpTransport network --host=HOST
// In that case you can remove the `certificate_roots` import.
*/
client := mqtt.Client --transport=transport
options := mqtt.SessionOptions
--client_id = "toit-example-client"
--username = ADAFRUIT_IO_USERNAME
--password = ADAFRUIT_IO_KEY
client.start --options=options
print "Connected to broker"
topic_1 := "$ADAFRUIT_IO_USERNAME/feeds/$ADAFRUIT_IO_FEEDNAME_2"
topic_2 := "$ADAFRUIT_IO_USERNAME/feeds/$ADAFRUIT_IO_FEEDNAME_1"
bus := i2c.Bus
--sda=gpio.Pin 21
--scl=gpio.Pin 22
device := bus.device Scd30.I2C_ADDRESS
scd30 := Scd30 device
scd30.continuous_mode = true
sleep --ms=5000
//seconds := #[0x00, 0x10]
//command := #[0x46, 0x00] + seconds + #[scd30.compute_crc8_ seconds]
//scd30.device_.write command
while true:
reading := scd30.read
if reading.co2 > 2000:
print "Open your window: $(reading.co2.to_int)ppm"
else:
print "CO2 level is healthy: $(reading.co2.to_int)ppm"
print "Temperature: $(%.1f reading.temperature)ºC"
print "Humidity: $(%.1f reading.humidity)%"
temperature := reading.co2.to_int
client.publish topic_1 "$temperature".to_byte_array
sleep --ms=5_500
// temperature := 25
client.publish topic_2 "$temperature".to_byte_array
print "i am going to deep sleep %"
sleep --ms=5_500
scd30.continuous_mode = false
device.close
bus.close
esp32.deep_sleep (Duration --s=90)
print "I am awake"
client.close
floitsch
06/08/2023, 3:46 PMfloitsch
06/08/2023, 3:48 PMfloitsch
06/08/2023, 3:49 PMfloitsch
06/08/2023, 3:49 PMfloitsch
06/08/2023, 3:49 PMfloitsch
06/08/2023, 3:50 PMfloitsch
06/08/2023, 3:51 PMsleep --ms=5_500
to just before the esp32.deep_sleep
call. This way you already turn off the device/bus 5 seconds earlier.Shadi
06/08/2023, 3:53 PMfloitsch
06/08/2023, 3:53 PMfloitsch
06/08/2023, 3:53 PMShadi
06/08/2023, 3:53 PMShadi
06/08/2023, 3:54 PMShadi
06/08/2023, 3:54 PMfloitsch
06/08/2023, 3:54 PMfloitsch
06/08/2023, 3:54 PMScd30.continuous_mode=
.floitsch
06/08/2023, 3:55 PMShadi
06/08/2023, 3:55 PMShadi
06/08/2023, 3:56 PMShadi
06/08/2023, 3:57 PMShadi
06/08/2023, 3:57 PMfloitsch
06/08/2023, 3:57 PMfloitsch
06/08/2023, 3:57 PMcontinuous_mode = true
line to after the sleep
.Shadi
06/08/2023, 3:58 PMShadi
06/08/2023, 4:01 PMfloitsch
06/08/2023, 4:01 PMfloitsch
06/08/2023, 4:01 PMfloitsch
06/08/2023, 4:01 PMShadi
06/08/2023, 4:01 PMfloitsch
06/08/2023, 4:05 PMseconds := #[0x00, 0x02]
command := #[0x46, 0x00] + seconds + #[scd30.compute_crc8_ seconds]
scd30.device_.write command
You only need to run it once. The sensor will save it in its own memory.Shadi
06/08/2023, 4:07 PMfloitsch
06/08/2023, 4:07 PMfloitsch
06/08/2023, 4:07 PMShadi
06/08/2023, 4:08 PMShadi
06/08/2023, 4:11 PMShadi
06/08/2023, 4:11 PMShadi
06/08/2023, 4:11 PM`
device := bus.device Scd30.I2C_ADDRESS
scd30 := Scd30 device
seconds := #[0x00, 0x02]
command := #[0x46, 0x00] + seconds + #[scd30.compute_crc8_ seconds]
scd30.device_.write command
sleep --ms=5000
scd30.continuous_mode = true
floitsch
06/08/2023, 4:12 PMscd30.device_.write command
?floitsch
06/08/2023, 4:12 PMfloitsch
06/08/2023, 4:12 PMsleep --ms=5000
directly after the scd30 := Scd30 device
.Shadi
06/08/2023, 4:14 PMfloitsch
06/08/2023, 4:15 PMfloitsch
06/08/2023, 4:15 PMfloitsch
06/08/2023, 4:15 PMShadi
06/08/2023, 4:16 PMfloitsch
06/08/2023, 4:17 PMfloitsch
06/08/2023, 4:18 PMShadi
06/08/2023, 4:18 PMShadi
06/08/2023, 4:18 PMfloitsch
06/08/2023, 4:19 PMfloitsch
06/08/2023, 4:19 PMfloitsch
06/08/2023, 4:19 PMShadi
06/08/2023, 4:19 PMfloitsch
06/08/2023, 4:20 PMfloitsch
06/08/2023, 4:20 PMShadi
06/08/2023, 4:22 PMShadi
06/08/2023, 4:22 PMfloitsch
06/08/2023, 4:22 PMfloitsch
06/08/2023, 4:23 PMfloitsch
06/08/2023, 4:23 PMfloitsch
06/08/2023, 4:23 PMShadi
06/08/2023, 4:23 PM