About oxygen, humidity and temperature sensors

Hello. I plan to use your application to make the laboratory follow oxygen, humidity and temperature online. But I think those sensors are not supported?

DHT22 humidity and temperature sensor

What device are you planning to use? You can do this with an Arduino for sure, and a Pi with some patience and MQTT.

I plan to use to Arduino Uno with ESP8266 Wifi module. Can I see the data from these sensors (DHT22 and Grove oxygen sensor) without problem?

Currently using ESP8266 as a wifi shield is not supported, but if you install the pubsubclient library you can send the values to your dashboard using MQTT. Below is an example of using it to send temp/humidity. You will have to make some modifications, but the basics are there. Let me know if you need any help.

You will have to modify the following lines to include your info:
const char* ssid = “SSID”;
const char* password = “PASSWORD”;
const char* mqtt_server = “SERVER”;

if (client.connect(“ClientID”, “Username”, “Password”)) {

client.publish(“Topic”, msg);

#include <PubSubClient.h>
#include <ESP8266WiFi.h>

const char* ssid = "SSID";
const char* password = "PASSWORD";
const char* mqtt_server = "SERVER";

WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;

void setup() {
  int timeoutcounter = 0;
  
  Serial.begin(9600);
  dht.begin();
  WiFi.begin(ssid, password);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  while (WiFi.status() != WL_CONNECTED) {
    timeoutcounter++;
    delay(500);
    Serial.print(".");
    if (timeoutcounter >= 30){
      Serial.println("Failed to connect to wireless - sleeping for 5 minutes");
      delay(100);
      ESP.deepSleep(300000000, WAKE_RF_DEFAULT);
      delay(100);
    }
  }
  
  Serial.println("");
  Serial.println("WiFi connected");

  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("ClientID", "Username", "Password")) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Sleep for 5 minutes before retrying
      Serial.println("Failed to connect to MQTT server - sleeping for 5 minutes");
      delay(100);
      ESP.deepSleep(300000000, WAKE_RF_DEFAULT);
      delay(100);
    }
  }
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}

void loop() {
  if (DHTcounter > 200){
    Serial.println("Failed to read DHT11 sensor - sleeping for 5 minutes");
    delay(100);
    ESP.deepSleep(300000000, WAKE_RF_DEFAULT);
    delay(100);
  }
  
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  float h = dht.readHumidity();
  float t = dht.readTemperature(true);
  
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    DHTcounter++;
    return;
  }

  float hif = dht.computeHeatIndex(t, h);

  float vcc = ESP.getVcc();
  vcc = vcc / 1000;

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.println(" %");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *F");
  Serial.print("Heat index: ");
  Serial.print(hif);
  Serial.println(" *F");
  Serial.print("VCC Voltage: ");
  Serial.print(vcc);
  Serial.println(" V");

  String mqtt_message = String(t) + "," + String(h) + "," + String(hif) + "," + String(vcc);
  mqtt_message.toCharArray(msg, 50);

  Serial.print("Publish message: ");
  Serial.println(msg);
  client.publish("Topic", msg);

  Serial.println("Loop complete - sleeping for 10 minutes");
  delay(100);
  ESP.deepSleep(600000000, WAKE_RF_DEFAULT);
  delay(100);
}

Thank for your interest. I will try this method and i will disturb you again if I need help :slight_smile:

Bumping this old thread to share that we’ve just provided support in our MQTT Arduino library for using ESP8266 as a shield :slight_smile: We’ve done basic testing and works well. Give it a try for your project and let us know how it works out for you !

Here is the updated library on our github:

and the code can be found here: