Ubidots device not receiving data


#1

Below is the WiFi.printDiag(Serial) printout of the nodemcu v3 device. I am not getting any data at my ubidots device. It seems to be reconnecting every 19 send points.

connected with TP-LINK_D22080, channel 9
dhcp client start…
ip:192.168.1.104,mask:255.255.255.0,gw:192.168.1.1
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
state: 5 -> 2 (2c0)
rm 0
reconnect
state: 2 -> 0 (0)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt

connected with TP-LINK_D22080, channel 9
dhcp client start…
ip:192.168.1.104,mask:255.255.255.0,gw:192.168.1.1
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 9.00}]}
publishing to TOPIC:
/v1.6/devices/water-sensor
JSON dict: {“h2o_heater”: [{“value”: 10.00}]}
state: 5 -> 2 (2c0)
rm 0
reconnect
state: 2 -> 0 (0)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 3
cnt


#2

Dear @blueminerals,

Is a little bit difficult to me verify where can be the issue by just reviewing the logs. Can you provide me a more useful information about it? :smiley:

Also, before start working with Ubidots I recommend you make a test using a basic example of “WebClient” which handle an HTTP request to a server. If everything works properly with the sample tested, just modify the request made to the Ubidots Server following the Ubidots API Reference.

All the best,
Maria C.


#3
#include <UbidotsESPMQTT.h>


/****************************************
   Define Constants
 ****************************************/
#define TOKEN "A1Exxxxxxxxx" // Your Ubidots TOKEN
#define WIFINAME "TP-LINK_D22080" //Your SSID
#define WIFIPASS "xxxxxxxxxxx" // Your Wifi Password

#define sensor    A0       // Hook water sensor to pin A0 of NODEMCU module
#define LED       2       // Led in NodeMCU/lolin wemos v3  at pin GPIO2 D4 
#define BRIGHT    350      // Max led intensity (1-500)
#define INHALE    2500     // Inhalation time in milliseconds.
#define PULSE     INHALE*1000/BRIGHT
#define REST      10000    // Rest Between Inhalations.

Ubidots client(TOKEN);

/****************************************
   Auxiliary Functions
 ****************************************/

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();
}

/****************************************
   Main Functions
 ****************************************/

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200); 
  pinMode(sensor, INPUT);   // Analog pin setup for read
  pinMode(LED, OUTPUT);     // LED pin as output.
  client.setDebug(true);    // Pass a true or false bool value to activate debug messages
  client.wifiConnection(WIFINAME, WIFIPASS);
  client.begin(callback); 
  WiFi.printDiag(Serial); 
}

void loop() {
  // Make sure the water sensor is connected to your WiFi network. If not try to reconnect.
  if (!client.connected()) {
    client.reconnect();
  }
  float adcValue = analogRead(sensor);    // Read the ADC channel
  client.add("h2o_heater", adcValue);     //
  client.ubidotsPublish("water-sensor");  // Device name for Ubidots. Make sure Ubidots is setup prior to loading and running this application.
  client.loop();
}

#4

Hey @blueminerals,

Now I understand the behavior presented by your side.

Making reference to the functionality of the function WiFi.printDiag(Serial) is provide a snapshot of Wi-Fi status, but as I can see in the code you are just calling the function just in the setup(). Based on this, I suspect the following options:

  1. The device is being restarted itself (memory issue probably), and for this reason prints every “x” period of time the WiFi diagnostic.
  2. The device is presenting network connectivity issues and once the module lost the connection to the network also lost the connection with the client.

In order to test where can be the issue following the options above I recommend you:

  • For option #1: Include a counter in the code. Initzalace a counter in the setup equal to 0. Then, increment it one per one in each loop and print the counter value. So, if you noted that the counter value starts incrementing and them in a moment the counter es equal to 0 means the device is being restarted.

  • For option #2: If the counter never decreases, means the device is not being restarted but it have a network connectivity issue. At this point, my recommendation is to try with other network and check if the issue persists.

I hope this can help you!

All the best,
Maria C.