Compare commits
	
		
			4 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					c04197e7ae | ||
| 
						 | 
					d6a111ede7 | ||
| 
						 | 
					28a8c01a5a | ||
| 
						 | 
					71ab300339 | 
							
								
								
									
										10
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Dockerfile
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					FROM --platform=$BUILDPLATFORM python:3.10-alpine
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					WORKDIR /app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					COPY requirements.txt /app
 | 
				
			||||||
 | 
					RUN pip3 install -r requirements.txt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					COPY . /app
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CMD ["python", "main.py"]
 | 
				
			||||||
| 
						 | 
					@ -1,12 +1,11 @@
 | 
				
			||||||
# Initialise flask
 | 
					# Initialise flask
 | 
				
			||||||
from flask import Flask
 | 
					from flask import Flask
 | 
				
			||||||
app = Flask(__name__)
 | 
					app = Flask(__name__)
 | 
				
			||||||
app.config['SERVER_NAME'] = '0.0.0.0:5000'
 | 
					 | 
				
			||||||
app.config.from_prefixed_env()
 | 
					app.config.from_prefixed_env()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Initialise the bluetooth stack
 | 
					# Initialise the bluetooth stack
 | 
				
			||||||
from bluewind import headwind
 | 
					from bluewind import headwind
 | 
				
			||||||
fan = headwind.Headwind(app, app.config["ADDRESS"])
 | 
					fan = headwind.Headwind(app.config["ADDRESS"])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Load the views
 | 
					# Load the views
 | 
				
			||||||
from bluewind import views
 | 
					from bluewind import views
 | 
				
			||||||
| 
						 | 
					@ -15,15 +15,12 @@ CHARACTERISTIC = "a026e038-0a7d-4ab3-97fa-f1500f9feb8b"
 | 
				
			||||||
