What is the difference between these 2 startup code?
Posted: Wed Jan 13, 2016 1:35 am
I have a working code for starting up MQTT. I am using the SMING framework. The relevant code section is like this;
I then made a small modification and things stopped working. Here are the changes;
What I did was to add the function parameter MqttClient to the function startMqttClient(). This simple change caused MQTT connection to fail. What is wrong with the code?
Code: Select all
MqttClient mqtt("192.168.1.4", 1883, onMessageReceived);
void startMqttClient()
{
mqtt.connect("esp8266");
mqtt.subscribe("ToXXX");
}
void connectOk()
{
Serial.println("I'm CONNECTED");
// Run MQTT client
startMqttClient();
}
void init()
{
Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
Serial.systemDebugOutput(false);
WifiStation.config(WIFI_SSID, WIFI_PWD);
WifiStation.enable(true);
WifiAccessPoint.enable(false);
WifiStation.waitConnection(connectOk, 20, connectFail); //We recommend 20+ seconds for connection timeout at start
}
I then made a small modification and things stopped working. Here are the changes;
Code: Select all
void startMqttClient(MqttClient mqtt_client)
{
mqtt_client.connect("esp8266");
mqtt_client.subscribe("ToXXX");
}
void connectOk()
{
Serial.println("I'm CONNECTED");
// Run MQTT client
startMqttClient(mqtt);
}
What I did was to add the function parameter MqttClient to the function startMqttClient(). This simple change caused MQTT connection to fail. What is wrong with the code?