I am getting the error 'ERROR: the index ‘mqtt’ does not exist`, while trying to implement a simple MQTT message sender.
Short (relevant) code here:
const MQTT_URL = "ssl://mqtt.<domain>";
const MQTT_PORT = 8883
const MQTT_UN = "electricimp";
const MQTT_PW = "<pass>";
local mqtt_cid = "sensors/" + imp.configparams.deviceid;
local mqtt_client = null;
function createMqttClient() {
// Instance an MQTT client
mqtt_client = mqtt.createclient();
// Connect with credentials
local options = {};
options.username <- MQTT_UN;
options.password <- MQTT_PW;
mqtt_client.connect(MQTT_URL + ":" + MQTT_PORT.tostring(), mqtt_cid, options);
}
function postReading(reading) {
createMqttClient()
}
device.on("reading", postReading);
Full trace:
[Status] Downloading new code; 8.99% program storage used
[Agent] ERROR: the index ‘mqtt’ does not exist
[Agent] ERROR: in createMqttClient agent_code:103
[Agent] ERROR: from postReading agent_code:60
(line numbers are different from above, since it’s a snippet)
Any idea on how to get my imp to understand mqtt?