From 950854215898dbbbcdfc9ddde27d1217625bda94 Mon Sep 17 00:00:00 2001 From: Ollo Date: Fri, 26 Mar 2021 22:44:18 +0100 Subject: [PATCH] All MQTT dummy function added --- simulation/config.lua | 2 ++ .../src/de/c3ma/ollo/mockup/ESP8266Mqtt.java | 36 +++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/simulation/config.lua b/simulation/config.lua index c6b8f5e..4b24281 100644 --- a/simulation/config.lua +++ b/simulation/config.lua @@ -11,3 +11,5 @@ color4=string.char(0,0 ,tonumber(blue*0.2)) colorBg=string.char(0,0,0) -- black is the default background color sntpserverhostname="ptbtime1.ptb.de" timezoneoffset=1 +mqttServer="192.168.1.1" +mqttPrefix="test" diff --git a/simulation/src/de/c3ma/ollo/mockup/ESP8266Mqtt.java b/simulation/src/de/c3ma/ollo/mockup/ESP8266Mqtt.java index 758ab76..cbc752a 100644 --- a/simulation/src/de/c3ma/ollo/mockup/ESP8266Mqtt.java +++ b/simulation/src/de/c3ma/ollo/mockup/ESP8266Mqtt.java @@ -6,6 +6,8 @@ import org.luaj.vm2.Varargs; import org.luaj.vm2.lib.TwoArgFunction; import org.luaj.vm2.lib.VarArgFunction; +import de.c3ma.ollo.LuaThreadTmr; + /** * * @author ollo @@ -20,7 +22,7 @@ public class ESP8266Mqtt extends TwoArgFunction { mqtt.set("Client", new MqttClient()); env.set("mqtt", mqtt); env.get("package").get("loaded").set("tmr", mqtt); - + System.out.println("[MQTT] Modlue loaded"); return mqtt; } @@ -28,12 +30,13 @@ public class ESP8266Mqtt extends TwoArgFunction { public LuaValue invoke(Varargs varargs) { final LuaTable dynMqtt = new LuaTable(); if (varargs.narg() == 2) { - final String client = varargs.arg(2).toString().toString(); - final int timeout = varargs.arg(3).toint(); + final String client = varargs.arg(1).toString().toString(); + final int timeout = varargs.arg(2).toint(); dynMqtt.set("on", new OnMqtt(client, timeout)); dynMqtt.set("publish", new PublishMqtt()); dynMqtt.set("subscribe", new SubscribeMqtt()); - System.out.println("[MQTT] New " + client + " client"); + dynMqtt.set("connect", new ConnectMqtt()); + System.out.println("[MQTT] New client: " + client + "(" + timeout+ "s)"); } return dynMqtt; } @@ -51,8 +54,13 @@ public class ESP8266Mqtt extends TwoArgFunction { public LuaValue invoke(Varargs varargs) { final LuaTable onMqtt = new LuaTable(); - if (varargs.narg() == 2) { - System.out.println("[MQTT] On " + this.client); + + if (varargs.narg() == 3) { + final LuaTable table = varargs.arg(1).checktable(); + final String callback = varargs.arg(2).toString().toString(); + final LuaValue code = varargs.arg(3); + System.out.println("[MQTT] On " + this.client + " " + callback); + onMqtt.set("function", code); } else { for(int i=0; i <= varargs.narg(); i++) { System.err.println("[MQTT] On ["+(i) + "] (" + varargs.arg(i).typename() + ") " + varargs.arg(i).toString() ); @@ -94,4 +102,20 @@ public class ESP8266Mqtt extends TwoArgFunction { return onMqtt; } } + +private class ConnectMqtt extends VarArgFunction { + + public LuaValue invoke(Varargs varargs) { + final LuaTable onMqtt = new LuaTable(); + if (varargs.narg() == 1) { + System.out.println("[MQTT] connect "); + } else { + for(int i=0; i <= varargs.narg(); i++) { + System.err.println("[MQTT] connect ["+(i) + "] (" + varargs.arg(i).typename() + ") " + varargs.arg(i).toString() ); + } + return LuaValue.NIL; + } + return onMqtt; + } + } }