thingsboard / thingsboard

Open-source IoT Platform - Device management, data collection, processing and visualization.
https://thingsboard.io
Apache License 2.0
17.49k stars 5.17k forks source link

problem changing the wifi linking code from arduino uno with esp8266 wifi sheild into esp32 #3069

Closed csmus closed 4 years ago

csmus commented 4 years ago

I have a code that send data to thingbords from the arduino ide through arduino uno with wifi sheild, I want the same code to work on esp32 board, I tried to change the wifi linking code to work on the esp32 board but its not working, I want the same code that is uploading data through arduino auno with es8266 wifi sheild to upload the same data using esp32 board, I will put the code here , I need help on changing the wifi linking code for thingsboard to work on esp32 board instead of the arduino auno with the esp8266 wifi sheild

csmus commented 4 years ago

This is the code that is working with the arduino uno with the wifi sheild, I want to make it work with esp32 board:

include

include

include

include

include

include

include

char ssid[] = "Raheem"; char pass[] = "11112222";

define TOKEN "EcjGhZfGdsB0YybyEWN1"

define mi A0 // analoge //select the inputs sensor to a pins

define wa A5 // analoge

define ONE_WIRE_BUS 7

OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); double Celcius=0;

float value=0,moisture=0,water=0; double temp[5]; double wat[5]; double moni[5]; int i = 0; double avT; double QT[5]; double QW[5]; double QM[5]; double QTW[5]; double QTM[5]; double QMW[5]; double avM; double avW; double TT[5]; double WW[5]; double MM[5]; double ssT=0; double ssW=0; double ssM=0; double ssTW=0; double ssTM=0; double ssMW=0; double RTW ; double RTM ; double RMW ; double RTWIOT ; double RTMIOT ; double RMWIOT ;

String Fualtstuats ; String Fualtstuats1 ; String Fualtstuats2 ;

String FualtstuatsIOT ; String FualtstuatsIOT1 ; String FualtstuatsIOT2 ;

double TEMPREAD; double MOISREAD; double WATREAD;

char thingsboardServer[] = "demo.thingsboard.io";

// Initialize the Ethernet client object WiFiEspClient espClient;

PubSubClient client(espClient);

SoftwareSerial soft(2, 3); // RX, TX

int status = WL_IDLE_STATUS; unsigned long lastSend;

void setup() {

// initialize serial for debugging Serial.begin(115200);

InitWiFi(); client.setServer( thingsboardServer, 1883 ); lastSend = 0; }

