All MQTT dummy function added

This commit is contained in:
Ollo 2021-03-26 22:44:18 +01:00
parent 41179c4afd
commit 9508542158
2 changed files with 32 additions and 6 deletions

View File

@ -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 colorBg=string.char(0,0,0) -- black is the default background color
sntpserverhostname="ptbtime1.ptb.de" sntpserverhostname="ptbtime1.ptb.de"
timezoneoffset=1 timezoneoffset=1
mqttServer="192.168.1.1"
mqttPrefix="test"

View File

@ -6,6 +6,8 @@ import org.luaj.vm2.Varargs;
import org.luaj.vm2.lib.TwoArgFunction; import org.luaj.vm2.lib.TwoArgFunction;
import org.luaj.vm2.lib.VarArgFunction; import org.luaj.vm2.lib.VarArgFunction;
import de.c3ma.ollo.LuaThreadTmr;
/** /**
* *
* @author ollo * @author ollo
@ -20,7 +22,7 @@ public class ESP8266Mqtt extends TwoArgFunction {
mqtt.set("Client", new MqttClient()); mqtt.set("Client", new MqttClient());
env.set("mqtt", mqtt); env.set("mqtt", mqtt);
env.get("package").get("loaded").set("tmr", mqtt); env.get("package").get("loaded").set("tmr", mqtt);
System.out.println("[MQTT] Modlue loaded");
return mqtt; return mqtt;
} }
@ -28,12 +30,13 @@ public class ESP8266Mqtt extends TwoArgFunction {
public LuaValue invoke(Varargs varargs) { public LuaValue invoke(Varargs varargs) {
final LuaTable dynMqtt = new LuaTable(); final LuaTable dynMqtt = new LuaTable();
if (varargs.narg() == 2) { if (varargs.narg() == 2) {
final String client = varargs.arg(2).toString().toString(); final String client = varargs.arg(1).toString().toString();
final int timeout = varargs.arg(3).toint(); final int timeout = varargs.arg(2).toint();
dynMqtt.set("on", new OnMqtt(client, timeout)); dynMqtt.set("on", new OnMqtt(client, timeout));
dynMqtt.set("publish", new PublishMqtt()); dynMqtt.set("publish", new PublishMqtt());
dynMqtt.set("subscribe", new SubscribeMqtt()); 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; return dynMqtt;
} }
@ -51,8 +54,13 @@ public class ESP8266Mqtt extends TwoArgFunction {
public LuaValue invoke(Varargs varargs) { public LuaValue invoke(Varargs varargs) {
final LuaTable onMqtt = new LuaTable(); 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 { } else {
for(int i=0; i <= varargs.narg(); i++) { for(int i=0; i <= varargs.narg(); i++) {
System.err.println("[MQTT] On ["+(i) + "] (" + varargs.arg(i).typename() + ") " + varargs.arg(i).toString() ); 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; 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;
}
}
} }