I have a Mosquitto MQTT Broker set up using TLS via Pre-Shared Key. I’ve tested it by running a mosquitto client remotely and the broker itself is functioning properly. I’ve also tested MQTT on a Flexy with standard unencrypted MQTT on port 1883, based on the example BASIC code found here:
https://tools.ewonsupport.biz/mqtt/program.txt
So, what I am attempting to do now is modify the BASIC code from the example to change the port to 8883 and include the proper PSK information.
Below is what I have at the moment (only pasting in the portions of code that I’m modifying):
//######## CONFIG ###############
MQTTBrokerURL$ = “public IP address”
MQTTPort$ = “8883”
MQTTpsk_identity$ = “PSK Hint”
MQTTpsk$ = “hexadecimal PSK”
TopicToPublishOn$ = “/topic/flexy/” + SerNum$ + “/data”
TopicToSubscribe$ = “/topic/flexy/” + SerNum$ + “/command”
MsgToPublish$ = "Hello From Flexy " + SerNum$
//Uncomment the below line if you want to send your Tag values in a json format
SendTagValues% = 1
//######## END CONFIG ###############
Last_ConnStatus% = 0
//Configure MQTT Connection parameters
CONNECTMQTT:
MQTT “OPEN”, SerNum$ , MQTTBrokerURL$
MQTT “SETPARAM”, “PORT”, MQTTPort$
MQTT “SETPARAM”, “PSK”, MQTTpsk$
MQTT “SETPARAM”, “PSK-IDENTITY”, MQTTpsk_identity$
MQTT “SETPARAM”, “KEEPALIVE”, “30”
MQTT “SUBSCRIBE”,TopicToSubscribe$,1
//Launch the MQTT process in the background
SETSYS PRG,“RESUMENEXT”,1 //Continue in case of error at MQTT “CONNECT”
MQTT “CONNECT”
//If an error is raised --> Log a message
ErrorReturned% = GETSYS PRG,“LSTERR”
IF ErrorReturned% = 28 THEN @Log("[MQTT SCRIPT] WAN interface not yet ready")
SETSYS PRG,“RESUMENEXT”,0
//When receiving a message from Broker, “GOTO MQTTRECEIVEMSG”
ONMQTT “GOTO MQTTRECEIVEMSG”
ONTIMER 1, “GOTO SENDDATA”
TSET 1,30 //publish every 30 seconds
END
When I run this, I receive the error:
Operation failed (28) 38: MQTT “SETPARAM”, “PSK”, MQTTpsk$
So, my assumption is that “PSK” isn’t the proper parameter name to use here, but I haven’t been able to find any documentation about implementing TLS-PSK in BASIC. Any help would be awesome!