void loop() { Serial.print(" soil Temperature "); // addrees Serial.print(" soil Water "); Serial.println(" soil Moisture ");

   value=analogRead(mi);
   moisture=map(value,1017,100,0,100);

   sensors.requestTemperatures(); 
   Celcius=sensors.getTempCByIndex(0);

   value=analogRead(wa);
   water=map(value,1017,100,0,100);

    for ( int i=0 ; i <5; i++)
   {
   Serial.print("        ");

   temp[i] = Celcius;
   Serial.print(temp[i]);
   sensors.requestTemperatures(); 
   Celcius=sensors.getTempCByIndex(0);

Serial.print(" ");

   wat[i] = water;
   Serial.print(wat[i]);
   value=analogRead(wa);
   water=map(value,1017,100,0,100);

Serial.print(" ");

  moni[i] = moisture;
  Serial.println(moni[i]);
  value=analogRead(mi);
  moisture=map(value,1017,100,0,100);

  delay(60000);
  }

Serial.println("");

avT = (temp[0]+temp[1]+temp[2]+temp[3]+temp[4])/5; avW = (wat[0]+wat[1]+wat[2]+wat[3]+wat[4])/5; avM = ( moni[0]+ moni[1]+ moni[2]+ moni[3]+ moni[4])/5;

for ( int i=0 ; i < 5; i++) {

TT[i] =sq( temp[i] - avT); WW[i] =sq( wat[i] - avW); MM[i] =sq( moni[i] - avM);

QT[i] =( temp[i] - avT); QW[i] =( wat[i] - avW); QM[i] =( moni[i] - avM);

QTW[i]= QT[i] QW[i]; QTM[i]= QT[i] QM[i]; QMW[i]= QM[i]* QW[i];

ssTW+=QTW[i]; ssTM+=QTM[i]; ssMW+=QMW[i];

ssT+=TT[i]; ssW+=WW[i]; ssM+=MM[i]; } ssT=ssT+0.1; ssW=ssW+0.1; ssM=ssM+0.1;

RTW= ssTW/(sqrt(ssT ssW)); RTM= ssTM/(sqrt(ssT ssM)); RMW= ssMW/(sqrt(ssM * ssW));

Serial.print(" "); Serial.print("RTW="); Serial.println(RTW);

Serial.print(" "); Serial.print("RTM="); Serial.println(RTM);

Serial.print(" "); Serial.print("RMW="); Serial.println(RMW);

Serial.println(""); Serial.print(" ");

if (temp[0] == temp[1] && temp[0] == temp[2] && temp[0] == temp[3] && temp[0] == temp[4]) {

   TEMPREAD == 0;                                         
    } else {
       TEMPREAD == 1;                        // if the all dadt not equal 
    }

if (moni[0] == moni[1] && moni[0] == moni[2] && moni[0] == moni[3] && moni[0] == moni[4]) {

   MOISREAD == 0;
    } else { 
      MOISREAD == 1;                                            // if the all dadt not equal
    }

if (wat[0] == wat[1] && wat[0] == wat[2] && wat[0] == wat[3] && wat[0] == wat[4]) {

   WATREAD == 0;
   } else {
    WATREAD == 1;                                              // if the all dadt not equal
   }

if (TEMPREAD == 0 && MOISREAD ==0 && WATREAD == 0) { Serial.print("ALL SENSORS HAVE A FAULT"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= F" ; } else {

 if (RTW < 0 && RTM <0 && RMW < 0)   {  
       Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;
       Serial.print(" Faulty two sensor");

}

else if (RTW < 0 && RTM <0 && RMW > 0) { Serial.print("NO FAULT"); Fualtstuats = "T= G" ; Fualtstuats1 = "M= G" ; Fualtstuats2 = "W= G" ; }

else if (RTW < 0 && RTM >0 && RMW < 0) { Serial.print("Water have a Fault"); Fualtstuats = "T= G" ; Fualtstuats1 = "M= G" ; Fualtstuats2 = "W= F" ; }

else if (RTW < 0 && RTM > 0 && RMW > 0) { Serial.print("Faulty two sensor"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= F" ; }

else if (RTW > 0 && RTM < 0 && RMW < 0) {
Fualtstuats = "T= G" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= G" ; Serial.print("MOIS"); }

else if (RTW > 0 && RTM < 0 && RMW > 0) { Serial.print("Faulty two sensor"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= F" ; }

else if (RTW > 0 && RTM > 0 && RMW < 0) { Serial.print("Faulty all sensors"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= F" ; }

else if (RTW > 0 && RTM > 0 && RMW > 0) { Serial.print("Temperature have Fault"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= G" ; Fualtstuats2 = "W= G" ; } }

                                                                   // END THE CORRELATION EQUATION

if (TEMPREAD == 0 && MOISREAD == 0 && WATREAD == 1 && RTM > 0 ) {

    Serial.print("ALL SENSORS HAVE A FAULT");
    Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;

}

else if (TEMPREAD == 0 && MOISREAD == 0 && WATREAD == 1 && RTM < 0 ) {

   Serial.print("WATER SENSOR HAVE A FAULT");
   Fualtstuats = "T= G" ;
 Fualtstuats1 = "M= G" ;
 Fualtstuats2 = "W= F" ;

}

if (TEMPREAD == 0 && MOISREAD == 1 && WATREAD == 0 && RTW > 0 ) {

  Serial.print("ALL SENSORS HAVE A FAULT");
  Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;

}

else if (TEMPREAD == 0 && MOISREAD == 1 && WATREAD == 0 && RTW > 0 ) {

  Serial.print("MOISTURE SENSOR HAVE A FAULT");
  Fualtstuats = "T= G" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= G" ;

}

if (TEMPREAD == 1 && MOISREAD == 0 && WATREAD == 0 && RMW < 0 ) {

  Serial.print("ALL SENSORS HAVE A FAULT");
 Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;

}

else if (TEMPREAD == 1 && MOISREAD == 0 && WATREAD == 0 && RMW < 0 ) {

  Serial.print("TEMPERATURE SENSOR HAVE A FAULT");
  Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= G" ;
 Fualtstuats2 = "W= G" ;

}

if (TEMPREAD == 0 && MOISREAD == 1 && WATREAD == 1 ) {

  Serial.print("MOISTURE AND WATER SENSORS HAVE A FAULT");
  Fualtstuats = "T= G" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;

}

if (TEMPREAD == 1 && MOISREAD == 0 && WATREAD == 1 ) {

  Serial.print(" TEMPERATURE AND WATER SENSORS HAVE A FAULT");
 Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= G" ;
 Fualtstuats2 = "W= F" ;

}

if (TEMPREAD == 1 && MOISREAD == 1 && WATREAD == 0 ) {

  Serial.print("TEMPERATURE AND MOISTURE SENSORS HAVE A FAULT");
  Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= G" ;

} Serial.print(" ");

status = WiFi.status(); if ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid);

// Connect to WPA/WPA2 network status = WiFi.begin(ssid, pass); delay(500); } Serial.println("Connected to AP");

}

if ( !client.connected() ) { reconnect(); }

if ( millis() - lastSend > 1000 ) { // Update and send only after 1 seconds getAndSendTemperatureAndMoistureData(); lastSend = millis(); }

client.loop(); }

void getAndSendTemperatureAndMoistureData() { Serial.println("Collecting temperature data.");

                // Reading temperature or Moisture takes about 250 milliseconds!

float h = 100; // Read temperature as Celsius (the default) float t = 105;

                // Check if any reads failed and exit early (to try again).

if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // // Serial.print("Moisture: "); // Serial.print(h); // Serial.print(" %\t"); // Serial.print("Temperature: "); // Serial.print(t); // Serial.print(" *C ");

String temperature = String( Celcius); String moistureIOT = String(moisture); String waterIOT = String(water); String FualtstuatsIOT = String(Fualtstuats); String FualtstuatsIOT1 = String(Fualtstuats1); String FualtstuatsIOT2 = String(Fualtstuats2); String RTWIOT = String(RTW); String RTMIOT = String(RTM); String RMWIOT = String(RMW);

                   // Just debug messages

Serial.print( "[" ); Serial.print( temperature ); Serial.print( "," ); Serial.print( moistureIOT ); Serial.print( "," ); Serial.print( waterIOT ); Serial.print( "," ); Serial.print( FualtstuatsIOT ); Serial.print( "," ); Serial.print( FualtstuatsIOT1 ); Serial.print( "," ); Serial.print( FualtstuatsIOT2 ); Serial.print( "," );

Serial.print( RTWIOT ); Serial.print( "," ); Serial.print(RTMIOT); Serial.print( "," ); Serial.print(RMWIOT); Serial.print( "] -> " );

// Prepare a JSON payload string String payload = "{"; payload += ""T":"; payload += temperature; payload += ","; payload += ""H":"; payload += moistureIOT; payload += ","; payload += ""W":"; payload += waterIOT; payload += ",";

payload += "" ":"; payload += FualtstuatsIOT; payload += ","; payload += "" ":"; payload += FualtstuatsIOT1; payload += ","; payload += "" ":"; payload += FualtstuatsIOT2; payload += ",";

payload += ""TW":"; payload += RTWIOT; payload += ","; payload += ""TM":"; payload += RTMIOT; payload += ","; payload += ""MW":"; payload += RMWIOT; payload += "}";

// Send payload char attributes[100]; payload.toCharArray( attributes, 100 ); client.publish( "v1/devices/me/telemetry", attributes ); Serial.println( attributes ); }

void InitWiFi() { // initialize serial for ESP module soft.begin(9600); // initialize ESP module WiFi.init(&soft);

while (true);

}

Serial.println("Connecting to AP ...");

                                // attempt to connect to WiFi network

while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid);

                                // Connect to WPA/WPA2 network

status = WiFi.begin(ssid, pass); delay(500);

} Serial.println("Connected to AP"); }

void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.print("Connecting to ThingsBoard node ...");

                       // Attempt to connect (clientId, username, password)

if ( client.connect("Arduino uno Devices", TOKEN, NULL) ) { Serial.println( "[DONE]" ); } else { Serial.print( "[FAILED] [ rc = " ); Serial.print( client.state() ); Serial.println( " : retrying in 5 seconds]" );

           // Wait 5 seconds before retrying

delay( 500 ); }

} }

csmus commented 4 years ago

This is my trial to make it work on the esp32 but its not working, any suggestion or help, i am new to the IoT..:

include

include

include

include

include

char ssid[] = "ha"; char pass[] = "1853373553833";

define TOKEN "sCswyCt1dfLtUnaKXp3Y"

define mi 34 // analoge //select the inputs sensor to a pins

define wa 35 // analoge

define ONE_WIRE_BUS 7

OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); double Celcius=0; float value=0,moisture=0,water=0; double temp[5]; double wat[5]; double moni[5]; int i = 0; double avT; double QT[5]; double QW[5]; double QM[5]; double QTW[5]; double QTM[5]; double QMW[5]; double avM; double avW; double TT[5]; double WW[5]; double MM[5]; double ssT=0; double ssW=0; double ssM=0; double ssTW=0; double ssTM=0; double ssMW=0; double RTW ; double RTM ; double RMW ; double RTWIOT ; double RTMIOT ; double RMWIOT ;

String Fualtstuats ; String Fualtstuats1 ; String Fualtstuats2 ;

String FualtstuatsIOT ; String FualtstuatsIOT1 ; String FualtstuatsIOT2 ;

double TEMPREAD; double MOISREAD; double WATREAD;

char thingsboardServer[] = "demo.thingsboard.io";

// Initialize the Ethernet client object WiFiClient wifiClient; int status = WL_IDLE_STATUS; unsigned long lastSend;

void setup() {

// initialize serial for debugging Serial.begin(115200);

InitWiFi(); client.setServer( thingsboardServer, 1883 ); lastSend = 0; }

void loop() { Serial.print(" soil Temperature "); // addrees Serial.print(" soil Water "); Serial.println(" soil Moisture ");

   value=analogRead(mi);
   moisture=map(value,1017,100,0,100);

   sensors.requestTemperatures(); 
   Celcius=sensors.getTempCByIndex(0);

   value=analogRead(wa);
   water=map(value,1017,100,0,100);

    for ( int i=0 ; i <5; i++)
   {
   Serial.print("        ");

   temp[i] = Celcius;
   Serial.print(temp[i]);
   sensors.requestTemperatures(); 
   Celcius=sensors.getTempCByIndex(0);

Serial.print(" ");

   wat[i] = water;
   Serial.print(wat[i]);
   value=analogRead(wa);
   water=map(value,1017,100,0,100);

Serial.print(" ");

  moni[i] = moisture;
  Serial.println(moni[i]);
  value=analogRead(mi);
  moisture=map(value,1017,100,0,100);

  delay(60000);
  }

Serial.println("");

avT = (temp[0]+temp[1]+temp[2]+temp[3]+temp[4])/5; avW = (wat[0]+wat[1]+wat[2]+wat[3]+wat[4])/5; avM = ( moni[0]+ moni[1]+ moni[2]+ moni[3]+ moni[4])/5;

for ( int i=0 ; i < 5; i++) {

TT[i] =sq( temp[i] - avT); WW[i] =sq( wat[i] - avW); MM[i] =sq( moni[i] - avM);

QT[i] =( temp[i] - avT); QW[i] =( wat[i] - avW); QM[i] =( moni[i] - avM);

QTW[i]= QT[i] QW[i]; QTM[i]= QT[i] QM[i]; QMW[i]= QM[i]* QW[i];

ssTW+=QTW[i]; ssTM+=QTM[i]; ssMW+=QMW[i];

ssT+=TT[i]; ssW+=WW[i]; ssM+=MM[i]; } ssT=ssT+0.1; ssW=ssW+0.1; ssM=ssM+0.1;

RTW= ssTW/(sqrt(ssT ssW)); RTM= ssTM/(sqrt(ssT ssM)); RMW= ssMW/(sqrt(ssM * ssW));

Serial.print(" "); Serial.print("RTW="); Serial.println(RTW);

Serial.print(" "); Serial.print("RTM="); Serial.println(RTM);

Serial.print(" "); Serial.print("RMW="); Serial.println(RMW);

Serial.println(""); Serial.print(" ");

if (temp[0] == temp[1] && temp[0] == temp[2] && temp[0] == temp[3] && temp[0] == temp[4]) {

   TEMPREAD == 0;                                         
    } else {
       TEMPREAD == 1;                        // if the all dadt not equal 
    }

if (moni[0] == moni[1] && moni[0] == moni[2] && moni[0] == moni[3] && moni[0] == moni[4]) {

   MOISREAD == 0;
    } else { 
      MOISREAD == 1;                                            // if the all dadt not equal
    }

if (wat[0] == wat[1] && wat[0] == wat[2] && wat[0] == wat[3] && wat[0] == wat[4]) {

   WATREAD == 0;
   } else {
    WATREAD == 1;                                              // if the all dadt not equal
   }

if (TEMPREAD == 0 && MOISREAD ==0 && WATREAD == 0) { Serial.print("ALL SENSORS HAVE A FAULT"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= F" ; } else {

 if (RTW < 0 && RTM <0 && RMW < 0)   {  
       Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;
       Serial.print(" Faulty two sensor");

}

else if (RTW < 0 && RTM <0 && RMW > 0) { Serial.print("NO FAULT"); Fualtstuats = "T= G" ; Fualtstuats1 = "M= G" ; Fualtstuats2 = "W= G" ; }

else if (RTW < 0 && RTM >0 && RMW < 0) { Serial.print("Water have a Fault"); Fualtstuats = "T= G" ; Fualtstuats1 = "M= G" ; Fualtstuats2 = "W= F" ; }

else if (RTW < 0 && RTM > 0 && RMW > 0) { Serial.print("Faulty two sensor"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= F" ; }

else if (RTW > 0 && RTM < 0 && RMW < 0) {
Fualtstuats = "T= G" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= G" ; Serial.print("MOIS"); }

else if (RTW > 0 && RTM < 0 && RMW > 0) { Serial.print("Faulty two sensor"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= F" ; }

else if (RTW > 0 && RTM > 0 && RMW < 0) { Serial.print("Faulty all sensors"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= F" ; Fualtstuats2 = "W= F" ; }

else if (RTW > 0 && RTM > 0 && RMW > 0) { Serial.print("Temperature have Fault"); Fualtstuats = "T= F" ; Fualtstuats1 = "M= G" ; Fualtstuats2 = "W= G" ; } }

                                                                   // END THE CORRELATION EQUATION

if (TEMPREAD == 0 && MOISREAD == 0 && WATREAD == 1 && RTM > 0 ) {

    Serial.print("ALL SENSORS HAVE A FAULT");
    Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;

}

else if (TEMPREAD == 0 && MOISREAD == 0 && WATREAD == 1 && RTM < 0 ) {

   Serial.print("WATER SENSOR HAVE A FAULT");
   Fualtstuats = "T= G" ;
 Fualtstuats1 = "M= G" ;
 Fualtstuats2 = "W= F" ;

}

if (TEMPREAD == 0 && MOISREAD == 1 && WATREAD == 0 && RTW > 0 ) {

  Serial.print("ALL SENSORS HAVE A FAULT");
  Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;

}

else if (TEMPREAD == 0 && MOISREAD == 1 && WATREAD == 0 && RTW > 0 ) {

  Serial.print("MOISTURE SENSOR HAVE A FAULT");
  Fualtstuats = "T= G" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= G" ;

}

if (TEMPREAD == 1 && MOISREAD == 0 && WATREAD == 0 && RMW < 0 ) {

  Serial.print("ALL SENSORS HAVE A FAULT");
 Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;

}

else if (TEMPREAD == 1 && MOISREAD == 0 && WATREAD == 0 && RMW < 0 ) {

  Serial.print("TEMPERATURE SENSOR HAVE A FAULT");
  Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= G" ;
 Fualtstuats2 = "W= G" ;

}

if (TEMPREAD == 0 && MOISREAD == 1 && WATREAD == 1 ) {

  Serial.print("MOISTURE AND WATER SENSORS HAVE A FAULT");
  Fualtstuats = "T= G" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= F" ;

}

if (TEMPREAD == 1 && MOISREAD == 0 && WATREAD == 1 ) {

  Serial.print(" TEMPERATURE AND WATER SENSORS HAVE A FAULT");
 Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= G" ;
 Fualtstuats2 = "W= F" ;

}

if (TEMPREAD == 1 && MOISREAD == 1 && WATREAD == 0 ) {

  Serial.print("TEMPERATURE AND MOISTURE SENSORS HAVE A FAULT");
  Fualtstuats = "T= F" ;
 Fualtstuats1 = "M= F" ;
 Fualtstuats2 = "W= G" ;

} Serial.print(" ");

status = WiFi.status(); if ( status != WL_CONNECTED) { while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid);

// Connect to WPA/WPA2 network status = WiFi.begin(ssid, pass); delay(500); } Serial.println("Connected to AP");

}

if ( !client.connected() ) { reconnect(); }

if ( millis() - lastSend > 1000 ) { // Update and send only after 1 seconds getAndSendTemperatureAndMoistureData(); lastSend = millis(); }

client.loop(); }

void getAndSendTemperatureAndMoistureData() { Serial.println("Collecting temperature data.");

                // Reading temperature or Moisture takes about 250 milliseconds!

float h = 100; // Read temperature as Celsius (the default) float t = 105;

                // Check if any reads failed and exit early (to try again).

if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } // // Serial.print("Moisture: "); // Serial.print(h); // Serial.print(" %\t"); // Serial.print("Temperature: "); // Serial.print(t); // Serial.print(" *C ");

String temperature = String( Celcius); String moistureIOT = String(moisture); String waterIOT = String(water); String FualtstuatsIOT = String(Fualtstuats); String FualtstuatsIOT1 = String(Fualtstuats1); String FualtstuatsIOT2 = String(Fualtstuats2); String RTWIOT = String(RTW); String RTMIOT = String(RTM); String RMWIOT = String(RMW);

                   // Just debug messages

Serial.print( "[" ); Serial.print( temperature ); Serial.print( "," ); Serial.print( moistureIOT ); Serial.print( "," ); Serial.print( waterIOT ); Serial.print( "," ); Serial.print( FualtstuatsIOT ); Serial.print( "," ); Serial.print( FualtstuatsIOT1 ); Serial.print( "," ); Serial.print( FualtstuatsIOT2 ); Serial.print( "," );

Serial.print( RTWIOT ); Serial.print( "," ); Serial.print(RTMIOT); Serial.print( "," ); Serial.print(RMWIOT); Serial.print( "] -> " );

// Prepare a JSON payload string String payload = "{"; payload += ""T":"; payload += temperature; payload += ","; payload += ""H":"; payload += moistureIOT; payload += ","; payload += ""W":"; payload += waterIOT; payload += ",";

payload += "" ":"; payload += FualtstuatsIOT; payload += ","; payload += "" ":"; payload += FualtstuatsIOT1; payload += ","; payload += "" ":"; payload += FualtstuatsIOT2; payload += ",";

payload += ""TW":"; payload += RTWIOT; payload += ","; payload += ""TM":"; payload += RTMIOT; payload += ","; payload += ""MW":"; payload += RMWIOT; payload += "}";

// Send payload char attributes[100]; payload.toCharArray( attributes, 100 ); client.publish( "v1/devices/me/telemetry", attributes ); Serial.println( attributes ); }

void InitWiFi() { // initialize serial for ESP module soft.begin(9600); // initialize ESP module WiFi.init(&soft);

while (true);

}

Serial.println("Connecting to AP ...");

                                // attempt to connect to WiFi network

while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to WPA SSID: "); Serial.println(ssid);

                                // Connect to WPA/WPA2 network

status = WiFi.begin(ssid, pass); delay(500);

} Serial.println("Connected to AP"); }

void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.print("Connecting to ThingsBoard node ...");

                       // Attempt to connect (clientId, username, password)

if ( client.connect("Arduino uno Devices", TOKEN, NULL) ) { Serial.println( "[DONE]" ); } else { Serial.print( "[FAILED] [ rc = " ); Serial.print( client.state() ); Serial.println( " : retrying in 5 seconds]" );

           // Wait 5 seconds before retrying

delay( 500 ); }

} }

Karabiy commented 4 years ago

so that code does not work. Do you receive a specific error on those?

csmus commented 4 years ago

@Karabiy yes I recieved this error: exit status 1 'client' was not declared in this scope ,in line 430, also duplicate of library errors

Karabiy commented 4 years ago

make sure that you have described the client object, so that it can be used

csmus commented 4 years ago

@Karabiy can u show me how on the code above? thanks in advance..

Karabiy commented 4 years ago

you may refer to this link regarding the essentials of the code and on how to proceed with those in a correct way: https://thingsboard.io/docs/samples/arduino/temperature/ make sure to declare all the objects being used in the body