Struggling with thing.handle()

Hello there, i made a project to measure AC line frequency using nodeMCU and zmpt101B. after googling i found the code and was able to view the measured AC line frequency on serial monitor. But when i try to send the data to thinger.io it wasn’t easy. When i apply the thing.handle() on the void loop() the esp NodeMCU was able to connect to thinger.io but after 8 seconds its reconnecting again. Can anyone help me about this problem?
btw this is my code :

#define DISABLE_TLS
#define THINGER_SERIAL_DEBUG

#include <ThingerESP8266.h>
#include <ESP8266WiFi.h>

#define USERNAME “username”
#define DEVICE_ID “device1”
#define DEVICE_CREDENTIAL “xxxxxxxxxxx”
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

int decimalPrecision = 2;
unsigned long startMicros;
unsigned long currentMicros;
int expectedFrequency = 50;
int frequencyAnalogPin = A0;
float frequencySampleCount = 0;
float frequency = 0;
float a;
float switch01 = 0;
float vAnalogRead = 0;
float readPin = 0;
unsigned long previousMicros = 0;

const char* ssid = “my_ssid”;
const char* password = “ssid_pass”;

int state =0;

void setup()
{
Serial.begin(9600);

pinMode(frequencyAnalogPin, OUTPUT);
digitalWrite(frequencyAnalogPin,HIGH);

WiFi.mode(WIFI_STA);
thing.add_wifi(ssid, password);
thing[“frequency”] >> outputValue(analogRead(frequencyAnalogPin));
}

void loop()
{
thing.handle();
currentMicros = micros();
vAnalogRead = analogRead(frequencyAnalogPin) - 512;

if(vAnalogRead >=0 && switch01 == 0)
  {
    frequencySampleCount = frequencySampleCount +1 ;
    switch01 = 1;
  }

if(vAnalogRead < 0 && switch01 == 1)
  {
    switch01 = 0;
  }

if(frequencySampleCount == expectedFrequency)
  {
    digitalWrite(LED_BUILTIN, LOW);
    a = currentMicros-startMicros ;
    frequency = 1/((a/1000000)/frequencySampleCount);
    Serial.print(frequency,decimalPrecision);                     
    Serial.println(" Hz");
    digitalWrite(LED_BUILTIN, HIGH);
    startMicros = currentMicros;
    frequencySampleCount = 0;
  }

}

** my code to measure and show value to serial monitor is :

int decimalPrecision = 2;
unsigned long startMicros;
unsigned long currentMicros;
int expectedFrequency = 50;
int frequencyAnalogPin = A0;
float frequencySampleCount = 0;
float frequency = 0;
float a;
float switch01 = 0;
float vAnalogRead = 0;

void setup()
{

Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
startMicros = micros();

}

void loop()
{

currentMicros = micros();
vAnalogRead = analogRead(frequencyAnalogPin) - 512;

if(vAnalogRead >=0 && switch01 == 0)
  {
    frequencySampleCount = frequencySampleCount +1 ;
    switch01 = 1;
  }

if(vAnalogRead < 0 && switch01 == 1)
  {
    switch01 = 0;
  }

if(frequencySampleCount == expectedFrequency)
  {
    a = currentMicros-startMicros ;
    frequency = 1/((a/1000000)/frequencySampleCount);
    Serial.print(frequency,decimalPrecision);                     
    Serial.println(" Hz");
    startMicros = currentMicros;
    frequencySampleCount = 0;
  }

}

Hi,

Can you paste the debug window output? the code seems to be ok, what I see is that you are reading the analog pin consulting the resource “frequency”, share the debug output to have better idea about it.

Hope this helps.

This is the debug output from my serial monitor

