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