MCPcopy Create free account
hub / github.com/antirez/freakwan / exec_state_machine

Method exec_state_machine

sensor.py:32–56  ·  view source on GitHub ↗
(self,tick)

Source from the content-addressed store, hash-verified

30 # execute the sensor state machine, that is: send sample, wait
31 # for reply for some time, then go in deep sleep.
32 def exec_state_machine(self,tick):
33 # Send sensor data. After this step, there should be a pending
34 # message in the TX queue, with the encoded readings of the
35 # sensor.
36 if self.state == "send_sample":
37 print("[sensor] sending sample")
38 self.send_sample()
39 self.state = "wait_tx"
40
41 # Once the TX queue is empty, we will wait a bit more in order
42 # to receive some data: then we will shut down and enter
43 # in deep sleep.
44 if self.state == "wait_tx":
45 if len(self.fw.send_queue) == 0:
46 print("[sensor] data sent (tx queue is empty)")
47 # Give it 10 seconds to receive some reply.
48 self.poweroff_tick = tick + 100
49 self.state = "wait_poweroff"
50
51 # Finally shut down if we sent the message and the time to
52 # receive some command elapsed.
53 if self.state == "wait_poweroff":
54 if tick == self.poweroff_tick:
55 print("[sensor] entering deep sleep")
56 self.fw.power_off(self.config['period'])
57
58 def send_sample(self):
59 if self.config['type'] == 'DHT22':

Callers 1

cronMethod · 0.80

Calls 2

send_sampleMethod · 0.95
power_offMethod · 0.80

Tested by

no test coverage detected