17:31:48.868 → scandone
17:31:49.806 → state: 0 → 2 (b0)
17:31:49.806 → state: 2 → 3 (0)
17:31:49.853 → state: 3 → 5 (10)
17:31:49.853 → add 0
17:31:49.853 → aid 4
17:31:49.853 → cnt
17:31:50.857 →
17:31:50.857 → connected with wifi_ssid, channel 8
17:31:50.904 → dhcp client start…
17:31:50.904 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
17:31:50.986 → [NETWORK] Connected to WiFi!
17:31:50.986 → [NETWORK] Getting IP Address…
17:31:51.023 → [NETWORK] Got IP Address: 192.168.0.105
17:31:51.070 → [NTP_SYN] Waiting for NTP time sync…
17:31:51.475 → [NTP_SYN] Current time (UTC): Thu Apr 14 09:31:51 2022
17:31:51.524 → [NETWORK] Connected!
17:31:51.571 → [_SOCKET] Connecting to iot.thinger .io:25202…
17:31:51.571 → [_SOCKET] Using secure TLS/SSL connection: yes
17:31:52.974 → [_SOCKET] Connected!
17:31:52.974 → [THINGER] Authenticating. User: thinger_username Device: nodemcu01
17:31:53.043 → [THINGER] Writing bytes: 48 [OK]
17:31:53.827 → [THINGER] Authenticated
17:31:54.791 → 5.37 Hz
17:31:55.776 → 50.03 Hz
17:31:56.777 → 50.03 Hz
17:31:57.784 → 50.02 Hz
17:31:58.779 → 50.02 Hz
17:31:59.750 → bcn_timout,ap_probe_send_start
17:31:59.797 → 50.01 Hz
17:31:59.835 → pm open,type:2 0
17:32:00.784 → 50.02 Hz
17:32:01.799 → 50.01 Hz
17:32:02.285 → ap_probe_send over, rest wifi status to disassoc
17:32:02.285 → state: 5 → 0 (1)
17:32:02.339 → rm 0
17:32:02.339 → pm close 7
17:32:02.339 → [NETWORK] Starting connection…
17:32:02.386 → [NETWORK] Connecting to network wifi_ssid
17:32:02.439 → scandone
17:32:02.439 → scandone
17:32:02.439 → state: 0 → 2 (b0)
17:32:02.486 → state: 2 → 3 (0)
17:32:02.486 → state: 3 → 5 (10)
17:32:02.486 → add 0
17:32:02.486 → aid 4
17:32:02.486 → cnt
17:32:02.539 →
17:32:02.539 → connected with wifi_ssid, channel 8
17:32:02.583 → dhcp client start…
17:32:02.583 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
17:32:02.639 → [NETWORK] Connected to WiFi!
17:32:02.686 → [NETWORK] Getting IP Address…
17:32:02.686 → [NETWORK] Got IP Address: 192.168.0.105
17:32:02.774 → [NTP_SYN] Waiting for NTP time sync…
17:32:02.824 → [NTP_SYN] Current time (UTC): Thu Apr 14 09:32:02 2022
17:32:02.871 → [NETWORK] Connected!
17:32:02.871 → [_SOCKET] Connecting to iot.thinger .io:25202…
17:32:02.923 → [_SOCKET] Using secure TLS/SSL connection: yes
17:32:04.087 → [_SOCKET] Connected!
17:32:04.087 → [THINGER] Authenticating. User: thinger_username Device: nodemcu01
17:32:04.172 → [THINGER] Writing bytes: 48 [OK]
17:32:04.957 → [THINGER] Authenticated
17:32:05.498 → 13.52 Hz
17:32:06.488 → 50.01 Hz
17:32:07.490 → 50.02 Hz
17:32:08.466 → 50.02 Hz
17:32:09.467 → 50.02 Hz
17:32:10.468 → 50.01 Hz
17:32:10.932 → bcn_timout,ap_probe_send_start
17:32:11.469 → 50.02 Hz
17:32:12.433 → pm open,type:2 0
17:32:12.471 → 50.02 Hz
17:32:13.403 → ap_probe_send over, rest wifi status to disassoc
17:32:13.450 → state: 5 → 0 (1)
17:32:13.494 → rm 0
17:32:13.494 → pm close 7
17:32:13.494 → [NETWORK] Starting connection…
17:32:13.541 → [NETWORK] Connecting to network wifi_ssid
17:32:13.589 → scandone
17:32:13.589 → scandone
17:32:13.589 → state: 0 → 2 (b0)
17:32:13.636 → state: 2 → 3 (0)
17:32:13.636 → state: 3 → 5 (10)
17:32:13.636 → add 0
17:32:13.636 → aid 4
17:32:13.636 → cnt
17:32:13.672 →
17:32:13.672 → connected with wifi_ssid, channel 8
17:32:13.719 → dhcp client start…
17:32:13.772 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
17:32:13.772 → [NETWORK] Connected to WiFi!
17:32:13.819 → [NETWORK] Getting IP Address…
17:32:13.872 → [NETWORK] Got IP Address: 192.168.0.105
17:32:13.908 → [NTP_SYN] Waiting for NTP time sync…
17:32:13.955 → [NTP_SYN] Current time (UTC): Thu Apr 14 09:32:13 2022
17:32:14.038 → [NETWORK] Connected!
17:32:14.038 → [_SOCKET] Connecting to iot.thinger .io:25202…
17:32:14.072 → [_SOCKET] Using secure TLS/SSL connection: yes
17:32:15.808 → [_SOCKET] Connected!
17:32:15.808 → [THINGER] Authenticating. User: thinger_username Device: nodemcu01
17:32:15.889 → [THINGER] Writing bytes: 48 [OK]
17:32:16.799 → [THINGER] Authenticated
17:32:16.905 → 11.37 Hz
17:32:17.878 → 50.02 Hz