# > bytearray(b'\xfd\x01\x00\x01')
 | 
					# > bytearray(b'\xfd\x01\x00\x01')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Headwind:
 | 
					class Headwind:
 | 
				
			||||||
    fanClient = None
 | 
					    def __init__(self, address):
 | 
				
			||||||
    flaskApp = None
 | 
					        self.address = address
 | 
				
			||||||
    def __init__(self, flaskApp, address):
 | 
					 | 
				
			||||||
        self.flaskApp = flaskApp
 | 
					 | 
				
			||||||
        self.fanClient = BleakClient(address)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def readSpeed(self):
 | 
					    async def readSpeed(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            async with self.fanClient as client:
 | 
					            async with BleakClient(self.address) as client:
 | 
				
			||||||
                result = await client.read_gatt_char(CHARACTERISTIC)
 | 
					                result = await client.read_gatt_char(CHARACTERISTIC)
 | 
				
			||||||
                return result[2]
 | 
					                return result[2]
 | 
				
			||||||
        except Exception:
 | 
					        except Exception:
 | 
				
			||||||
| 
						 | 
					@ -31,7 +28,7 @@ class Headwind:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def readMode(self):
 | 
					    async def readMode(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            async with self.fanClient as client:
 | 
					            async with BleakClient(self.address) as client:
 | 
				
			||||||
                result = await client.read_gatt_char(CHARACTERISTIC)
 | 
					                result = await client.read_gatt_char(CHARACTERISTIC)
 | 
				
			||||||
                return result[3] # Return state code, needs to figure out what each code means
 | 
					                return result[3] # Return state code, needs to figure out what each code means
 | 
				
			||||||
        except Exception:
 | 
					        except Exception:
 | 
				
			||||||
| 
						 | 
					@ -39,32 +36,32 @@ class Headwind:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def writeSleep(self):
 | 
					    async def writeSleep(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            async with self.fanClient as client:
 | 
					            async with BleakClient(self.address) as client:
 | 
				
			||||||
                await client.write_gatt_char(CHARACTERISTIC, SLEEP)
 | 
					                await client.write_gatt_char(CHARACTERISTIC, SLEEP, response=False)
 | 
				
			||||||
                return True
 | 
					                return True
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    async def writeOn(self):
 | 
					    async def writeOn(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            async with self.fanClient as client:
 | 
					            async with BleakClient(self.address) as client:
 | 
				
			||||||
                await client.write_gatt_char(CHARACTERISTIC, ON)
 | 
					                await client.write_gatt_char(CHARACTERISTIC, ON, response=False)
 | 
				
			||||||
                return True
 | 
					                return True
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def writeSpeedMode(self):
 | 
					    async def writeSpeedMode(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            async with self.fanClient as client:
 | 
					            async with BleakClient(self.address) as client:
 | 
				
			||||||
                await client.write_gatt_char(CHARACTERISTIC, SPD)
 | 
					                await client.write_gatt_char(CHARACTERISTIC, SPD, response=False)
 | 
				
			||||||
                return True
 | 
					                return True
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def writeHrMode(self):
 | 
					    async def writeHrMode(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            async with self.fanClient as client:
 | 
					            async with BleakClient(self.address) as client:
 | 
				
			||||||
                await client.write_gatt_char(CHARACTERISTIC, HR)
 | 
					                await client.write_gatt_char(CHARACTERISTIC, HR, response=False)
 | 
				
			||||||
                return True
 | 
					                return True
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
| 
						 | 
					@ -73,8 +70,8 @@ class Headwind:
 | 
				
			||||||
        if speed > 0:
 | 
					        if speed > 0:
 | 
				
			||||||
            value = [0x2, speed]
 | 
					            value = [0x2, speed]
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                async with self.fanClient as client:
 | 
					                async with BleakClient(self.address) as client:
 | 
				
			||||||
                    await client.write_gatt_char(CHARACTERISTIC, value)
 | 
					                    await client.write_gatt_char(CHARACTERISTIC, value, response=False)
 | 
				
			||||||
                    return True
 | 
					                    return True
 | 
				
			||||||
            except Exception as e:
 | 
					            except Exception as e:
 | 
				
			||||||
                return False
 | 
					                return False
 | 
				
			||||||
| 
						 | 
					@ -82,8 +79,8 @@ class Headwind:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def writeOff(self):
 | 
					    async def writeOff(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            async with self.fanClient as client:
 | 
					            async with BleakClient(self.address) as client:
 | 
				
			||||||
                await client.write_gatt_char(CHARACTERISTIC, OFF)
 | 
					                await client.write_gatt_char(CHARACTERISTIC, OFF, response=False)
 | 
				
			||||||
                return True
 | 
					                return True
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
| 
						 | 
					@ -24,7 +24,6 @@ async def setSpeed(speed):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.route("/speed/increase", methods=["POST"])
 | 
					@app.route("/speed/increase", methods=["POST"])
 | 
				
			||||||
async def setIncreaseSpeed():
 | 
					async def setIncreaseSpeed():
 | 
				
			||||||
    print("increase speed")
 | 
					 | 
				
			||||||
    currentSpeed = await fan.readSpeed()
 | 
					    currentSpeed = await fan.readSpeed()
 | 
				
			||||||
    newSpeed = 0
 | 
					    newSpeed = 0
 | 
				
			||||||
    if currentSpeed < 25:
 | 
					    if currentSpeed < 25:
 | 
				
			||||||
| 
						 | 
					@ -42,7 +41,6 @@ async def setIncreaseSpeed():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.route("/speed/decrease", methods=["POST"])
 | 
					@app.route("/speed/decrease", methods=["POST"])
 | 
				
			||||||
async def setDecreaseSpeed():
 | 
					async def setDecreaseSpeed():
 | 
				
			||||||
    print("decrease speed")
 | 
					 | 
				
			||||||
    currentSpeed = await fan.readSpeed()
 | 
					    currentSpeed = await fan.readSpeed()
 | 
				
			||||||
    newSpeed = 0
 | 
					    newSpeed = 0
 | 
				
			||||||
    if currentSpeed == 100:
 | 
					    if currentSpeed == 100:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,2 +1 @@
 | 
				
			||||||
FLASK_ADDRESS='F2:B3:F7:6A:24:48'
 | 
					FLASK_ADDRESS='F2:B3:F7:6A:24:48'
 | 
				
			||||||
FLASK_URL='127.0.0.1:5000'
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user