fab-lab.eu
Published

Retro-fit #IoT to your washing machine or home appliance

Why buy a new "connected" washing machine if you can add a little like $10 and 1hr time to make it a connected one? #ESP8266 #IFTTT

IntermediateWork in progress11,503
Retro-fit #IoT to your washing machine or home appliance

Things used in this project

Hardware components

Mini Photocell
×1
Light Pipe
×1
SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
you can use also the 6$ version of Adafruit if you want to stick to the 10$ overall
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Code

init.lua

Lua
init script will be started by autostart of nodemcu, scripted in LUA language, change the SSID and passkey according to your Wifi AP, uncomment dofile ("machine.lua") if you want to autostart machine.lua after next boot
print('init.lua ver 1.2')
wifi.setmode(wifi.STATION)
print('set mode=STATION (mode='..wifi.getmode()..')')
print('MAC: ',wifi.sta.getmac())
print('chip: ',node.chipid())
print('heap: ',node.heap())
-- wifi config start
wifi.sta.config("SSID","passkey")
-- wifi config end
wifi.sta.connect()
 tmr.alarm(1, 1000, 1, function()
  if wifi.sta.getip()== nil then
  print("IP unavaiable, Waiting...")
 else
  tmr.stop(1)
 print("ESP8266 mode is: " .. wifi.getmode())
 print("The module MAC address is: " .. wifi.ap.getmac())
 print("Config done, IP is "..wifi.sta.getip())
 -- dofile ("machine.lua")
 end
end)

machine.lua

Lua
sending event to trigger IFTTT event processing in their Maker channel, replace YOURKEY with your IFTTT Maker channel key in "GET /trigger/WashDone/with/key/YOURKEY HTTP/1.1\r\n" as well "WashDone" is your Event name, this test does a time based loop ... attention you might receive a lot events ;-) added ?value1=t1 ...
port = 80
gpio.mode(1, gpio.OUTPUT)

function sendData()
  
t1=adc.read(0) -- reads value from Analog Input (max 1V)

-- conection to IFTTT channel
print("Sending data to IFTTT channel")
conn=net.createConnection(net.TCP, 0) 
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(80,'maker.ifttt.com') 

conn:on("connection", function(conn, payload) 
	print("Connected, sending event")
	   if t1 > 500 then -- sensor >500 detect status LED is on
        conn:send("GET /trigger/WashDone/with/key/YOURKEY?value1="..t1.." HTTP/1.1\r\n")
        conn:send("Host: maker.ifttt.com\r\n")
        conn:send("Accept: */*\r\n")
        conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.)\r\n")
        conn:send("\r\n")
        
        -- flash LED GPIO5 0.5 sec to indicate send
        gpio.write(1, gpio.HIGH)
             tmr.alarm(1, 500, 0, function()
                gpio.write(1, gpio.LOW)
             end)
      end
    end)

conn:on("sent",function(conn)
        print("Closing connection")
        conn:close()
    end)

conn:on("disconnection", function(conn)
        print("Got disconnection...")
    end)

end

-- send data every 10000 ms to thing speak
tmr.alarm(0, 10000, 1, function() sendData() end )

Credits

fab-lab.eu

fab-lab.eu

22 projects • 275 followers
Maker!

Comments