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 = {
...
@@ -12,16 +12,33 @@ local data = {
password
=
"eZcKn1zBE6KtbeFnZ33lV1EKnr9Bcn8B"
,
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
mqttBaseTopic
=
core
.
settings
:
get
(
"ledtree_base_topic"
)
or
"ledtree"
local
client
=
mqtt
.
connect
(
data
.
url
,
data
.
clientId
,
data
.
username
,
data
.
password
)
local
client
=
mqtt
.
connect
(
data
.
url
,
data
.
clientId
,
data
.
username
,
data
.
password
)
mqtt
.
subscribe
(
client
,
"ledtree/led/1"
,
function
(
topic
,
payload
)
local
change_color
=
function
(
player
,
led_id
,
pos
)
core
.
chat_send_all
(
"Received message from topic "
..
topic
..
": "
..
payload
)
local
pos_string
=
core
.
serialize
(
pos
)
end
active_pos
=
pos
)
active_id
=
led_id
local
change_color
=
function
(
player
,
led_id
)
local
formspec
=
"size[3,3]"
..
local
formspec
=
"size[3,3]"
..
"image_button[0,0;1,1;red.png;red;red;false;false;]"
..
"image_button[0,0;1,1;red.png;red;red;false;false;]"
..
"image_button[1,0;1,1;green.png;green;green;false;false;]"
..
"image_button[1,0;1,1;green.png;green;green;false;false;]"
..
...
@@ -40,14 +57,23 @@ local function send_mqtt(id, rgb)
...
@@ -40,14 +57,23 @@ local function send_mqtt(id, rgb)
mqtt
.
publish
(
client
,
mqttBaseTopic
..
"/led/"
..
id
,
"["
..
rgb
..
"]"
)
mqtt
.
publish
(
client
,
mqttBaseTopic
..
"/led/"
..
id
,
"["
..
rgb
..
"]"
)
end
end
for
id
=
1
,
10
,
1
do
local
function
replace_block
(
pos
,
id
,
new_texture
)
core
.
register_node
(
"ledtree:led"
..
id
,
{
--local node = core.get_node(pos)
description
=
"LED"
..
id
,
local
node_name
=
"ledtree:led"
..
id
..
"_"
..
new_texture
--tiles = "",
core
.
set_node
(
pos
,
{
name
=
node_name
})
on_rightclick
=
function
(
pos
,
node
,
player
,
itemstack
,
pointed_thing
)
end
change_color
(
player
,
id
)
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
end
core
.
register_on_player_receive_fields
(
function
(
player
,
formname
,
fields
)
core
.
register_on_player_receive_fields
(
function
(
player
,
formname
,
fields
)
...
@@ -76,8 +102,11 @@ 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
end
if
rgb
~=
""
then
if
rgb
~=
""
then
core
.
chat_send_player
(
player
:
get_player_name
(),
"RGB: "
..
rgb
)
core
.
chat_send_player
(
player
:
get_player_name
(),
"LED: "
..
active_id
..
" - RGB: "
..
rgb
..
" ("
..
color
..
")"
)
send_mqtt
(
1
,
rgb
)
send_mqtt
(
active_id
,
rgb
)
replace_block
(
active_pos
,
active_id
,
color
)
core
.
close_formspec
(
player
:
get_player_name
(),
"ledtree:colorpicker"
)
end
end
end
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