|
Post by gerhut2000 on Dec 28, 2015 6:30:28 GMT
Hello Altogether
I use the Gateway-SW with version 2.3. Everything is working well, I receive data from a node etc. .
But if I use the loop funktion the check if the mqtt connection is available and do a reconnect if it is needed the system will stop working.
This means that the mqtt is running, I can see this because of the Ping and response pings from the mqtt server. But I do not receive or data by the RFM69 module, I see this because no mqtt message is send out and no Log in the SerialMonitor is shown of a received message.
OK. This are not so many information but maybe somebody knows a solution or can give me a hint qhat to check. I really do not know how to go on!
If you need more information please let me know what and how many information you need.
Thanks so far!
Nice greetings
Gerhard
|
|
|
Post by papa on Dec 29, 2015 13:40:32 GMT
Yes, I'm not sure I understand what you're asking. Maybe I can help you clarify your request so someone on this forum can help you.
Here's what I believe you're saying, gerhut2000: "I implemented computourist Gateway 2.3 & a compatible node program & that much works. THEN I made changes & additions involving mqttClient.loop() but those changes are NOT working. I want to use the loop function to check if the mqtt connection is available & do a reconnect if it is not available. HOWEVER when I try to use the loop function like this, the mqtt broker continues to run, but the system stops exchanging mqtt messages."
^^ Is my rephrasing of your post (just above) what you mean? ^^ Please correct anything important that I missed.
Another question: If the system is working (mqtt is functioning), why do you want or need to check if mqtt is available, especially if that causes problems?
Next, if you are trying to change the program, please post the changes you have tried.
If you respond to my questions & request for your program changes, perhaps someone on this forum can help.
|
|
|
Post by gerhut2000 on Dec 31, 2015 10:13:55 GMT
Hi Papa, yes you are right with your comments. Sorry for my bad writing.... This is the Main loop of my actual program. void loop() {
//#ifdef DEBUG
// if (!mqttToSend && Serial.available() > 0) // do not interfere with mqtt traffic
// {
// msgToSend = serialInput();
// } // get any human input in debug mode
// if (msgToSend) { sendMsg(dest); } // send serial input instruction packets
//#endif
// CONTROL RADIO LED AND CALCULATE UPTIME
//
/*if (Rstat) { // turn off radio LED after 100 msec
if (millis() - onMillis > 100) {
Rstat = false;
digitalWrite(R_LED, LOW);
}
}*/
if (lastMinute != (millis() / 60000)) { // another minute passed ?
lastMinute = millis() / 60000;
upTime++;
}
// RECEIVE AND SEND MESSAGES
//
if (mqttToSend) {
#ifdef DEBUG
Serial.println("mqttToSend - Start \n");
#endif
sendMsg(dest);
#ifdef DEBUG
Serial.print("mqttToSend - End \n");
#endif
} // send MQTT instruction packets over the radio network
if (radio.receiveDone()) {
processPacket();
} // check for received radio packets and construct MQTT message
if (lastMQTTCheck != (millis() / 5000)) { // another minute passed ?
lastMQTTCheck = millis() / 5000;
checkMQTTConnection = true;
}
if (checkMQTTConnection==true)
{
checkMQTTConnection = false;
if (!mqttClient.loop()) { // check connection MQTT server and process MQTT subscription input
#ifdef DEBUG
Serial.println("No MQTT conection... - Main Loop \n");
Serial.flush();
#endif
mqttCon = 0;
digitalWrite(MQCON, LOW);
while (mqttCon != 1) { // try to reconnect every 2 seconds
#ifdef DEBUG
Serial.println("connection failed... - Main Loop \n");
Serial.flush();
#endif
mqttCon = mqttClient.connect(clientName);
delay(2000);
}
if (mqttCon) { // Yes, we have a link so,
#ifdef DEBUG
Serial.println("got connection with MQTT server - Main Loop \n");
#endif
digitalWrite(MQCON, mqttCon); // turn on MQTT link indicator and
mqttClient.subscribe(subTopic); // re-subscribe to mqtt topic
}
#ifdef DEBUG
else Serial.println("no connection with MQTT server - Main Loop \n");
#endif
}
}
} // end loop This code is working now. As you see I only check every 5 seconds the mqqt connection (if (lastMQTTCheck != (millis() / 5000)) { lastMQTTCheck = millis() / 5000; checkMQTTConnection = true; } if (checkMQTTConnection==true) { ... } Before I checked every cycle if the mqqt connection is available. I think this is blocking the system or the mqqt server. Actually this is OK for me. What experience did you made with the " mqttClient.loop()" function? How do you use it? Thanks a lot. Nice greetings Gerhard Attachments:Gateway_2.3.ino (19.27 KB)
|
|
|
Post by papa on Dec 31, 2015 11:18:29 GMT
I'm glad you got it working.
Actually, I have no experience using the mqttClient.loop() function, except what is already in the Gateway sketch.
I do have a good amount of troubleshooting experience: I find that if I can clearly describe what I'm trying to do & what is going wrong, then I or someone else can often fix the problem. What I mean is that in the process of analyzing & describing a problem, the possible solution may appear to me or to someone else as I describe it to them.
It's good to have another happy coder with us. Enjoy.
|
|