Skip to content
Snippets Groups Projects
Verified Commit 8ba15919 authored by Tuxilio's avatar Tuxilio
Browse files

First working version

parent de5d5410
No related branches found
No related tags found
No related merge requests found
# Luanti LED Tree
You have to add the mod to the trusted mods in minetest.conf:
secure.http_mods = ledtree
......@@ -2,40 +2,79 @@
--
-- SPDX-License-Identifier: GPL-3.0-or-later
local HTTPApiTable = core.request_http_api()
local modname = core.get_current_modname()
local modpath = core.get_modpath(modname)
local data = {
url = "https://mqtt.felix-zauberer.de:443",
url = "mqtt.felix-zauberer.de",
clientId = "ledtree_luanti",
username = "kalle1",
token = "eZcKn1zBE6KtbeFnZ33lV1EKnr9Bcn8B",
password = "eZcKn1zBE6KtbeFnZ33lV1EKnr9Bcn8B",
}
change_color = function(led_id)
local request = {
url = data.url,
method = 'POST',
timeout = 15,
username = data.username,
clientId = data.clientId,
extra_headers = {
"Authorization: Bearer "..data.token,
}
}
HTTPApiTable.fetch(request, function(response)
print(dump(request))
if response.code ~= 200 then
return false
else
return true
end
end)
local mqttBaseTopic = core.settings:get("ledtree_base_topic") or "ledtree"
local client = mqtt.connect(data.url, data.clientId, data.username, data.password)
local change_color = function(player, led_id)
local formspec = "size[3,3]" ..
"image_button[0,0;1,1;red.png;red;red;false;false;]" ..
"image_button[1,0;1,1;green.png;gren;green;false;false;]" ..
"image_button[2,0;1,1;blue.png;blue;blue;false;false;]" ..
"image_button[0,1;1,1;yellow.png;yellow;yellow;false;false;]" ..
"image_button[1,1;1,1;cyan.png;cyan;cyan;false;false;]" ..
"image_button[2,1;1,1;magenta.png;magenta;magenta;false;false;]" ..
"image_button[0,2;1,1;white.png;white;white;false;false;]" ..
"image_button[1,2;1,1;black.png;black;black;false;false;]" ..
"image_button[2,2;1,1;gray.png;gray;gray;false;false;]"
core.show_formspec(player:get_player_name(), "ledtree:colorpicker", formspec)
end
local function send_mqtt(id, rgb)
mqtt.publish(client, mqttBaseTopic.."/led/"..id, "["..rgb.."]")
end
for id=1, 10, 1 do
core.register_node("ledtree:led"..id, {
description = "LED"..id,
--tiles = "",
on_rightclick = change_color(id),
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
change_color(player, id)
end,
})
end
core.register_on_player_receive_fields(function(player, formname, fields)
if formname == "ledtree:colorpicker" then
for color, _ in pairs(fields) do
if color then
local rgb = ""
if color == "red" then
rgb = "255,0,0"
elseif color == "green" then
rgb = "0,255,0"
elseif color == "blue" then
rgb = "0,0,255"
elseif color == "yellow" then
rgb = "255,255,0"
elseif color == "cyan" then
rgb = "0,255,255"
elseif color == "magenta" then
rgb = "255,0,255"
elseif color == "white" then
rgb = "255,255,255"
elseif color == "black" then
rgb = "0,0,0"
elseif color == "gray" then
rgb = "128,128,128"
end
if rgb ~= "" then
core.chat_send_player(player:get_player_name(), "RGB: " .. rgb)
send_mqtt(1, rgb)
end
end
end
end
end)
name = ledtree
title = Teckids LED-Weihnachtsbaum
description = Teckids LED-Weihnachtsbaum
depends = mqtt
author = Tuxilio <mail@tuxil.io>
ledtree_base_topic (Base topic (e.g. /[base_topic]/led/1)) string ledtree
textures/black.png

550 B

textures/blue.png

560 B

textures/cyan.png

560 B

textures/gray.png

560 B

textures/green.png

558 B

textures/magenta.png

560 B

textures/red.png

556 B

textures/white.png

560 B

textures/yellow.png

558 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment