Ejemplo n.º 1
0
class NordicSerial:
    """
    This class supports definition for the Nordic Serial service over GATT
    """

    nordicService = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"
    nordicWrite = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
    nordicNotify = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
    service_uuid = UUID(nordicService)
    write_uuid = UUID(nordicWrite)
    notify_uuid = UUID(nordicNotify)
Ejemplo n.º 2
0
class KeypressSensor(SensorBase):
    svcUUID = UUID(0xFFE0)
    dataUUID = UUID(0xFFE1)

    def __init__(self, periph):
        SensorBase.__init__(self, periph)

    def enable(self):
        self.periph.writeCharacteristic(0x60, struct.pack('<bb', 0x01, 0x00))

    def disable(self):
        self.periph.writeCharacteristic(0x60, struct.pack('<bb', 0x00, 0x00))
Ejemplo n.º 3
0
class BatterySensor(SensorBase):
    svcUUID = UUID("0000180f-0000-1000-8000-00805f9b34fb")
    dataUUID = UUID("00002a19-0000-1000-8000-00805f9b34fb")
    ctrlUUID = None
    sensorOn = None

    def __init__(self, periph):
        SensorBase.__init__(self, periph)

    def read(self):
        '''Returns the battery level in percent'''
        val = ord(self.data.read())
        return val
Ejemplo n.º 4
0
class KeypressSensor(SensorBase):
    svcUUID = UUID(0xFFE0)
    dataUUID = UUID(0xFFE1)
    ctrlUUID = None
    sensorOn = None

    def __init__(self, periph):
        SensorBase.__init__(self, periph)

    def enable(self):
        SensorBase.enable(self)
        self.char_descr = self.service.getDescriptors(forUUID=0x2902)[0]
        self.char_descr.write(struct.pack('<bb', 0x01, 0x00), True)

    def disable(self):
        self.char_descr.write(struct.pack('<bb', 0x00, 0x00), True)
Ejemplo n.º 5
0
class KeypressSensor(SensorBase):
    svcUUID = UUID(0xFFE0)
    dataUUID = UUID(0xFFE1)
    ctrlUUID = None
    sensorOn = None

    def __init__(self, periph):
        SensorBase.__init__(self, periph)
 
    def enable(self):
        SensorBase.enable(self)
        # NB handle value changed between v1.4 and v1.5 firmware,
        # but is not directly discoverable by UUID. This seems to work.
        self.periph.writeCharacteristic(self.data.handle+2, struct.pack('<bb', 0x01, 0x00), True)

    def disable(self):
        self.periph.writeCharacteristic(self.data.handle+2, struct.pack('<bb', 0x00, 0x00), True)
Ejemplo n.º 6
0
def _TI_UUID(val):
    return UUID("%08X-0451-4000-b000-000000000000" % (0xF0000000 + val))
Ejemplo n.º 7
0
                                      database='smarttimersocket')
        cursor = cnx.cursor()
        #My SQL Command
        cursor.execute("SELECT * FROM `device_switch` WHERE `id`=" + deviceid)
        row = cursor.fetchone()
        cursor.close()
        cnx.close()
        return int(row[3])
    except (IOError, TypeError) as e:
        print("sqlauto IOError TypeError:" + str(e))
    except Exception as e:
        print("sqlauto Error:" + str(e))


##---------------bluetooth setting-------------------------
RX_SERVICE_UUID = UUID('6e400001-b5a3-f393-e0a9-e50e24dcca9e')
RX_CHAR_UUID = UUID('6e400003-b5a3-f393-e0a9-e50e24dcca9e')
TX_CHAR_UUID = UUID('6e400002-b5a3-f393-e0a9-e50e24dcca9e')
switch_staus = "off"

##----------------Fuzzy Setting-----------------------------#
# New Antecedent/Consequent objects hold universe variables and membership
# functions
temp = ctrl.Antecedent(np.arange(0, 41, 1), 'temp')
light = ctrl.Antecedent(np.arange(0, 11, 1), 'light')
hum = ctrl.Antecedent(np.arange(0, 81, 1), 'hum')
switch_power = ctrl.Consequent(np.arange(0, 11, 1), 'switch_power')
temp.automf(3)
light.automf(3)
hum.automf(3)
#switch_power.automf(3)
Ejemplo n.º 8
0
 def readBattery(self):
     battery_level_uuid = UUID(0x2A19)
     ch = self.connection.getCharacteristics(uuid=battery_level_uuid)[0]
     val = binascii.b2a_hex(ch.read())
     val = binascii.unhexlify(val)
     self.battery = struct.unpack('B', val)[0]
def _TI_UUID(val):
    return UUID("%08X-0451-4000-b000-000000000000" %
                (0xF0000000 + val))  #Sensor 128 but UUID