2016. április 10., vasárnap

AutomaTales - Switching the Lamp (a LED)

Going further. This is just a copy-paste programming.
I grabbed the Arduino code from here:
http://iot-playground.com/blog/2-uncategorised/40-esp8266-wifi-relay-switch-arduino-ide

Changed the SSID and the password, connected a 150ohm resistor and the first LED I found in my junk box to the corresponding pins of the ESP8266. Downloaded the code, and fired the serial monitor in the Visual Studio:


When I connect to the web server from a browser, I can switch the LED on and off.

Now integrate it to the OpenHAB.
We don't need anything else just modify the previously created rules. First I just added the http calls into the previously created rule, but the result wasn't satisfactory. I was able to control the LED from the remote, but not from the web browser. So I modified it a bit more.

Here is the result:
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*

rule "GarageLightRemote"
when
    Item KeeLoq_Remote_B changed from CLOSED to OPEN
then
    if(Garage_Light.state == ON)
    {
        sendCommand(Garage_Light, OFF)
    }
    else
    {
        sendCommand(Garage_Light, ON)
    }
end

rule "GarageLightOffAction"
when
    Item Garage_Light changed from ON to OFF
then
        sendHttpGetRequest("http://10.1.2.129/gpio/0")
end

rule "GarageLightOffAction"
when
    Item Garage_Light changed from OFF to ON
then
        sendHttpGetRequest("http://10.1.2.129/gpio/1") 
end
Here is the circuit:

Nincsenek megjegyzések:

Megjegyzés küldése