Hey guys
I want to use my Alexa to control my fan, I did the following example, Alexa can't find my device, here is the excerpt from my start program, thank you in advance
I want to use my Alexa to control my fan, I did the following example, Alexa can't find my device, here is the excerpt from my start program, thank you in advance
B4R:
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
timer1.Initialize("timer1_Tick",2000)
Timer2.Initialize("Stats",1000)
onewire.Initialize(ESPin.D4)'Pino D4 DS18B20
PinGPIO05.Initialize(d1.D1,PinGPIO05.MODE_OUTPUT)'Pino D1 Triac1
PinGPIO04.Initialize(d1.D2,PinGPIO04.MODE_OUTPUT)'Pino D2 Triac2
PinGPIO13.Initialize(d1.D7,PinGPIO13.MODE_OUTPUT)'Pino D7 Buzzer
PinGPIO14.Initialize(d1.D5,PinGPIO14.MODE_OUTPUT)'Pino D5 Triac1
PinGPIO16.Initialize(d1.D0,PinGPIO16.MODE_OUTPUT)'Pino D16 Led
'Set Desligar Pinos ESP
PinGPIO05.DigitalWrite(False)
PinGPIO04.DigitalWrite(False)
PinGPIO14.DigitalWrite(False)
PinGPIO16.DigitalWrite(False)
PinGPIO13.DigitalWrite(True)
Delay(200)
PinGPIO13.DigitalWrite(False)
alexa.Initialize("DeviceChanged")
Timer3.Initialize("LoopRun",1)
Timer3.Enabled = True
alexa.addDevice("ventilador auto",0)
alexa.addDevice("ventilador normal",1)
alexa.addDevice("ventilador baixo",2)
alexa.addDevice("Temporizador 1 hora",3)
SetRelay(0)
SetRelay(1)
SetRelay(2)
' SetRelay(3)
' SetRelay(4)
' SetRelay(5)
' SetRelay(6)
' SetRelay(7)
WiFiServer.Start
ConnectToNetwork(0)
End Sub
Sub LoopRun
alexa.RunLoop
time = time + 1
If time = 90000 Then
time = 0
Log("loop running")
Log("memory=", AvailableRAM,"stack :",StackBufferUsage)
End If
End Sub
Sub DeviceChanged(index As Byte)
'unique callback for all device, callback is done with device number
Log("deviceindex=",index,"deviceName=",alexa.getName(index))
Select Case index
Case 0
If alexa.getValue(0) = 0 Then
PinGPIO05.DigitalWrite(True)
PinGPIO13.DigitalWrite(True)
Delay(200)
PinGPIO13.DigitalWrite(False)
RS1 = (True)
If State = False Then
SaveRelay(0,1)
Else
SaveRelay(0,0)
End If
Else
PinGPIO05.DigitalWrite(False)
PinGPIO13.DigitalWrite(True)
Delay(200)
PinGPIO13.DigitalWrite(False)
RS1 = (False)
If State = False Then
SaveRelay(0,1)
Else
SaveRelay(0,0)
End If
End If
Case 1
If alexa.getValue(1) = 0 Then
PinGPIO04.DigitalWrite(True)
PinGPIO13.DigitalWrite(True)
Delay(200)
PinGPIO13.DigitalWrite(False)
RS2 = (True)
If State = False Then
SaveRelay(1,1)
Else
SaveRelay(1,0)
End If
Else
PinGPIO04.DigitalWrite(False)
PinGPIO13.DigitalWrite(True)
Delay(200)
PinGPIO13.DigitalWrite(False)
RS2 = (False)
If State = False Then
SaveRelay(1,1)
Else
SaveRelay(1,0)
End If
End If
Case 2
If alexa.getValue(2) = 0 Then
PinGPIO14.DigitalWrite(True)
PinGPIO13.DigitalWrite(True)
Delay(200)
PinGPIO13.DigitalWrite(False)
RS3 = (True)
If State = False Then
SaveRelay(2,1)
Else
SaveRelay(2,0)
End If
Else
PinGPIO14.DigitalWrite(False)
PinGPIO13.DigitalWrite(True)
Delay(200)
PinGPIO13.DigitalWrite(False)
RS3 = (False)
If State = False Then
SaveRelay(2,1)
Else
SaveRelay(2,0)
End If
End If
End Select
End Sub