(self,tick)
| 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': |
no test coverage detected