ESP8266/BeamerControl: Unterschied zwischen den Versionen
Aus C3MAWiki
Weitere Optionen
Ollo (Diskussion | Beiträge) |
Ollo (Diskussion | Beiträge) Auf den neuen Flasher umgebaut. |
||
| Zeile 6: | Zeile 6: | ||
Es wird die [https://github.com/nodemcu/nodemcu-firmware LUA Firmware] vorausgesetzt. | Es wird die [https://github.com/nodemcu/nodemcu-firmware LUA Firmware] vorausgesetzt. | ||
Mit folgendem | Mit folgendem [[ESP8266/Programmer]] kann die folgende Initialisierungsdatei '''beamer_init.lua''' geschrieben werden: | ||
<pre> | <pre> | ||
print("Booting... Beamer v0.5") | |||
wifi.setmode(wifi.STATION) | |||
wifi.sta.config("WIFI","PASSWORD") | |||
global_c=nil | |||
function netPrint(str) | |||
if global_c~=nil then | |||
global_c:send(str) | |||
global_c:send("\n") | |||
function | end | ||
end | |||
function startTelnetServer( | function startTelnetServer(dummy) | ||
s=net.createServer(net.TCP, 180) | s=net.createServer(net.TCP, 180) | ||
s:listen(2323,function(c) | s:listen(2323,function(c) | ||
global_c=c | |||
function s_output(str) | function s_output(str) | ||
if( | if(global_c~=nil) | ||
then | then global_c:send(str) | ||
end | end | ||
end | end | ||
| Zeile 38: | Zeile 35: | ||
c:on("disconnection",function(c) | c:on("disconnection",function(c) | ||
node.output(nil) | node.output(nil) | ||
global_c=nil | |||
end) | end) | ||
print("Welcome to NodeMcu world.") | print("Welcome to NodeMcu world.") | ||
| Zeile 46: | Zeile 44: | ||
m = mqtt.Client("beamer", 120, "", "") | m = mqtt.Client("beamer", 120, "", "") | ||
function startMqttServer(c) | function startMqttServer(c) | ||
m:on("connect", function(con) print ("connected") end) | m:on("connect", function(con) print ("MQTT connected") end) | ||
m:on("offline", function(con) print ("offline") end) | m:on("offline", function(con) print ("MQTT offline") end) | ||
m:on("message", function(conn, topic, data) | m:on("message", function(conn, topic, data) | ||
netPrint(topic .. ":" ) | |||
if data ~= nil then | if data ~= nil then | ||
netPrint(topic .. ":" .. data) | |||
if data == "OFF" and topic == "/room/beamer/command" then | if data == "OFF" and topic == "/room/beamer/command" then | ||
netPrint ("Shutdown beamer") | |||
uart.write(0, "* 0 IR 002\\\r") | uart.write(0, "* 0 IR 002\\\r") | ||
end | end | ||
if data == "ON" and topic == "/room/beamer/command" then | if data == "ON" and topic == "/room/beamer/command" then | ||
netPrint ("Start Beamer") | |||
uart.write(0, "OKOKOKOKOK\\\r") | uart.write(0, "OKOKOKOKOK\\\r") | ||
end | end | ||
end | end | ||
end) | end) | ||
m:connect(" | m:connect("10.23.XXX.XXX", 1883, 0, function(conn) print("connected") end) | ||
tmr.alarm(2, 2000, 0, function() | tmr.alarm(2, 2000, 0, function() | ||
| Zeile 86: | Zeile 84: | ||
uart.setup(0,9600,8,0,1,0) | uart.setup(0,9600,8,0,1,0) | ||
-- Send all UART stuff to the debug client | |||
uart.on("data",4, function(data) | |||
if global_c~=nil then | |||
global_c:send(data) | |||
end | |||
end, 0) | |||
if | |||
</pre> | </pre> | ||
Version vom 17. April 2015, 16:44 Uhr
BeamerControl
Hardware
- ESP8266
- MAX3232
Software
Es wird die LUA Firmware vorausgesetzt.
Mit folgendem ESP8266/Programmer kann die folgende Initialisierungsdatei beamer_init.lua geschrieben werden:
print("Booting... Beamer v0.5")
wifi.setmode(wifi.STATION)
wifi.sta.config("WIFI","PASSWORD")
global_c=nil
function netPrint(str)
if global_c~=nil then
global_c:send(str)
global_c:send("\n")
end
end
function startTelnetServer(dummy)
s=net.createServer(net.TCP, 180)
s:listen(2323,function(c)
global_c=c
function s_output(str)
if(global_c~=nil)
then global_c:send(str)
end
end
node.output(s_output, 0)
c:on("receive",function(c,l)
node.input(l)
end)
c:on("disconnection",function(c)
node.output(nil)
global_c=nil
end)
print("Welcome to NodeMcu world.")
end)
print("WiFi up and running")
end
m = mqtt.Client("beamer", 120, "", "")
function startMqttServer(c)
m:on("connect", function(con) print ("MQTT connected") end)
m:on("offline", function(con) print ("MQTT offline") end)
m:on("message", function(conn, topic, data)
netPrint(topic .. ":" )
if data ~= nil then
netPrint(topic .. ":" .. data)
if data == "OFF" and topic == "/room/beamer/command" then
netPrint ("Shutdown beamer")
uart.write(0, "* 0 IR 002\\\r")
end
if data == "ON" and topic == "/room/beamer/command" then
netPrint ("Start Beamer")
uart.write(0, "OKOKOKOKOK\\\r")
end
end
end)
m:connect("10.23.XXX.XXX", 1883, 0, function(conn) print("connected") end)
tmr.alarm(2, 2000, 0, function()
m:subscribe("/room/beamer/#",0, function(conn) print("Mqtt - subscribe success") end)
end)
end
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()=="0.0.0.0" or wifi.sta.getip() == nil then
print("Connect AP, Waiting...")
else
print("Connected")
print( wifi.sta.getip() )
startTelnetServer()
startMqttServer()
tmr.stop(1)
end
end)
print("Setup UART")
uart.setup(0,9600,8,0,1,0)
-- Send all UART stuff to the debug client
uart.on("data",4, function(data)
if global_c~=nil then
global_c:send(data)
end
end, 0)
Schnittstelle
Der Beamer kann An:
mosquitto_pub -h IP1.IP2.IP3.IP4 -t "/room/beamer/command" -m "OFF"
und aus-geschalten werden:
mosquitto_pub -h IP1.IP2.IP3.IP4 -t "/room/beamer/command" -m "ON"
Hardware-Doku
-
Schaltung - Seitenansicht
-
Schaltung - Seitenansicht2
-
Schaltung - Oben
-
Schaltung - Unten
-
Alle Bauteile
-
Eingebaut