lua exaples

hi,
are there examples awailable how to write lua modules for repetier server? maybe on github?

Comments

  • No, but here a sample that makes a led blink and shuts down pi on button press

    rs = RepetierServer()

    local GPIO = periphery.GPIO


    local loopCounter = 0

    local blink = false

    local blinkOn = true

    local lastButton = true

    local gpioBlink = nil

    local gpioButton = nil


    function setup()

      print("lua setup called")

      gpioBlink = GPIO(3, "out")

      gpioButton = GPIO(2, "in")

      print("lua setup finsihed")

    end



    function loop()

      print("loop")

      loopCounter = loopCounter + 1

      if lastButton ~= gpioButton:read() then

        lastButton = not lastButton

        print("Button " .. tostring(lastButton))

        if lastButton then

          blinkOn = not blinkOn

          os.execute("sudo /sbin/shutdown -h now")

        end

      end

      if loopCounter >= 100 then

        loopCounter = 0

        if blinkOn then

          blink = not blink

          gpioBlink:write(blink)

          print("Blink:" .. tostring(blink))

        end

      end

    end


    Also a snippet to send a gcode(M119)  to all printers being active:

    function sendM119()
      pList = rs.printerList
      for _,printer in pairs(pList) do
        if printer.activated then
          printer:injectManualCommand("M119")
        end
      end
    end

    Watch out with shutdown example - a small error there will shutdown pi as soon as server starts!
    Just copy the lua script to  /var/lib/Repetier-Server/lua and restart server. Watch server.log as script errors and print commands get written there. So that is your main point in finding errors in scripts.
Sign In or Register to comment.