LightBus/LuaServer

Aus Wiki CCC Göttingen
Zur Navigation springen Zur Suche springen

Zugriff

Der Server ist (zur Zeit) auf brickme.nok.lab im Neotopia-Netzwerk auf TCP Port 1167 erreichbar.

Man kann ihm Lua-Code schicken, der dann ausgeführt wird (jajaja, unsicher, blablabla, aber lustig).

Der Effekt-Server ruft 100x pro Sekunde seinen "Effekt-Stack" auf, auf dem Effekt-Funktionen liegen, die ihm mit dem API-Aufruf api:effect_add(...) hinzugefügt worden sind. Diese Effekt-Funktionen werden in der Reihenfolge ihrer Priorität (aufsteigend) aufgerufen und setzen den Zustand der LEDs.

Dokumentation der Lua-API

    LBUS: busmaster: host: example network effect server
    
    This implements an effect server (srv.lua) which listens on TCP
    port 1167 and waits for Lua code there. An API is presented that
    allows to send animation functions (effects) to the server which
    it will then run.
    
    Uses LJSyscall for implementing the server functionality.
    
    API is accessible for the functions in the "api" variable. It
    offers the following methods:
    
    api:set(x, y, r, g, b, alpha)
      set Pixel at x, y to the values r, g, b using alpha value
    
    api:effect_list()
      return a list of currently loaded/active effects
    
    api:effect_add(prio, name, effect)
      add an effect
      effect is a function:
        function(time, data)
      when called by the server in distinct intervals, time is the
      current time (in seconds), data is a table containing data
      that can be configured at runtime (see api:effect_set())
    
    api:effect_del(name)
      remove an effect
    
    api:effect_set(name, data_name, value)
      set an effect's data_name value

Siehe zur Implementation https://github.com/hwhw/stm32-projects/blob/master/lbus_usb_master/host_tools/luajit/srv.lua

Beispiele für Lua-Code, den man an den Server schicken kann, finden sich hier: https://github.com/hwhw/stm32-projects/tree/master/lbus_usb_master/host_tools/luajit/srv_effects

Beispiel für Script-Aufruf

Einzelner API-Call von der Kommandozeile:

  $ echo 'api:effect_list()' | netcat brickme 1167

Einen Effekt (oder eine größere andere Menge Lua-Code) aus einer Datei laden:

  $ cat red_alert.lua | netcat brickme 1167

Laufzeit-Parameter eines Effekts setzen:

  $ echo 'api:effect_set("red_alert", "active", true)' | netcat brickme 1167