ESP8266/BeamerControl: Unterschied zwischen den Versionen

Aus C3MAWiki
Zur Navigation springenZur Suche springen
(Schnittstelle)
Zeile 107: Zeile 107:
und '''aus'''-geschalten werden:
und '''aus'''-geschalten werden:
  mosquitto_pub -h IP1.IP2.IP3.IP4 -t "/room/beamer/command" -m "ON"
  mosquitto_pub -h IP1.IP2.IP3.IP4 -t "/room/beamer/command" -m "ON"
== Hardware-Doku ==
<gallery>
Datei:leinwandcontroller.jpg | Orginal Mikrocontoller
Datei:IMG_20150411_000306.jpg | Schaltung - Seitenansicht
Datei:IMG_20150411_000325.jpg | Schaltung - Seitenansicht2
Datei:IMG_20150411_000256.jpg | Schaltung - Oben
Datei:IMG_20150411_000315.jpg | Schaltung - Unten
Datei:IMG_20150411_000353.jpg | Alle Bauteile
Datei:IMG_20150411_001054.jpg | Eingebaut
</gallery>

Version vom 11. April 2015, 00:41 Uhr

BeamerControl

Hardware

  • ESP8266
  • MAX3232

Software

Es wird die LUA Firmware vorausgesetzt.

Mit folgendem Bash-Skript kann die Initialisierungsdatei geschrieben werden.


#!/bin/bash

DEVICE=/dev/ttyUSB0
SLEEPTIME=0.2

function init() {

echo "Flashing the Initialization"

echo 'file.open("init.lua","w")' >> $DEVICE; sleep $SLEEPTIME
cat <<'EOF' | while read a; do echo "file.writeline([[${a}]])" >> $DEVICE; echo "$a"; sleep $SLEEPTIME; done
print("Booting...")
wifi.setmode(wifi.STATION)
wifi.sta.config("WLAN","passwort")

function startTelnetServer(c)
	s=net.createServer(net.TCP, 180)
	s:listen(2323,function(c)
	function s_output(str)
	  if(c~=nil)
	     then 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)
	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 ("connected") end)
	m:on("offline", function(con) print ("offline") end)

	m:on("message", function(conn, topic, data)
	  print(topic .. ":" )
	  if data ~= nil then
	    print(data)
	    if data == "OFF" and topic == "/room/beamer/command" then
		print ("Shutdown beamer")
		uart.write(0, "* 0 IR 002\\\r")
	    end
            if data == "ON" and topic == "/room/beamer/command" then
		print ("Start Beamer")
		uart.write(0, "OKOKOKOKOK\\\r")
	    end
	  end
	end)
        m:connect("IP1.IP2.IP3.IP4", 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)

EOF
# Close the init file
echo "file.close()" >> $DEVICE; sleep $SLEEPTIME

echo "========================="
echo "now login on ESP and call"
echo "node.restart()"

}

if [ "$EUID" -ne 0 ]
  then echo "Please run as root"
  exit
fi

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