Beispiel #1
0
static int handle_GET_humidity(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{
    char response[16];
    
    int chk = DHT.read22(DHT22PIN);
    switch (chk)
    {
      case DHTLIB_OK:
          // 1H30 de travail : pour trouver la seule fonction du monde en AVR capable de transormer un double en string
          dtostrf(DHT.humidity, 5, 2, response);
          break;
      case DHTLIB_ERROR_CHECKSUM:
          strncpy(response, "Checksum error", 16);
          break;
      case DHTLIB_ERROR_TIMEOUT:
          strncpy(response, "Time out error", 16);
          break;
      case DHTLIB_ERROR_CONNECT:
          strncpy(response, "Connect error", 16);
          break;
      case DHTLIB_ERROR_ACK_L:
          strncpy(response, "Ack Low error", 16);
          break;
      case DHTLIB_ERROR_ACK_H:
          strncpy(response, "Ack High error", 16);
          break;
      default:
          strncpy(response, "Unknown error", 16);
          break; 
    }
    
    return coap_make_response(scratch, outpkt, (const uint8_t *)response, strlen(response), id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
}
Beispiel #2
0
void loop()
{
  // Blink LED
  // blink();

  // Humidity from YL-38
  // Serial.println("------ YL-38 ------");
  // Serial.print("Humidity: ");
  // // Serial.print((float)getHumidityYL38()/10.24);
  // // Serial.println("\%");
  // Serial.println(getHumidityYL38());

  // Temperature and humidity from DHT11
  // dht11.read(4);

  // Read DHT22 data
  // Serial.print("DHT22, \t");
  // int chk = DHT.read22(DHT22_PIN);
  // switch (chk)
  // {
  //   case DHTLIB_OK:  
  //   Serial.print("OK,\t");
  //   break;
  //   case DHTLIB_ERROR_CHECKSUM: 
  //   Serial.print("Checksum error,\t"); 
  //   break;
  //   case DHTLIB_ERROR_TIMEOUT: 
  //   Serial.print("Time out error,\t"); 
  //   break;
  //   default: 
  //   Serial.print("Unknown error,\t"); 
  //   break;
  // }
  // Display data: human readable
  // Serial.println();
  // Serial.println("------ DHT22 ------");
  // Serial.print("Temperature: ");
  // Serial.println(DHT.temperature, 1);
  // Serial.print("Humidity:    ");
  // Serial.print(DHT.humidity, 1);
  // Serial.print("\%     ");

  int chk = DHT.read22(DHT22_PIN);
  switch (chk)
  {
    case DHTLIB_OK:
      Serial.println();
      Serial.print("temp: ");
      Serial.println(DHT.temperature, 1);
      Serial.print("humi: ");
      Serial.println(DHT.humidity, 1);
    break;
    case DHTLIB_ERROR_CHECKSUM: 
    break;
    case DHTLIB_ERROR_TIMEOUT: 
    break;
    default: 
    break;
  }

  delay(500);
}