Freetronics EtherTen with IRTemp Sensor and DHT22 Sensor Hosted on a External Server

Hi all

Was wondering how can I integrate these 2 sensors and then push the data to an external hosted server so that I can monitor them wherever I am

Sensor 1

Humidity and Temperature Sensor Module - DHT22

Sensor 2

IR Temperature Sensor Module

Arduino

EtherTen Arduino

I have read these pages

I have both sensors working in the examples, but I am confused on how to merge the 2 examples together.

DHT22 Code

#include <dht.h>

dht DHT;

#define DHT22_PIN 5

struct
{
    uint32_t total;
    uint32_t ok;
    uint32_t crc_error;
    uint32_t time_out;
    uint32_t connect;
    uint32_t ack_l;
    uint32_t ack_h;
    uint32_t unknown;
} stat = { 0,0,0,0,0,0,0,0};

void setup()
{
    Serial.begin(9600);
    Serial.println("dht22_test.ino");
    Serial.print("LIBRARY VERSION: ");
    Serial.println(DHT_LIB_VERSION);
    Serial.println();
    Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
}

void loop()
{
    // READ DATA
    Serial.print("DHT22, \t");

    uint32_t start = micros();
    int chk = DHT.read22(DHT22_PIN);
    uint32_t stop = micros();

    stat.total++;
    switch (chk)
    {
    case DHTLIB_OK:
        stat.ok++;
        Serial.print("OK,\t");
        break;
    case DHTLIB_ERROR_CHECKSUM:
        stat.crc_error++;
        Serial.print("Checksum error,\t");
        break;
    case DHTLIB_ERROR_TIMEOUT:
        stat.time_out++;
        Serial.print("Time out error,\t");
        break;
    case DHTLIB_ERROR_CONNECT:
        stat.connect++;
        Serial.print("Connect error,\t");
        break;
    case DHTLIB_ERROR_ACK_L:
        stat.ack_l++;
        Serial.print("Ack Low error,\t");
        break;
    case DHTLIB_ERROR_ACK_H:
        stat.ack_h++;
        Serial.print("Ack High error,\t");
        break;
    default:
        stat.unknown++;
        Serial.print("Unknown error,\t");
        break;
    }
    // DISPLAY DATA
    Serial.print(DHT.humidity, 1);
    Serial.print(",\t");
    Serial.print(DHT.temperature, 1);
    Serial.print(",\t");
    Serial.print(stop - start);
    Serial.println();

    if (stat.total % 20 == 0)
    {
        Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
        Serial.print(stat.total);
        Serial.print("\t");
        Serial.print(stat.ok);
        Serial.print("\t");
        Serial.print(stat.crc_error);
        Serial.print("\t");
        Serial.print(stat.time_out);
        Serial.print("\t");
        Serial.print(stat.connect);
        Serial.print("\t");
        Serial.print(stat.ack_l);
        Serial.print("\t");
        Serial.print(stat.ack_h);
        Serial.print("\t");
        Serial.print(stat.unknown);
        Serial.println("\n");
    }
    delay(2000);
}

IRTemp

#include "IRTemp.h"

static const byte PIN_DATA    = 2; // Choose any pins you like for these
static const byte PIN_CLOCK   = 3;
static const byte PIN_ACQUIRE = 4;

static const TempUnit SCALE=CELSIUS;  // Options are CELSIUS, FAHRENHEIT

IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);

void setup(void) {
  Serial.begin(9600);
  Serial.println("IRTemp example");
  Serial.println("~~~~~~~~~~~~~~");
}

void loop(void) {
  float irTemperature = irTemp.getIRTemperature(SCALE);
  printTemperature("IR", irTemperature);

  float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
  printTemperature("Ambient", ambientTemperature);

  delay(1000);
}

void printTemperature(
  char  *type,
  float  temperature) {

  Serial.print(type);
  Serial.print(" temperature: ");

  if (isnan(temperature)) {
    Serial.println("Failed");
  }
  else {
    Serial.print(temperature);
    Serial.println(SCALE == FAHRENHEIT  ?  " F"  :  " C");
  }
}

Is it a matter of grouping all the revenant parts together i.e. void setup, void loop then the rest?

I have the add_data.php, dbconnect.php and review_data.php from the tweaking4all.com guide, all on my hosted server and I can see the review_data.php file rendered

Any help would be great
Cheers

Arduino_Noob23: Hi all

Was wondering how can I integrate these 2 sensors and then push the data to an external hosted server so that I can monitor them wherever I am

I have both sensors working in the examples, but I am confused on how to merge the 2 examples together.

Is it a matter of grouping all the revenant parts together i.e. void setup, void loop then the rest?

Yes.

You can then send the data to an Internet of Things facility like Xively or Exosite where they can be accessed from anywhere. The Etherten is only just adequate for this. If you get any more ambitious, like local data backup or display, you may find yourself short of memory.

ok I have mash the codes as best I could with the ethernet part just yet but I get this error

