mqttagent

MQTT Lua Agent
git clone https://git.instinctive.eu/mqttagent.git
Log | Files | Refs | README | LICENSE

commit b6d283e67970c1564c2a1f11b9e0f916592aad17
parent 3c4f73c7eb6fded3c09839d7609bc0f9b55797a9
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Fri, 18 Apr 2025 18:20:01 +0000

SQL logging is moved from full agent to Lua callbacks
Diffstat:
Mcmd/mqttagent-full/main.go | 29+++--------------------------
1 file changed, 3 insertions(+), 26 deletions(-)

diff --git a/cmd/mqttagent-full/main.go b/cmd/mqttagent-full/main.go @@ -29,7 +29,6 @@ import ( ) type fullMqttAgent struct { - logger *sqlogger } func (agent *fullMqttAgent) Setup(L *lua.LState) { @@ -39,28 +38,11 @@ func (agent *fullMqttAgent) Setup(L *lua.LState) { L.SetGlobal("sqlogger", mt) L.SetField(mt, "new", L.NewFunction(luaSqloggerNew)) L.SetField(mt, "__index", L.SetFuncs(L.NewTable(), luaSqloggerMethods)) - - L.SetGlobal("sqlog", L.NewFunction(func(L *lua.LState) int { - arg := L.CheckString(1) - if logger, err := connect(arg); err != nil { - log.Println(err) - L.Push(lua.LNil) - L.Push(lua.LString(err.Error())) - return 2 - } else { - agent.logger.Close() - agent.logger = logger - L.Push(lua.LTrue) - return 1 - } - })) } -func (agent *fullMqttAgent) Log(L *lua.LState, msg *mqttagent.MqttMessage) { - if agent.logger != nil { - agent.logger.Received(msg) - } -} +func (agent *fullMqttAgent) Log(L *lua.LState, msg *mqttagent.MqttMessage) {} + +func (agent *fullMqttAgent) Teardown(L *lua.LState) {} func (logger *sqlogger) Received(msg *mqttagent.MqttMessage) { if logger.insertTopic == nil || logger.insertReceived == nil { @@ -78,11 +60,6 @@ func (logger *sqlogger) Received(msg *mqttagent.MqttMessage) { } } -func (agent *fullMqttAgent) Teardown(L *lua.LState) { - agent.logger.Close() - agent.logger = nil -} - type sqlogger struct { db *sql.DB insertTopic *sql.Stmt