Hi @haxorcitoz

It is possible that the connection is breaking in the 8-10 seconds until it reaches the thing.handle() again.

Based on the Coding Good Practices, and specifically in this paragraph:

If a specific routine requires several times to be executed, including an additional thing.handle() instruction could be helpful to guarantee the connection.

You may try to include several thing.handle() in your code, outside the conditional blocks or even inside if necessary.

Regards!

i try this code

#define DISABLE_TLS
#define THINGER_SERIAL_DEBUG

#include <ThingerESP8266.h>
#include <ESP8266WiFi.h>

#define USERNAME “thinger_user”
#define DEVICE_ID “nodemcu01”
#define DEVICE_CREDENTIAL “xxxxxxxxxxxxx”
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

int decimalPrecision = 2;
unsigned long startTimer = micros();
unsigned long currentTimer = micros();
int expectedFrequency = 50;
int frequencyAnalogPin = A0;
float frequencySampleCount = 0;
float frequency = 0;
float a;
float switch01 = 0;
float vAnalogRead = 0;

const char* ssid = “my_ssid”;
const char* password = “ssid_password”;

void setup()
{
Serial.begin(9600);
pinMode(frequencyAnalogPin, INPUT);
WiFi.mode(WIFI_STA);

thing.add_wifi(ssid, password);

startTimer;
thing[“send_data”] >>(pson & out)
{
out[“frequency”] = frequency;
};
}

void loop()
{
thing.handle();
currentTimer = micros();
vAnalogRead = analogRead(frequencyAnalogPin) - 512;
if(vAnalogRead >=0 && switch01 == 0)
{
frequencySampleCount = frequencySampleCount +1 ;
switch01 = 1;
}

if(vAnalogRead < 0 && switch01 == 1)
  {
    switch01 = 0;
  }

if(frequencySampleCount == expectedFrequency)
  {
    a = currentTimer-startTimer;
    frequency = 1/((a/1000000)/frequencySampleCount);
    Serial.print(frequency,decimalPrecision);
    Serial.println(" Hz");
    startTimer = currentTimer;
    frequencySampleCount = 0;
  }

thing.handle();
}

and i got this output