Arduino: 1.0.6 (Mac OS X), Board: “Arduino Uno”
Beer_Temp.ino: In function ‘void loop()’:
Beer_Temp:111: error: ‘printTemperature’ was not declared in this scope
Beer_Temp:123: error: a function-definition is not allowed here before ‘{’ token
Beer_Temp:140: error: expected `}’ at end of input

The code is here

#include "IRTemp.h"
#include <SPI.h>
#include <Ethernet.h>
#include <dht.h>

dht DHT;

#define DHT22_PIN 5 // DHT22 Sensor
static const byte PIN_DATA    = 2; // Choose any pins you like for these
static const byte PIN_CLOCK   = 3;
static const byte PIN_ACQUIRE = 4;

static const TempUnit SCALE=CELSIUS;  // Options are CELSIUS, FAHRENHEIT

IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);

struct
{
    uint32_t total;
    uint32_t ok;
    uint32_t crc_error;
    uint32_t time_out;
    uint32_t connect;
    uint32_t ack_l;
    uint32_t ack_h;
    uint32_t unknown;
} stat = { 0,0,0,0,0,0,0,0};

void setep()
{
    Serial.begin(9600);
    Serial.println("Arduino Beer Temperature Log");
    Serial.println();
    Serial.println("IRTemp example");
    Serial.println("~~~~~~~~~~~~~~");
    Serial.println("Date,\tsensor,\tHumidity (%),\tTemperature (C)\tTime (us)");
  }

void loop()
{
   // DHT22 Sensor Section Read DATA
    Serial.print("DHT22, \t");

    uint32_t start = micros();
    int chk = DHT.read22(DHT22_PIN);
    uint32_t stop = micros();

    stat.total++;
    switch (chk)
    {
    case DHTLIB_OK:
        stat.ok++;
        Serial.print("OK,\t");
        break;
    case DHTLIB_ERROR_CHECKSUM:
        stat.crc_error++;
        Serial.print("Checksum error,\t");
        break;
    case DHTLIB_ERROR_TIMEOUT:
        stat.time_out++;
        Serial.print("Time out error,\t");
        break;
    case DHTLIB_ERROR_CONNECT:
        stat.connect++;
        Serial.print("Connect error,\t");
        break;
    case DHTLIB_ERROR_ACK_L:
        stat.ack_l++;
        Serial.print("Ack Low error,\t");
        break;
    case DHTLIB_ERROR_ACK_H:
        stat.ack_h++;
        Serial.print("Ack High error,\t");
        break;
    default:
        stat.unknown++;
        Serial.print("Unknown error,\t");
        break;
    }
    // DISPLAY DATA
    Serial.print(DHT.humidity, 1);
    Serial.print(",\t");
    Serial.print(DHT.temperature, 1);
    Serial.print(",\t");
    Serial.print(stop - start);
    Serial.println();

    if (stat.total % 20 == 0)
    {
        Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
        Serial.print(stat.total);
        Serial.print("\t");
        Serial.print(stat.ok);
        Serial.print("\t");
        Serial.print(stat.crc_error);
        Serial.print("\t");
        Serial.print(stat.time_out);
        Serial.print("\t");
        Serial.print(stat.connect);
        Serial.print("\t");
        Serial.print(stat.ack_l);
        Serial.print("\t");
        Serial.print(stat.ack_h);
        Serial.print("\t");
        Serial.print(stat.unknown);
        Serial.println("\n");
    }
    {
      //IRTemperature Sensor Section Read Data
      float irTemperature = irTemp.getIRTemperature(SCALE);
      printTemperature("IR", irTemperature);
      
      float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
      printTemperature("Ambient", ambientTemperature);
      
      delay(1000);
    }
    
    void printTemperature
    (char *type,
    float temperature)
    
    {
      //Display Data
    Serial.print(type);
    Serial.print(" temperature: ");
    if (isnan(temperature))
    
    {
      Serial.printIn("Failed");
    }
    else
    {
      Serial.print(temperature);
      Serial.println(SCALE == FAHRENHEIT  ?  " F"  :  " C");
    }
    }
    
    delay(2000);
}

I can’t comment much on the code as I use different sensors, but it appears that you need to learn how to spell “setup”. It would also appear that most, or all, of the problem is to do with braces “{}”. I believe your printTemperature subroutine isn’t one. It is enclosed with the loop

Once you have it working locally, getting onto the internet is just a few more lines for formatting the data for transmission, sending it, and confirmation of proper transmission.

Lol thx for the spelling pickup, what do you mean by the printTemperature isn't a subroutine I am totally new to this arduino and programming and I am just try to mash the to examples together. Yes once I have the sensors working all I need to do is transmit the results to my hosting server which at this stage seems easier than the sensors.

So what should the code look like?

My idea for the table to be transmitted to the hosting server will be something like this updating every 30-60 mins haven't decided yet due to database size

Arduino Beer Temperature Log

ID Date and Time Sensor Temperature in Celsius Humidity %

Cheers

Essentially, it should look like

preamble

call libraries, define variables etc

void setup() {

do the stuff that is run once

}

void loop() {

do the repeated work

}

void subroutine() {

peripheral duties, maths, display etc.

}

subroutines are outside the loop as matters of convenience, or stuff that is accessed more than once in the go-round. I think that printTemperature is enclosed in the loop. There are plenty of examples in the IDE. The order of subroutines does not matter nor does the stuff in the preamble.

I inserted an extra } but still had errors but was able to solve all of them except the printin failed line.

This is the working code

#include "IRTemp.h"
#include <SPI.h>
#include <Ethernet.h>
#include <dht.h>

dht DHT;

#define DHT22_PIN 5 // DHT22 Sensor
static const byte PIN_DATA    = 2; // Choose any pins you like for these
static const byte PIN_CLOCK   = 3;
static const byte PIN_ACQUIRE = 4;

static const TempUnit SCALE=CELSIUS;  // Options are CELSIUS, FAHRENHEIT

IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);

struct
{
  uint32_t total;
  uint32_t ok;
  uint32_t crc_error;
  uint32_t time_out;
  uint32_t connect;
  uint32_t ack_l;
  uint32_t ack_h;
  uint32_t unknown;
} 
stat = { 
  0,0,0,0,0,0,0,0};

void setup()
{
  Serial.begin(9600);
  Serial.println("Arduino Beer Temperature Log");
  Serial.println();
  // Serial.println("IRTemp example");
  Serial.println("~~~~~~~~~~~~~~");
  Serial.println("Date,\tsensor,\tHumidity (%),\tTemperature (C)\tTime (us)");
}

void loop()
{
  // DHT22 Sensor Section Read DATA
  Serial.print("DHT22, \t");

  uint32_t start = micros();
  int chk = DHT.read22(DHT22_PIN);
  uint32_t stop = micros();

  stat.total++;
  switch (chk)
  {
  case DHTLIB_OK:
    stat.ok++;
    Serial.print("OK,\t");
    break;
  case DHTLIB_ERROR_CHECKSUM:
    stat.crc_error++;
    Serial.print("Checksum error,\t");
    break;
  case DHTLIB_ERROR_TIMEOUT:
    stat.time_out++;
    Serial.print("Time out error,\t");
    break;
  case DHTLIB_ERROR_CONNECT:
    stat.connect++;
    Serial.print("Connect error,\t");
    break;
  case DHTLIB_ERROR_ACK_L:
    stat.ack_l++;
    Serial.print("Ack Low error,\t");
    break;
  case DHTLIB_ERROR_ACK_H:
    stat.ack_h++;
    Serial.print("Ack High error,\t");
    break;
  default:
    stat.unknown++;
    Serial.print("Unknown error,\t");
    break;
  }
  // DISPLAY DATA
  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.print(DHT.temperature, 1);
  Serial.print(",\t");
  Serial.print(stop - start);
  Serial.println();

  if (stat.total % 20 == 0)
  {
    Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
    Serial.print(stat.total);
    Serial.print("\t");
    Serial.print(stat.ok);
    Serial.print("\t");
    Serial.print(stat.crc_error);
    Serial.print("\t");
    Serial.print(stat.time_out);
    Serial.print("\t");
    Serial.print(stat.connect);
    Serial.print("\t");
    Serial.print(stat.ack_l);
    Serial.print("\t");
    Serial.print(stat.ack_h);
    Serial.print("\t");
    Serial.print(stat.unknown);
    Serial.println("\n");
  }
  {
    //IRTemperature Sensor Section Read Data
    float irTemperature = irTemp.getIRTemperature(SCALE);
    printTemperature("Surface IR", irTemperature);

    float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
    printTemperature("Ambient", ambientTemperature);

    delay(1000);
  }
}
void printTemperature
(char *type,
float temperature)

{
  //Display Data
  Serial.print(type);
  Serial.print(" temperature: ");

  if (isnan(temperature))
  {
    Serial.println("Failed");
  }
  else
  {
    Serial.print(temperature);
    Serial.println(SCALE == FAHRENHEIT  ?  " F"  :  " C");
  }
  delay(2000);
}

I changed the following lines to read

//IRTemperature Sensor Section Read Data
float irTemperature = irTemp.getIRTemperature(SCALE);
//printTemperature(“IR”, irTemperature); removed the comments //

float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
//printTemperature(“Ambient”, ambientTemperature); removed the comments //

delay(1000);
} Inserted }

void printTemperature
(char *type,
float temperature)

{
//Display Data
Serial.print(type);
Serial.print(" temperature: ");
if (isnan(temperature)) Inserted ;
} Removed }
Serial.println(“Failed”); - There was a ‘I’ for India instead of a ‘l’ for Lima

else

Serial.print(temperature);
Serial.println(SCALE == FAHRENHEIT ? " F" : " C");

delay(2000);
}

Now onto the next part getting it onto the internet