Avoid some mqtt server connection

Do not check subscription when we do not subscribe
This commit is contained in:
Mathieu Maret 2022-09-10 22:48:37 +02:00
parent 73d6e17dc1
commit 7b1d9ae63e
2 changed files with 7 additions and 4 deletions

View File

@ -197,14 +197,17 @@ void MqttCheckIRQ() {
}
void MqttCheckSubscription() {
void MqttCheckSubscription()
{
if (mqtt->getSubscriptionCount() == 0)
return;
if (MqttConnect() == 0) {
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt->readSubscription(0))) {
int gpio = getGpioFromSubscription(subscription, "/gpio/");
if (gpio > 0 && findIndex(gpio, gpioControlled) >= 0) {
SKETCH_DEBUG_PRINTF("Got Subscription for GPIO %d\n", gpio);
char *value = (char *) subscription->lastread;
char *value = (char *)subscription->lastread;
SKETCH_DEBUG_PRINTF("Receive data: %s\n", value);
MqttChangeGpioValue(gpio, atoi(value));
}
@ -212,7 +215,7 @@ void MqttCheckSubscription() {
gpio = getGpioFromSubscription(subscription, "/pwm/");
if (gpio > 0 && findIndex(gpio, pwmControlled) >= 0) {
SKETCH_DEBUG_PRINTF("Got Subscription for PWM %d\n", gpio);
char *value = (char *) subscription->lastread;
char *value = (char *)subscription->lastread;
SKETCH_DEBUG_PRINTF("Receive data: %s\n", value);
MqttChangePWMValue(gpio, atoi(value));
}

View File

@ -15,7 +15,7 @@ int TeleinfoSetup() {
inline int TeleinfoProcess(std::vector<struct mqttInfo> &){
return 0;
};
int TeleinfoProcess(float &iinst, float &papp, float &base){
int TeleinfoProcess(float &, float &, float &){
return 0;
};
#endif