0

dht11 esp32
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

dht11 esp32

by Gstvgrc on Thu May 09, 2019 2:25 pm

hi, this is driving me crazy, please help
--------------------------------------------------------
Code: Select all | TOGGLE FULL SIZE
#include "config.h"
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DATA_PIN 4

DHT_Unified dht(DATA_PIN, DHT11);

AdafruitIO_Feed *temperature = io.feed("temperature");
AdafruitIO_Feed *humidity = io.feed("humidity");

void setup() {
  Serial.begin(115200);
  while (! Serial);
  dht.begin();

  Serial.print("Connecting to Adafruit IO");
  io.connect();
  while (io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.println(io.statusText());
}

void loop() {
  io.run();
  sensors_event_t event;
  dht.temperature().getEvent(&event);

  float celsius = event.temperature;
  float fahrenheit = (celsius * 1.8) + 32;

  Serial.print("celsius: ");
  Serial.print(celsius);
  Serial.println("C");

  Serial.print("fahrenheit: ");
  Serial.print(fahrenheit);
  Serial.println("F");

  temperature->save(fahrenheit);
  dht.humidity().getEvent(&event);

  Serial.print("humidity: ");
  Serial.print(event.relative_humidity);
  Serial.println("%");

  humidity->save(event.relative_humidity);
  delay(5000);

}

-----------

Arduino:1.8.9 (Mac OS X), Tarjeta:"Adafruit ESP32 Feather, 80MHz, 921600, None"

/Users/gstvgrc/Documents/Arduino/libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.cpp: In constructor 'AdafruitIO_ESP32::AdafruitIO_ESP32(const char*, const char*, const char*, const char*)':
/Users/gstvgrc/Documents/Arduino/libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.cpp:22:53: error: invalid new-expression of abstract class type 'HttpClient'
_http = new HttpClient(*_client, _host, _http_port);
^
In file included from /Users/gstvgrc/Documents/Arduino/libraries/ArduinoHttpClient/src/ArduinoHttpClient.h:8:0,
from /Users/gstvgrc/Documents/Arduino/libraries/Adafruit_IO_Arduino/src/AdafruitIO.h:23,
from /Users/gstvgrc/Documents/Arduino/libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.h:18,
from /Users/gstvgrc/Documents/Arduino/libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.cpp:14:
/Users/gstvgrc/Documents/Arduino/libraries/ArduinoHttpClient/src/HttpClient.h:41:7: note: because the following virtual functions are pure within 'HttpClient':
class HttpClient : public Client
^
In file included from /Users/gstvgrc/Library/Arduino15/packages/esp32/hardware/esp32/1.0.2/cores/esp32/Arduino.h:157:0,
from /Users/gstvgrc/Documents/Arduino/libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.h:17,
from /Users/gstvgrc/Documents/Arduino/libraries/Adafruit_IO_Arduino/src/wifi/AdafruitIO_ESP32.cpp:14:
/Users/gstvgrc/Library/Arduino15/packages/esp32/hardware/esp32/1.0.2/cores/esp32/Client.h:31:17: note: virtual int Client::connect(IPAddress, uint16_t, int)
virtual int connect(IPAddress ip, uint16_t port, int timeout) =0;
^
/Users/gstvgrc/Library/Arduino15/packages/esp32/hardware/esp32/1.0.2/cores/esp32/Client.h:32:17: note: virtual int Client::connect(const char*, uint16_t, int)
virtual int connect(const char *host, uint16_t port, int timeout) =0;
^
Se encontraron varias bibliotecas para "WiFi.h"
Usado: /Users/gstvgrc/Library/Arduino15/packages/esp32/hardware/esp32/1.0.2/libraries/WiFi
No usado: /private/var/folders/pn/_252rd7x3sbcp26l2jjm5rz00000gn/T/AppTranslocation/EE49D33C-150D-4889-86BB-29B9C6EEF1A1/d/Arduino.app/Contents/Java/libraries/WiFi
exit status 1
Error compilando para la tarjeta Adafruit ESP32 Feather.
Last edited by franklin97355 on Thu May 09, 2019 2:31 pm, edited 1 time in total.
Reason: Please use code tags when posting code or logs to the forums. It preserves formatting and makes it easier for everyone to read the code. Click the code button above the reply box and past your code between the tags created.

Gstvgrc
 
Posts: 6
Joined: Wed Mar 13, 2019 2:19 pm

Re: dht11 esp32

by franklin97355 on Thu May 09, 2019 2:49 pm

Sorry but your code does not compile on my computer. Make sure you included the exact code you used.

franklin97355
 
Posts: 20515
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: dht11 esp32

by Gstvgrc on Thu May 09, 2019 2:55 pm

thanks for time
It's a example from Adafruit IO Arduino library: adafruitio_15_temp_humidity

It includes a config.h file:
Code: Select all | TOGGLE FULL SIZE
/************************ Adafruit IO Config *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME   "Gstvgrc"
#define IO_KEY        "xxxxxxxxxxxxxx"

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
//   - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
//   - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
//   - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
//   - Feather M0 WiFi -> https://www.adafruit.com/products/3010
//   - Feather WICED -> https://www.adafruit.com/products/3056
//   - Adafruit PyPortal -> https://www.adafruit.com/product/4116
//   - Adafruit Metro M4 Express AirLift Lite -> https://www.adafruit.com/product/4000
//   - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201

#define WIFI_SSID   "xxxxxx"
#define WIFI_PASS   "xxxxxxxx"

// uncomment the following line if you are using airlift
// #define USE_AIRLIFT

// uncomment the following line if you are using winc1500
// #define USE_WINC1500

// comment out the following lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"

#ifdef USE_AIRLIFT
  // Configure the pins used for the ESP32 connection
  #if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
    // Don't change the names of these #define's! they match the variant ones
    #define SPIWIFI SPI
    #define SPIWIFI_SS 10  // Chip select pin
    #define SPIWIFI_ACK 9  // a.k.a BUSY or READY pin
    #define ESP32_RESETN 6 // Reset pin
    #define ESP32_GPIO0 -1 // Not connected
  #endif
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
#else
  AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
#endif
/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);

/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

Gstvgrc
 
Posts: 6
Joined: Wed Mar 13, 2019 2:19 pm

Re: dht11 esp32

by brubell on Fri May 10, 2019 10:01 am

I'm not able to duplicate the error, also on MacOS compiling your example for the ESP32 Feather. Your config shows that you're on the latest Adafruit IO Arduino library.

What ESP32 board support package version are you using? (Tools->Board->Board Manager->Search for "ESP32")

brubell
 
Posts: 380
Joined: Fri Jul 17, 2015 10:33 pm

Re: dht11 esp32

by Gstvgrc on Fri May 10, 2019 10:04 am

Hi, Adafruit feather Huzzah32

Gstvgrc
 
Posts: 6
Joined: Wed Mar 13, 2019 2:19 pm

Re: dht11 esp32

by Gstvgrc on Sat May 11, 2019 4:09 pm

finally, no more errors!!!
Code: Select all | TOGGLE FULL SIZE
#include <DHT.h>
#include <DHT_U.h>
#include <Adafruit_Sensor.h>
#include "ThingSpeak.h"
#include "secrets.h"
#include <WiFi.h>

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
WiFiClient  client;

unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

DHT dht(4, DHT11);

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  ThingSpeak.begin(client);
  dht.begin();
}

void loop() {
  if (WiFi.status() != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(SECRET_SSID);
    while (WiFi.status() != WL_CONNECTED) {
      WiFi.begin(ssid, pass);
      Serial.print(".");
      delay(5000);
    }
    Serial.println("\nConnected.");
  }

  float h = dht.readHumidity();
  float t = dht.readTemperature();

  ThingSpeak.setField(1, t);
  ThingSpeak.setField(2, h);

  int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  if (x == 200) {
    Serial.println("Channel update successful.");
  }
  else {
    Serial.println("Problem updating channel. HTTP error code " + String(x));
  }
  delay(20000);
}
Last edited by franklin97355 on Sat May 11, 2019 10:06 pm, edited 1 time in total.
Reason: Please use code tags when posting code or logs to the forums. It preserves formatting and makes it easier for everyone to read the code. Click the code button above the reply box and past your code between the tags created.

Gstvgrc
 
Posts: 6
Joined: Wed Mar 13, 2019 2:19 pm

Please be positive and constructive with your questions and comments.