05:45:08.202 → 50.00 Hz
05:45:08.556 → bcn_timout,ap_probe_send_start
05:45:09.204 → 50.01 Hz
05:45:10.174 → 51.04 Hz
05:45:11.061 → ap_probe_send over, rest wifi status to disassoc
05:45:11.061 → state: 5 → 0 (1)
05:45:11.108 → rm 0
05:45:11.108 → [NETWORK] Starting connection…
05:45:11.161 → [NETWORK] Connecting to network my_ssid
05:45:11.161 → scandone
05:45:11.208 → scandone
05:45:11.208 → state: 0 → 2 (b0)
05:45:11.261 → state: 2 → 3 (0)
05:45:11.261 → state: 3 → 5 (10)
05:45:11.261 → add 0
05:45:11.261 → aid 4
05:45:11.261 → cnt
05:45:11.261 →
05:45:11.261 → connected with my_ssid, channel 8
05:45:11.361 → dhcp client start…
05:45:11.361 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
05:45:11.408 → [NETWORK] Connected to WiFi!
05:45:11.446 → [NETWORK] Getting IP Address…
05:45:11.493 → [NETWORK] Got IP Address: 192.168.0.105
05:45:11.493 → [NETWORK] Connected!
05:45:11.540 → [_SOCKET] Connecting to iot.thinger .io:25200…
05:45:11.578 → [_SOCKET] Using secure TLS/SSL connection: no
05:45:11.647 → [_SOCKET] Connected!
05:45:11.698 → [THINGER] Authenticating. User: thinger_user Device: nodemcu01
05:45:11.698 → [THINGER] Writing bytes: 48 [OK]
05:45:12.710 → [THINGER] Authenticated
05:45:12.863 → 18.80 Hz
05:45:13.827 → 50.01 Hz
05:45:14.812 → 50.01 Hz
05:45:15.844 → 50.01 Hz
05:45:16.815 → 50.02 Hz
05:45:17.833 → 50.01 Hz
05:45:18.672 → bcn_timout,ap_probe_send_start
05:45:18.820 → 50.01 Hz
05:45:19.827 → 50.00 Hz
05:45:20.826 → 50.01 Hz
05:45:21.179 → ap_probe_send over, rest wifi status to disassoc
05:45:21.226 → state: 5 → 0 (1)
05:45:21.226 → rm 0
05:45:21.226 → [NETWORK] Starting connection…
05:45:21.280 → [NETWORK] Connecting to network my_ssid
05:45:21.327 → scandone
05:45:21.327 → scandone
05:45:21.327 → state: 0 → 2 (b0)
05:45:21.380 → state: 2 → 3 (0)
05:45:21.380 → state: 3 → 5 (10)
05:45:21.427 → add 0
05:45:21.427 → aid 4
05:45:21.427 → cnt
05:45:21.427 →
05:45:21.427 → connected with my_ssid, channel 8
05:45:21.481 → dhcp client start…
05:45:21.481 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
05:45:21.528 → [NETWORK] Connected to WiFi!
05:45:21.581 → [NETWORK] Getting IP Address…
05:45:21.628 → [NETWORK] Got IP Address: 192.168.0.105
05:45:21.628 → [NETWORK] Connected!
05:45:21.682 → [_SOCKET] Connecting to iot.thinger .io:25200…
05:45:21.729 → [_SOCKET] Using secure TLS/SSL connection: no
05:45:21.782 → [_SOCKET] Connected!
05:45:21.829 → [THINGER] Authenticating. User: thinger_user Device: nodemcu01
05:45:21.829 → [THINGER] Writing bytes: 48 [OK]
05:45:22.945 → [THINGER] Authenticated
05:45:23.622 → 17.99 Hz
05:45:24.620 → 50.01 Hz
05:45:25.590 → 50.01 Hz
05:45:25.691 → [THINGER] Writing bytes: 2 [OK]
05:45:26.594 → 50.01 Hz
05:45:27.598 → 50.01 Hz
05:45:28.633 → 50.01 Hz
05:45:28.902 → bcn_timout,ap_probe_send_start
05:45:29.604 → 50.01 Hz
05:45:30.592 → 50.07 Hz
05:45:31.328 → pm open,type:2 0
05:45:31.411 → ap_probe_send over, rest wifi status to disassoc
05:45:31.466 → state: 5 → 0 (1)
05:45:31.466 → rm 0
05:45:31.466 → pm close 7
05:45:31.466 → [NETWORK] Starting connection…
05:45:31.511 → [NETWORK] Connecting to network my_ssid
05:45:31.558 → scandone
05:45:31.558 → scandone
05:45:31.558 → state: 0 → 2 (b0)
05:45:31.596 → state: 2 → 3 (0)
05:45:31.596 → state: 3 → 5 (10)
05:45:31.643 → add 0
05:45:31.643 → aid 4
05:45:31.643 → cnt
05:45:31.690 →
05:45:31.690 → connected with my_ssid, channel 8
05:45:31.690 → dhcp client start…
05:45:31.728 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
05:45:31.774 → [NETWORK] Connected to WiFi!
05:45:31.813 → [NETWORK] Getting IP Address…
05:45:31.848 → [NETWORK] Got IP Address: 192.168.0.105
05:45:31.895 → [NETWORK] Connected!
05:45:31.895 → [_SOCKET] Connecting to iot.thinger .io:25200…
05:45:31.997 → [_SOCKET] Using secure TLS/SSL connection: no
05:45:32.360 → [_SOCKET] Connected!
05:45:32.360 → [THINGER] Authenticating. User: thinger_user Device: nodemcu01
05:45:32.442 → [THINGER] Writing bytes: 48 [OK]
05:45:33.245 → [THINGER] Authenticated

