Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
LED of things: control led with pushetta
Browse files Browse the repository at this point in the history
  • Loading branch information
karonth committed Jun 17, 2015
1 parent 301ca61 commit 4ff6469
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
59 changes: 59 additions & 0 deletions esp8266/colorneoled/Pushetta MQTT.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@


BROKER = "iot.pushetta.com"

BRPORT = 1883
BRUSER = "459bd6735bb43a0877219deca123a0d48c30e9d0"
BRPWD = "pushetta"
CLIENTID = "ESP8266-" .. node.chipid()


m = mqtt.Client( CLIENTID, 120, BRUSER, BRPWD)

m:on("message", function(conn, topic, data)

if data ~= nil then
-- print(data)


i=1
a={}
for token in string.gmatch(data, "[^%s]+") do
a[i]=token
print(a[i])
i=i+1
end

if a[1]=="colorlamp" then
--colorchngled 100,200,100 (<255)
colorchngled(3, 30,a[2],a[3],a[4])

elseif a[1]=="colorneoled" then
--colorneoled 100,200,100 (<255)
colorneoled(3, 30,a[2],a[3],a[4])


elseif a[1]=="gettemp" then
-- tmr.wdclr()
-- local a=(dofile("dht22.lua").read(1))

print(a)
pushetta("espmqtt_ret", a)


elseif a[1]=="led" then
led(a[2],a[3],a[4])


else pushetta("espmqtt_ret", a[1])
end

end
end)


m:connect( BROKER , BRPORT, 0, function(conn)

-- subscribe topic with qos = 0
m:subscribe("/pushetta.com/channels/espmqtt",0, function(conn) print("subscribe success") end)
end)
11 changes: 11 additions & 0 deletions esp8266/colorneoled/colorneoled.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
gpio.mode(3, gpio.OUTPUT)
gpio.write(3, gpio.LOW)
ws2812.writergb(3, string.char(0, 0, 0):rep(30))

function colorneoled(gpio, nleds, color1, color2, color3)

a=string.char(color1)..string.char(color2)..string.char(color3)
ws2812.writergb(gpio, a:rep(nleds))

end

51 changes: 51 additions & 0 deletions esp8266/colorneoled/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
wifi.setmode(wifi.STATION)
--wifi.sta.config("FABLAB_TORINO","FablabTorino")
wifi.sta.config("FASTWEB-1-ddufVHRPqndR","0123456789")
dofile("colorneoled.lua")
--dofile("led rgb.lua")
print("1")
-- tmr.alarm(3,20000,1, function()
-- a=(dofile("dht22.lua").read(4))
-- print(a)
-- end)
print("2")
dofile("pushetta.lua")
print("3")

function connected(conn)
print("Wifi console connected.")
function s_output(str)
if (conn~=nil) then
conn:send(str)
end
end
node.output(s_output,0)
conn:on("receive", function(conn, pl)
node.input(pl)
end)
conn:on("disconnection",function(conn)
node.output(nil)
end)
print("Welcome to NodeMcu world.")
end
function startServer()

sv=net.createServer(net.TCP, 180)
sv:listen(2323, connected)
print("Telnet Server running at :2323")
print("===Now, logon and input LUA.====")
end
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()==nil then
print("Connect AP, Waiting...")
else
print("Wifi AP connected. Wicon IP:")
print(wifi.sta.getip())
-- startServer()
dofile("Pushetta MQTT.lua")
tmr.stop(1)
end
end)



16 changes: 16 additions & 0 deletions esp8266/colorneoled/pushetta.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function pushetta(destin, text)
--len=tostring(43+string.len(text))
len1="80"
sk=net.createConnection(net.TCP, 0)
sk:on("receive", function(sck, c) print(c) end )
sk:connect(80,"149.210.164.152")
sk:send("POST /api/pushes/".. destin.."/ HTTP/1.1\r\nUser-Agent: test/1.0.0\r\nHost: api.pushetta.com\r\nAccept: */*\r\nAuthorization: Token 459bd6735bb43a0877219deca123a0d48c30e9d0\r\nContent-Type: application/json\r\nContent-Length: 73\r\n\r\n")
sk:send("{\"body\": \""..text.."\", \"message_type\": \"plain/text\"}\r\n\r\n")
end



-- pushetta("espmqtt_ret", dofile("dht22.lua").read(1))


-- pushetta("espmqtt_ret", "coco")

0 comments on commit 4ff6469

Please sign in to comment.