Ejemplo n.º 1
0
void Temperatura::loopApp()
{
  if (BaseApp::_running)
  {
    int chk = DHT11.read(DHT11PIN);

    switch (chk)
    {
      case 0: Serial.println("OK"); break;
      case -1: Serial.println("Erro de Checksum"); break;
      case -2: Serial.println("Erro de Time Out"); break;
      default: Serial.println("Erro Desconhecido"); break;
    }

    dtostrf((float)DHT11.humidity, 2, 0, floatValue);
    _ledMatrix->printStringScroll(0, 0, "Umidade (%): ", MESSAGE_SPEED, '<');
    _ledMatrix->printStringScroll(0, 0, floatValue, MESSAGE_SPEED, '<');
    
    delay(500);

    dtostrf((float)DHT11.temperature, 2, 0, floatValue);
    _ledMatrix->printStringScroll(0, 0, "Temperatura (Celsius): ", MESSAGE_SPEED, '<');
    _ledMatrix->printStringScroll(0, 0, floatValue, MESSAGE_SPEED, '<');

    delay(2000);
  } 
}
DHT11Readings getReadings()
{
    int chk = DHT11.read(DHT11PIN);
    DHT11Readings readings;
    Serial.print("Read sensor: ");
    switch (chk)
    {
        case DHTLIB_OK:
            Serial.println("OK");
            readings.status = true;
            break;
        case DHTLIB_ERROR_CHECKSUM:
            Serial.println("Checksum error");
            readings.status = false;
            break;
        case DHTLIB_ERROR_TIMEOUT:
            Serial.println("Time out error");
            readings.status = false;
            break;
        default:
            Serial.println("Unknown error");
            readings.status = false;
            break;
    }
    readings.temperature = DHT11.temperature;
    readings.humidity = DHT11.humidity;

    return readings;
}
Ejemplo n.º 3
0
void loop() {

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




  long now = millis();
  if (now - lastMsg > 2000) {
    int chk = DHT11.read(DHT11PIN);

    Serial.print("Read sensor: ");
    switch (chk)
    {
      case DHTLIB_OK:
        Serial.println("OK");
        break;
      case DHTLIB_ERROR_CHECKSUM:
        Serial.println("Checksum error");
        break;
      case DHTLIB_ERROR_TIMEOUT:
        Serial.println("Time out error");
        break;
      default:
        Serial.println("Unknown error");
        break;
    }

    Serial.print("Humidity (%): ");
    Serial.println((float)DHT11.humidity, 2);

    Serial.print("Temperature (°C): ");
    Serial.println((float)DHT11.temperature, 2);



    lastMsg = now;
    ++value;

    sprintf(msg, "%d",value);
    Serial.println(msg);
    client.publish("arduino-day/team0/sensor/value",msg);
  }
}
Ejemplo n.º 4
0
void loop()
{
    Serial.println("\n");

    int chk = DHT11.read(DHT11PIN);

    Serial.print("Read sensor: ");
    switch (chk)
    {
    case 0:
        Serial.println("OK");
        break;
    case -1:
        Serial.println("Checksum error");
        break;
    case -2:
        Serial.println("Time out error");
        break;
    default:
        Serial.println("Unknown error");
        break;
    }

    Serial.print("Humidity (%): ");
    Serial.println((float)DHT11.humidity, 2);

    Serial.print("Temperature (oC): ");
    Serial.println((float)DHT11.temperature, 2);

    Serial.print("Temperature (oF): ");
    Serial.println(Fahrenheit(DHT11.temperature), 2);

    Serial.print("Temperature (K): ");
    Serial.println(Kelvin(DHT11.temperature), 2);

    Serial.print("Dew Point (oC): ");
    Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

    Serial.print("Dew PointFast (oC): ");
    Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

    delay(2000);
}