i try this code

#define DISABLE_TLS
#define THINGER_SERIAL_DEBUG

#include <ThingerESP8266.h>
#include <ESP8266WiFi.h>

#define USERNAME “thinger_user”
#define DEVICE_ID “nodemcu01”
#define DEVICE_CREDENTIAL “xxxxxxxxxxxxx”
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

int decimalPrecision = 2;
unsigned long startTimer = micros();
unsigned long currentTimer = micros();
int expectedFrequency = 50;
int frequencyAnalogPin = A0;
float frequencySampleCount = 0;
float frequency = 0;
float a;
float switch01 = 0;
float vAnalogRead = 0;

const char* ssid = “my_ssid”;
const char* password = “ssid_password”;

void setup()
{
Serial.begin(9600);
pinMode(frequencyAnalogPin, INPUT);
WiFi.mode(WIFI_STA);

thing.add_wifi(ssid, password);

startTimer;
thing[“send_data”] >>(pson & out)
{
out[“frequency”] = frequency;
};
}

void loop()
{
thing.handle();
currentTimer = micros();
vAnalogRead = analogRead(frequencyAnalogPin) - 512;
if(vAnalogRead >=0 && switch01 == 0)
{
frequencySampleCount = frequencySampleCount +1 ;
switch01 = 1;
}

if(vAnalogRead < 0 && switch01 == 1)
  {
    switch01 = 0;
  }

if(frequencySampleCount == expectedFrequency)
  {
    thing.handle();
    a = currentTimer-startTimer;
    frequency = 1/((a/1000000)/frequencySampleCount);
    Serial.print(frequency,decimalPrecision);
    Serial.println(" Hz");
    startTimer = currentTimer;
    frequencySampleCount = 0;
  }

thing.handle();
}

and this is the output

