Esempio n. 1
0
    def _processADRRequests(self):
        """Updates devices with target data rate, and sends ADR requests.
        
        This method is called every adrcycletime seconds as a looping task.
        
        """
        # If we are running, return
        if self.adrprocessing is True:
            returnValue(None)

        self.adrprocessing = True

        devices = yield Device.all()
        sendtime = time.time()

        for device in devices:
            # Check this device is enabled
            if not device.enabled:
                continue

            # Check ADR is enabled
            if not device.adr:
                continue

            # Set the target data rate
            target = device.getADRDatarate(self.band, self.config.adrmargin)

            # If no target, or the current data rate is the target, continue
            if target is None:
                continue

            # Set the device adr_datr
            yield device.update(adr_datr=target)

            # Only send a request if we need to change
            if device.tx_datr == device.adr_datr:
                continue

            # If we are queueing commands, create the command and add to the queue.
            # Replace any existing requests.
            if self.config.macqueueing:
                log.info("Queuing ADR MAC Command")
                command = self._createLinkADRRequest(device)
                self._dequeueMACCommand(device.deveui, command)
                self._queueMACCommand(device.deveui, command)
                continue

            # Check we have reached the next scheduled ADR message time
            scheduled = sendtime + self.config.adrmessagetime
            current = time.time()
            if current < scheduled:
                yield txsleep(scheduled - current)

            # Refresh and send the LinkADRRequest
            sendtime = time.time()
            yield self._sendLinkADRRequest(device)

        self.adrprocessing = False
Esempio n. 2
0
 def get(self):
     """Method to get all devices"""
     try:
         devices = yield Device.all()
         if devices is None:
             returnValue({})
         data = {}
         for i,d in enumerate(devices):
             data[i] = marshal(d, self.fields)
         returnValue(data)
         
     except TimeoutError:
         # Exception returns 500 to client
         log.error("REST API timeout retrieving all devices")