Hi everyone,
Im trying to send telemetry from my Arduino Uno, ESP8266 module, and a sound sensor. I've tried with this code but I receive the message:
[FAILED] [ rc = : retry[FAILED] [ rc = : retrying in 5 seconds]
Connecting to ThingsBoard node ...
Can anyone help me?
Here is my code, I hide some info like my Wifi name and password or token of device but those are correct.
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char* ssid = "++++++++";
const char* password = "++++++";
#define TOKEN "+++++++++"
char ThingsboardHost[] = "192.168.1.77";
WiFiClient wifiClient;
PubSubClient client(wifiClient);
int status = WL_IDLE_STATUS;
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
Serial.print(".");
}
Serial.println("");
Serial.print("connected to");
Serial.println(ssid);
client.setServer( ThingsboardHost, 1883 );
}
void loop()
{
if ( !client.connected() )
{
reconnect();
}
getdecibeldata();
delay(5000);
}
void getdecibeldata()
{
String payload = "{";
payload += ""decibel":";payload += 60; payload += ",";
payload += "}";
char attributes[1000];
payload.toCharArray( attributes, 1000 );
client.publish( "v1/devices/me/telemetry",attributes);
Serial.println( attributes );
}
void reconnect() {
while (!client.connected()) {
status = WiFi.status();
if ( status != WL_CONNECTED) {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to AP");
}
Serial.print("Connecting to ThingsBoard node ...");
if ( client.connect("Esp8266", TOKEN, NULL) ) {
Serial.println( "[DONE]" );
} else {
Serial.print( "[FAILED] [ rc = " );
Serial.println( " : retrying in 5 seconds]" );
delay( 500 );
}
}
}