05:54:27.606 → scandone
05:54:28.530 → state: 0 → 2 (b0)
05:54:28.530 → state: 2 → 3 (0)
05:54:28.578 → state: 3 → 5 (10)
05:54:28.578 → add 0
05:54:28.578 → aid 4
05:54:28.578 → cnt
05:54:29.578 →
05:54:29.578 → connected with my_ssid, channel 8
05:54:29.631 → dhcp client start…
05:54:29.631 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
05:54:29.678 → [NETWORK] Connected to WiFi!
05:54:29.731 → [NETWORK] Getting IP Address…
05:54:29.731 → [NETWORK] Got IP Address: 192.168.0.105
05:54:29.771 → [NETWORK] Connected!
05:54:29.831 → [_SOCKET] Connecting to iot.thinger .io:25200…
05:54:29.831 → [_SOCKET] Using secure TLS/SSL connection: no
05:54:29.913 → [_SOCKET] Connected!
05:54:29.913 → [THINGER] Authenticating. User: thinger_user Device: nodemcu01
05:54:29.955 → [THINGER] Writing bytes: 48 [OK]
05:54:30.771 → [THINGER] Authenticated
05:54:31.735 → 6.96 Hz
05:54:32.736 → 50.00 Hz
05:54:33.737 → 50.01 Hz
05:54:34.738 → 50.01 Hz
05:54:35.740 → 50.01 Hz
05:54:36.688 → bcn_timout,ap_probe_send_start
05:54:36.741 → 50.01 Hz
05:54:37.743 → 50.01 Hz
05:54:38.538 → pm open,type:2 0
05:54:38.744 → 50.02 Hz
05:54:39.207 → ap_probe_send over, rest wifi status to disassoc
05:54:39.248 → state: 5 → 0 (1)
05:54:39.248 → rm 0
05:54:39.248 → pm close 7
05:54:39.248 → [NETWORK] Starting connection…
05:54:39.295 → [NETWORK] Connecting to network my_ssid
05:54:39.393 → scandone
05:54:39.393 → scandone
05:54:39.393 → no my_ssid found, reconnect after 1s
05:54:39.445 → reconnect
05:54:42.328 → scandone
05:54:42.328 → state: 0 → 2 (b0)
05:54:42.328 → state: 2 → 3 (0)
05:54:42.328 → state: 3 → 5 (10)
05:54:42.366 → add 0
05:54:42.366 → aid 4
05:54:42.366 → cnt
05:54:42.366 →
05:54:42.366 → connected with my_ssid, channel 8
05:54:42.402 → dhcp client start…
05:54:42.450 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
05:54:42.550 → [NETWORK] Connected to WiFi!
05:54:42.550 → [NETWORK] Getting IP Address…
05:54:42.598 → [NETWORK] Got IP Address: 192.168.0.105
05:54:42.598 → [NETWORK] Connected!
05:54:42.651 → [_SOCKET] Connecting to iot.thinger .io:25200…
05:54:42.697 → [_SOCKET] Using secure TLS/SSL connection: no
05:54:42.751 → [_SOCKET] Connected!
05:54:42.751 → [THINGER] Authenticating. User: thinger_user Device: nodemcu01
05:54:42.797 → [THINGER] Writing bytes: 48 [OK]
05:54:43.599 → [THINGER] Authenticated
05:54:44.115 → 9.30 Hz
05:54:45.131 → 50.02 Hz
05:54:46.140 → 50.02 Hz
05:54:47.104 → 50.02 Hz
05:54:48.107 → 50.01 Hz
05:54:49.123 → 50.01 Hz
05:54:49.506 → bcn_timout,ap_probe_send_start
05:54:50.123 → 50.01 Hz
05:54:51.096 → 50.01 Hz
05:54:51.998 → ap_probe_send over, rest wifi status to disassoc
05:54:52.045 → state: 5 → 0 (1)
05:54:52.045 → rm 0
05:54:52.045 → [NETWORK] Starting connection…
05:54:52.082 → [NETWORK] Connecting to network my_ssid
05:54:52.129 → scandone
05:54:52.165 → scandone
05:54:52.165 → state: 0 → 2 (b0)
05:54:52.222 → state: 2 → 3 (0)
05:54:52.222 → state: 3 → 5 (10)
05:54:52.222 → add 0
05:54:52.222 → aid 4
05:54:52.222 → cnt
05:54:52.222 →
05:54:52.222 → connected with my_ssid, channel 8
05:54:52.321 → dhcp client start…
05:54:52.321 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
05:54:52.365 → [NETWORK] Connected to WiFi!
05:54:52.404 → [NETWORK] Getting IP Address…
05:54:52.438 → [NETWORK] Got IP Address: 192.168.0.105
05:54:52.438 → [NETWORK] Connected!
05:54:52.481 → [_SOCKET] Connecting to iot.thinger .io:25200…
05:54:52.529 → [_SOCKET] Using secure TLS/SSL connection: no
05:54:52.612 → [_SOCKET] Connected!
05:54:52.612 → [THINGER] Authenticating. User: thinger_user Device: nodemcu01
05:54:52.666 → [THINGER] Writing bytes: 48 [OK]
05:54:53.514 → [THINGER] Authenticated
05:54:53.651 → 19.69 Hz
05:54:54.643 → 50.01 Hz
05:54:55.671 → 50.01 Hz
05:54:56.672 → 50.00 Hz
05:54:57.674 → 50.00 Hz
05:54:58.659 → 50.01 Hz
05:54:59.513 → bcn_timout,ap_probe_send_start
05:54:59.655 → 50.00 Hz
05:55:00.679 → 50.00 Hz
05:55:01.679 → 50.00 Hz
05:55:02.027 → ap_probe_send over, rest wifi status to disassoc
05:55:02.063 → state: 5 → 0 (1)
05:55:02.111 → rm 0
05:55:02.111 → [NETWORK] Starting connection…
05:55:02.111 → [NETWORK] Connecting to network my_ssid
05:55:02.164 → scandone
05:55:02.212 → scandone
05:55:02.212 → state: 0 → 2 (b0)
05:55:02.212 → state: 2 → 3 (0)
05:55:02.212 → state: 3 → 5 (10)
05:55:02.258 → add 0
05:55:02.258 → aid 4
05:55:02.258 → cnt
05:55:02.258 →
05:55:02.258 → connected with my_ssid, channel 8
05:55:02.344 → dhcp client start…
05:55:02.344 → ip:192.168.0.105,mask:255.255.255.0,gw:192.168.0.1
05:55:02.381 → [NETWORK] Connected to WiFi!
05:55:02.428 → [NETWORK] Getting IP Address…
05:55:02.481 → [NETWORK] Got IP Address: 192.168.0.105
05:55:02.481 → [NETWORK] Connected!
05:55:02.528 → [_SOCKET] Connecting to iot.thinger .io:25200…
05:55:02.565 → [_SOCKET] Using secure TLS/SSL connection: no
05:55:02.922 → [_SOCKET] Connected!
05:55:02.922 → [THINGER] Authenticating. User: thinger_user Device: nodemcu01
05:55:02.969 → [THINGER] Writing bytes: 48 [OK]
05:55:04.332 → [THINGER] Authenticated
05:55:04.979 → 15.06 Hz
05:55:05.972 → 50.00 Hz
05:55:06.974 → 50.00 Hz

