[SOLVED] Sensor data missing using mqtt and nodeMCU esp-12e

Good morning, we are using the nodeMCU esp-12e with MQTT to publish data from gas sensors to ubidots, we are using the arduino IDE and it shows that the board send the information, but ubidots doesnt get it at all, we are publishing 12 variables in 4 different devices, the serial monitor of arduino doesnt show any trouble, and we are waiting like 30 MINS for the information and there is missing information, like 1 or 2 devices missing, or the devices are empty at all, i’ll write the code below,

note: we tried a solution posted in this page, changing the PUBSUBCLIENT.h MQTT_MAX_PACKET_SIZE to 512, and it didnt work.

// Read Data from Grove - Multichannel Gas Sensor
#include <Wire.h>
#include "MutichannelGasSensor.h"
#include <Adafruit_ADS1015.h>
#include "UbidotsESPMQTT.h"
#define TOKEN "A1E-R1QItN2Iqv1udqhW625zn9yrnypsA8" // Your Ubidots TOKEN


#define WIFINAME "IoT Test" //Your SSID
#define WIFIPASS "IoT2017Test" // Your Wifi Pass

Ubidots client(TOKEN);

Adafruit_ADS1115 ads(0x48);
 float NH3_=0, CO_=0,NO2_=0, C3H8_=0,C4H10_=0, CH4_=0, H2_=0, C2H5OH_=0 ; 
 int16_t MQ7, MQ8, MQ4, MQ2;
 const float multiplier = 0.1875F;

 void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

 
void setup()
{
  
    Serial.begin(115200);  // start serial for output
    client.setDebug(true); // Pass a true or false bool value to activate debug messages
    client.wifiConnection(WIFINAME, WIFIPASS);
    client.begin(callback);
    Serial.println("power on!");
    gas.begin(0x04);//the default I2C address of the slave is 0x04
    gas.powerOn();
    ads.begin();
    Serial.print("Firmware Version = ");
    Serial.println(gas.getVersion());
}


void loop()
{  
   if (!client.connected()) {
    client.reconnect();

  }
  // Medición  MQ7
    MQ7 = ads.readADC_SingleEnded(0);
    float voltajeMQ7= (MQ7*multiplier)/1000;

    //Medición  MQ8
    MQ8=ads.readADC_SingleEnded(1);
    float voltajeMQ8= (MQ8*multiplier)/1000;

    // Medición  MQ4
    MQ4 = ads.readADC_SingleEnded(2);
    float voltajeMQ4= (MQ4*multiplier)/1000;

    // Medición  MQ2
    MQ2 = ads.readADC_SingleEnded(3);
    float voltajeMQ2= (MQ2*multiplier)/1000;
    float c1, c2, c3, c4, c5, c6, c7, c8;

    c1 = gas.measure_NH3();
    Serial.print("The concentration of NH3 is ");
    if(c1>=0) Serial.print(c1);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c2 = gas.measure_CO();
    Serial.print("The concentration of CO is ");
    if(c2>=0) Serial.print(c2);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c3 = gas.measure_NO2();
    Serial.print("The concentration of NO2 is ");
    if(c3>=0) Serial.print(c3);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c4 = gas.measure_C3H8();
    Serial.print("The concentration of C3H8 is ");
    if(c4>=0) Serial.print(c4);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c5 = gas.measure_C4H10();
    Serial.print("The concentration of C4H10 is ");
    if(c5>=0) Serial.print(c5);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c6 = gas.measure_CH4();
    Serial.print("The concentration of CH4 is ");
    if(c6>=0) Serial.print(c6);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c7 = gas.measure_H2();
    Serial.print("The concentration of H2 is ");
    if(c7>=0) Serial.print(c7);
    else Serial.print("invalid");
    Serial.println(" ppm");

    c8 = gas.measure_C2H5OH();
    Serial.print("The concentration of C2H5OH is ");
    if(c8>=0) Serial.print(c8);
    else Serial.print("invalid");
    Serial.println(" ppm");

    Serial.print("adcMQ7: ");Serial.println(MQ7);
    Serial.print("adcMQ8: ");Serial.println(MQ8);
    Serial.print("adcMQ4: ");Serial.println(MQ4);
    Serial.print("adcMQ2: ");Serial.println(MQ2);

  client.add("NH3-Multi", c1);  
  client.add("Co-Multi", c2);
  client.add("NO2-Multi", c3);
  //delay(1000);
  client.ubidotsPublish("Datos-Gases1"); 
  client.add("C3H8-Multi", c4);
  client.add("C4H10-Multi", c5);
  client.add("CH4-Multi", c6);
  //delay(1000);
  client.ubidotsPublish("oli2");     
  client.add("H2-Multi", c7);  
  client.add("C2H5OH-Multi", c8);
  client.add("MQ7", MQ7);  
  //delay(1000);
  client.ubidotsPublish("Datos-Gases3"); 
  client.add("MQ8", MQ8);
  client.add("MQ4", MQ4);
  client.add("MQ2", MQ2); 
 // delay(1000);
  client.ubidotsPublish("Datos-Gases4"); 
  
  client.loop();

  delay(20000);
}

thank you for your response.

Greetings @darkshagrath, as the PubSubclient library is limited to 512 I suspect that you are reaching that limit, try to send only two values per request and look if your device is updated properly, something like this:

// Updates First device
client.add("NH3-Multi", c1);  
client.add("Co-Multi", c2);
client.ubidotsPublish("Datos-Gases1"); 
client.add("NO2-Multi", c3);
client.ubidotsPublish("Datos-Gases1"); 

// Updates second device
client.add("C3H8-Multi", c4);
client.add("C4H10-Multi", c5);
client.ubidotsPublish("oli2"); 
client.add("CH4-Multi", c6);
client.ubidotsPublish("oli2"); 

Regards

1 Like