Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Luanti LED Tree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tuxilio
Luanti LED Tree
Commits
ed4672f3
Verified
Commit
ed4672f3
authored
4 months ago
by
Tuxilio
Browse files
Options
Downloads
Patches
Plain Diff
LED colors are changing on click, send to right MQTT topic
parent
e1131d5e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
init.lua
+45
-16
45 additions, 16 deletions
init.lua
with
45 additions
and
16 deletions
init.lua
+
45
−
16
View file @
ed4672f3
...
...
@@ -12,16 +12,33 @@ local data = {
password
=
"eZcKn1zBE6KtbeFnZ33lV1EKnr9Bcn8B"
,
}
local
ledCount
=
10
local
led_textures
=
{
"black"
,
"blue"
,
"cyan"
,
"gray"
,
"green"
,
"magenta"
,
"red"
,
"white"
,
"yellow"
,
}
local
led_colors
=
{}
local
active_pos
local
active_id
local
mqttBaseTopic
=
core
.
settings
:
get
(
"ledtree_base_topic"
)
or
"ledtree"
local
client
=
mqtt
.
connect
(
data
.
url
,
data
.
clientId
,
data
.
username
,
data
.
password
)
mqtt
.
subscribe
(
client
,
"ledtree/led/1"
,
function
(
topic
,
payload
)
core
.
chat_send_all
(
"Received message from topic "
..
topic
..
": "
..
payload
)
end
)
local
change_color
=
function
(
player
,
led_id
)
local
change_color
=
function
(
player
,
led_id
,
pos
)
local
pos_string
=
core
.
serialize
(
pos
)
active_pos
=
pos
active_id
=
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;green;green;false;false;]"
..
...
...
@@ -40,14 +57,23 @@ 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
=
function
(
pos
,
node
,
player
,
itemstack
,
pointed_thing
)
change_color
(
player
,
id
)
end
,
})
local
function
replace_block
(
pos
,
id
,
new_texture
)
--local node = core.get_node(pos)
local
node_name
=
"ledtree:led"
..
id
..
"_"
..
new_texture
core
.
set_node
(
pos
,
{
name
=
node_name
})
end
for
id
=
1
,
ledCount
do
led_colors
[
id
]
=
""
for
index
,
texture
in
ipairs
(
led_textures
)
do
core
.
register_node
(
"ledtree:led"
..
id
..
"_"
..
texture
,
{
description
=
"LED"
..
id
..
" "
..
texture
,
tiles
=
{
texture
..
".png"
,},
on_rightclick
=
function
(
pos
,
node
,
player
,
itemstack
,
pointed_thing
)
change_color
(
player
,
id
,
pos
)
end
,
})
end
end
core
.
register_on_player_receive_fields
(
function
(
player
,
formname
,
fields
)
...
...
@@ -76,8 +102,11 @@ core.register_on_player_receive_fields(function(player, formname, fields)
end
if
rgb
~=
""
then
core
.
chat_send_player
(
player
:
get_player_name
(),
"RGB: "
..
rgb
)
send_mqtt
(
1
,
rgb
)
core
.
chat_send_player
(
player
:
get_player_name
(),
"LED: "
..
active_id
..
" - RGB: "
..
rgb
..
" ("
..
color
..
")"
)
send_mqtt
(
active_id
,
rgb
)
replace_block
(
active_pos
,
active_id
,
color
)
core
.
close_formspec
(
player
:
get_player_name
(),
"ledtree:colorpicker"
)
end
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment