minetest-mods / technic

Technic mod for Minetest
Other
145 stars 153 forks source link

Lua controller overheats when GETing digilines data from a switching station #486

Closed ghost closed 4 years ago

ghost commented 5 years ago

I’m not sure where to place this but since the Lua controller does not behave like this on other events or on other Digiline events but only in conjunction with the switching station I’m putting this here.

I have a switching station providing 10.8 kEU MV energy, I connected the switching station to a Lua controller with a digiline (the switching stations channel is mv). The following super simple program is set up in the controller:

print('start')
digiline_send('mv', 'get')
print(event.msg)
print('end')

I expect something like …

"start"
{
    demand = 10000,
    supply = 10800
}
"end"

… when hitting "Execute". But the message gets repeated multiple times and the Lua controller overheats. See log file of the result.

Minetest on 0.4.17.1 and Digilines, Mesecons, and Technic on latest versions available.

thomasrudin commented 5 years ago

You seem to run in an endless send() loop there. Messages should be checked in an event-handler:

-- click on "execute"
if event.type == "program" then
 digiline_send("mv", "get")
end

-- event from switching station
if event.type == "digiline" then
 print(event.msg)
end
ghost commented 5 years ago

Thanks, I think I can work with this. So it’s just a misunderstanding … Any idea how I can get this into a loop querying multiple switching stations and do something with the return values?

Desour commented 5 years ago

Any idea how I can get this into a loop querying multiple switching stations and do something with the return values?

Do you mean something like:

local ss_channels = {"ss1", "ss2", "mvss"}
-- click on "execute"
if event.type == "program" then
  for i = 1, #ss_channels do
    digiline_send(ss_channels[i], "get")
  end
end

-- event from switching station
if event.type == "digiline" then
  -- event.channel is the channel with that the digiline message came, eg. "ss1"
  -- event.msg is the "return value" of the switching station
  -- I do not know what you want to do exactly here…
  print(event.msg)
end

Also see https://github.com/minetest-mods/technic/wiki/Digilines#switching-station.

BuckarooBanzay commented 4 years ago

@SmallJoker this can be closed too (sorry for the pings)