Hi Seb
I decided to follow the initial instructions you posted...
I got the library loaded and the errors fixed in the library that were not compatible with the current version of Mach 4... and I got Mach 4 to post a massage the MQTT server (I attached a routine to a button for testing). This worked fine - but I could not get Mach 4 to respond to an incoming message - did you manage to get this to work?
This is the code I added to the screen load routine...
function mqttCallback(
topic, -- string
message) -- string
wx.wxMessageBox("mqttCallback");
--mc.mcCntlLoadGcodeFile(inst, "C:\\temp\\AliLive6.nc")
--mc.mcCntlSetLastError(inst, "Topic: " .. topic .. ", message: '" .. message .. "'");
mc.mcCntlSetLastError(inst, "message - test");
end
function SendMessage(msg)
--wx.wxMessageBox("mqttCallback");
mc.mcCntlSetLastError(inst, msg);
mqtt_client:publish("mach4", msg)
end
function MQTT_Connect()
--mqtt_client = mqtt.client.create("192.168.0.55", nil, mqttCallback)
mqtt_client = mqtt.client.create("192.168.0.3", nil, mqttCallback)
mqtt_client:connect("mach4")
mqtt_client:publish("mach4", "online")
mqtt_client:subscribe({"mach4/set"})
mqtt.Utility.set_debug(true)
end
MQTT_Connect()
I also added this to the screen load routine...
--socket module
package.loaded.socket = nil
socket = require "socket"
--MQTT module
package.loaded.MqttModul = nil
mqtt = require "mqtt_library_mod"
and I added this to the beginning of the PLC script...
mqtt_client:handler()
Alas I have not been able to get Mach4 to respond to a message from my Node-Red server. I would be really cool if I could post a gcode file name to Mach4 and tell it 'go'...
BTW...this is my first attempt to do anything with Mach4 - so its quite possible that I have made some simple mistakes. Also - I am trying to do this with the demo version, since this kind of thing is the reason I would upgrade to Mach4 - I want to see if I could get it working first - it maybe the reason its not working!!