Hi,

The code seems to be ok, for testing purposes, comment your process code, just let at loop the “thing.handle();” instruction.

Which library version are you using?

i do this

#define DISABLE_TLS
#define THINGER_SERIAL_DEBUG

#include <ThingerESP8266.h>
#include <ESP8266WiFi.h>

#define USERNAME “thinger_user”
#define DEVICE_ID “nodemcu01”
#define DEVICE_CREDENTIAL “xxxxxxxxxxxxxxxxxx”
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

int decimalPrecision = 2;
unsigned long startTimer = micros();
unsigned long currentTimer = micros();
int expectedFrequency = 50;
int frequencyAnalogPin = A0;
float frequencySampleCount = 0;
float frequency = 0;
float a;
float switch01 = 0;
float vAnalogRead = 0;

const char* ssid = “my_ssid”;
const char* password = “ssid_password”;

void setup()
{
Serial.begin(9600);
pinMode(frequencyAnalogPin, INPUT);
WiFi.mode(WIFI_STA);

thing.add_wifi(ssid, password);

startTimer;
thing[“send_data”] >>(pson & out)
{
out[“frequency”] = frequency;
};
}

void loop()
{
thing.handle();

//////////////////////////////////////////////////////////////////////////////////// start comment
/*currentTimer = micros();
vAnalogRead = analogRead(frequencyAnalogPin) - 512;
if(vAnalogRead >=0 && switch01 == 0)
{
frequencySampleCount = frequencySampleCount +1 ;
switch01 = 1;
}

if(vAnalogRead < 0 && switch01 == 1)
{
switch01 = 0;
}

if(frequencySampleCount == expectedFrequency)
{
thing.handle();
a = currentTimer-startTimer;
frequency = 1/((a/1000000)/frequencySampleCount);
Serial.print(frequency,decimalPrecision);
Serial.println(" Hz");
startTimer = currentTimer;
frequencySampleCount = 0;
}
thing.handle();*/
//////////////////////////////////////////////////////////////////////////////////// stop comment
}

