118 | | This call is blocking. We now have a process (Device) running, listening to the bus. The Datapoints, through their respective Group Objects, will react to requests on the Group Addresses their are weaved to ("1/1/1" and "1/1/2"). According to the flags, they will transmit their internal value on a Read request, or if this value changes. |
| 117 | This call is blocking, and launch the framework main loop. |
| 118 | |
| 119 | We now have a process (Device) running, listening to the bus. The Datapoints, through their respective Group Objects, will react to requests on the Group Addresses their are weaved to ("1/1/1" and "1/1/2"). According to the flags, they will transmit their internal value on a Read request, or if this value changes. |
159 | | All we do, here, is adding a method periodically called by the framework (every 5 minutes in the above example). In this method, we retreive the temperature and humidity values (not explained here), and give the value to the respective Datapoints. If the value has changed from the previous call, the Datapoint will automagically transmit it to the bus (according to the flags, of course). |
| 161 | We have just imported and instanciated an additionnal object: |
| 162 | |
| 163 | {{{ |
| 164 | #!python |
| 165 | from pknyx.api import Scheduler |
| 166 | |
| 167 | |
| 168 | schedule = Scheduler() |
| 169 | }}} |
| 170 | |
| 171 | We have also defined a method which role is to update the temperature and humidity Datapoints values: |
| 172 | |
| 173 | {{{ |
| 174 | #!python |
| 175 | @schedule.every(minute=5) |
| 176 | def updateTemperaturHumidity(self, event): |
| 177 | |
| 178 | # How we retreive the temperature/humidity is out of the scope of this proposal |
| 179 | # temperature = xxx |
| 180 | # humidity = xxx |
| 181 | self.dp["temperature"] = temperature |
| 182 | self.dp["humidity"] = humidity |
| 183 | }}} |
| 184 | |
| 185 | Note how this method is periodically called, using the {{{schedule.every()}}} method as python decorator. This decorator will automatically register our method and call it every 5 minutes. |
| 186 | |
| 187 | In our method, we retreive the temperature and humidity values (not explained here), and give the value to the respective Datapoints. If the value has changed from the previous call, the Datapoint will automagically transmit it to the bus (according to the flags, of course). |