i got this on serial monitor

08:25:04.130 → SDK:2.2.2-dev(38a443e)/Core:2.7.3-3-g2843a5ac=20703003/lwIP:STABLE-2_1_2_RELEASE/glue:1.2-30-g92add50/BearSSL:5c771be
08:25:04.222 → [NETWORK] Starting connection…
08:25:04.284 → [NETWORK] Connecting to network my_ssid
08:25:04.331 → scandone
08:25:04.331 → scandone
08:25:04.331 → state: 0 → 2 (b0)
08:25:04.331 → state: 2 → 3 (0)
08:25:04.388 → state: 3 → 5 (10)
08:25:04.388 → add 0
08:25:04.388 → aid 6
08:25:04.435 → cnt
08:25:04.435 →
08:25:04.435 → connected with my_ssid, channel 8
08:25:04.435 → dhcp client start…
08:25:04.484 → ip:192.168.0.108,mask:255.255.255.0,gw:192.168.0.1
08:25:04.522 → [NETWORK] Connected to WiFi!
08:25:04.569 → [NETWORK] Getting IP Address…
08:25:04.569 → [NETWORK] Got IP Address: 192.168.0.108
08:25:04.650 → [NTP_SYN] Waiting for NTP time sync…
08:25:14.347 → pm open,type:2 0
08:25:20.071 → [NTP_SYN] Current time (UTC): Sun Apr 17 00:25:19 2022
08:25:20.113 → [NETWORK] Connected!
08:25:20.147 → [_SOCKET] Connecting to iot.thinger .io:25202…
08:25:20.192 → [_SOCKET] Using secure TLS/SSL connection: yes
08:25:22.345 → [_SOCKET] Connected!
08:25:22.345 → [THINGER] Authenticating. User: thinger_user Device: nodemcu01
08:25:22.391 → [THINGER] Writing bytes: 48 [OK]
08:25:23.339 → [THINGER] Authenticated
08:25:50.560 → [THINGER] Available bytes: 25
08:25:50.560 → [THINGER] Writing bytes: 7 [OK]
08:25:50.607 → [THINGER] Writing bytes: 27 [OK]
08:25:52.562 → [THINGER] Writing bytes: 27 [OK]
08:25:54.564 → [THINGER] Writing bytes: 27 [OK]
08:25:56.579 → [THINGER] Writing bytes: 27 [OK]
08:25:58.550 → [THINGER] Writing bytes: 27 [OK]
08:26:00.543 → [THINGER] Writing bytes: 27 [OK]
08:26:02.574 → [THINGER] Writing bytes: 27 [OK]
08:26:03.932 → [THINGER] Writing bytes: 2 [OK]
08:26:04.016 → [THINGER] Available bytes: 2
08:26:04.570 → [THINGER] Writing bytes: 27 [OK]
08:26:06.588 → [THINGER] Writing bytes: 27 [OK]
08:26:08.546 → [THINGER] Writing bytes: 27 [OK]
08:26:10.551 → [THINGER] Writing bytes: 27 [OK]
08:26:12.578 → [THINGER] Writing bytes: 27 [OK]

i use thinger library ver 2.21.1

and i use esp8266 ver 3.0.0
i try to use ver 3.0.2 but error on compiling so i downgrade to ver 3.0.0