[ create a new paste ] login | about

Link: http://codepad.org/BF17CEmj    [ raw code | output | fork ]

StarT - C++, pasted on Mar 24:
//
 //   FILE:  dht_test.pde
 // PURPOSE: DHT library test sketch for Arduino. Works with web service narodmon.ru
 //

 #include <dht.h>
 #include <Dhcp.h>
 #include <Dns.h>
 #include <Ethernet.h>
 #include <EthernetClient.h>
 #include <EthernetServer.h>
 #include <EthernetUdp.h>
 #include <util.h>
 #include <SPI.h>
#include <OneWire.h>
 dht DHT;
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2
 #define DHT22_PIN 7
 const unsigned long postingInterval = 400000;  // интервал между отправками данных в миллисекундах (5 минут)
 unsigned long lastConnectionTime = 0;           // время последней передачи данных
 boolean lastConnected = false;                  // состояние подключения
 int HighByte, LowByte, TReading, SignBit, Tc_100;
 char replyBuffer[106];
  char CurTemp[6],CurHum[6],TemperatureSum[8],DStemp[8];


 // ========================Задаем данные сети======================
 byte mac[] = {
   0x92, 0xA2, 0xDA, 0x0D, 0xD2, 0x3A }; //mac - адрес ethernet shielda ваш мак!
 EthernetClient client; //
 int ledPin = 9; // указываем что светодиод будет управляться через 9 Pin
 String readString = String(30); //string for fetching data from address
 boolean LEDON = false; //изначальный статус светодиода - выключен
 IPAddress server(94,19,113,221); // IP сервера narodmon.ru
 // ===============================================================

 void setup()
 {
   delay(4000);
   // Ethernet connection:
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure Ethernet using DHCP");
     // ничего не делаем. doing nothing
     for(;;)
       ;
   }
   // пара секунд для инициализации Ethernet. Couple of seconds just to warm up Ethernet.
   delay(2000);
   lastConnectionTime = millis()-postingInterval+15000; //первое соединение через 15 секунд после запуска. First connection after 15 sec timeout.
   //устанавливаем pin 9 на выход
   pinMode(ledPin, OUTPUT); 

   Serial.begin(115200);
   Serial.println("DHT TEST PROGRAM ");
   Serial.print("LIBRARY VERSION: ");
   Serial.println(DHT_LIB_VERSION);
   Serial.println();
   Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
 }

 void loop()
 {
   
   // READ 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
   delay (1000);
   // TempDig = DHT.temperature;
   dtostrf(DHT.temperature, 4, 1, CurTemp);
   delay (1000);
   dtostrf(DHT.humidity, 4, 1, CurHum);
   Serial.print (CurTemp);
   Serial.print(",\t");
   Serial.println (CurHum);

   delay(50000);

   if (client.available()) {
     char c = client.read();

   }

   if (client.connected() && lastConnected)
   {

     client.stop();

   }


   if(!client.connected() && (millis() - lastConnectionTime > postingInterval))

   {

     //формирование HTTP-запроса. Preparing http request.
     memset(replyBuffer, 0, sizeof(replyBuffer));
     strcpy(replyBuffer,"ID=");
     //Конвертируем MAC-адрес. Converting mac address.
     for (int k=0; k<6; k++)
     {
       int b1=mac[k]/16;
       int b2=mac[k]%16;
       char c1[2],c2[2];

       if (b1>9) c1[0]=(char)(b1-10)+'A';
       else c1[0] = (char)(b1) + '0';
       if (b2>9) c2[0]=(char)(b2-10)+'A';
       else c2[0] = (char)(b2) + '0';

       c1[1]='\0';
       c2[1]='\0';

       strcat(replyBuffer,c1);
       strcat(replyBuffer,c2);
     }
     //конвертируем адрес термодатчика. Converting first sensor address.

     strcat(replyBuffer,"&");
     for (int k=0; k<6; k++)
     {
       int b1=mac[k]/16;
       int b2=mac[k]%16;
       char c1[2],c2[2];

       if (b1>9) c1[0]=(char)(b1-10)+'A';
       else c1[0] = (char)(b1) + '0';
       if (b2>9) c2[0]=(char)(b2-10)+'A';
       else c2[0] = (char)(b2) + '0';

       c1[1]='\0';
       c2[1]='\0';

       strcat(replyBuffer,c1);
       strcat(replyBuffer,c2);
     }
     strcat(replyBuffer,"01");

     //конвертируем адрес датчика влажности. Converting secong sensor address.
     strcat(replyBuffer,"=");
     if (SignBit)
     {
       strcat(replyBuffer,"-");
     }
     strcat(replyBuffer,CurTemp);
     strcat(replyBuffer,"&");
     for (int k=0; k<6; k++)
     {
       int b1=mac[k]/16;
       int b2=mac[k]%16;
       char c1[2],c2[2];

       if (b1>9) c1[0]=(char)(b1-10)+'A';
       else c1[0] = (char)(b1) + '0';
       if (b2>9) c2[0]=(char)(b2-10)+'A';
       else c2[0] = (char)(b2) + '0';

       c1[1]='\0';
       c2[1]='\0';

       strcat(replyBuffer,c1);
       strcat(replyBuffer,c2);
     }
     strcat(replyBuffer,"02");

     strcat(replyBuffer,"=");

     strcat(replyBuffer,CurHum);
       strcat(replyBuffer,"&");
 for (int k=0; k<6; k++)
 {
 int b1=mac[k]/16;
 int b2=mac[k]%16;
 char c1[2],c2[2];

 if (b1>9) c1[0]=(char)(b1-10)+'A';
 else c1[0] = (char)(b1) + '0';
 if (b2>9) c2[0]=(char)(b2-10)+'A';
 else c2[0] = (char)(b2) + '0';

 c1[1]='\0';
 c2[1]='\0';

 strcat(replyBuffer,c1);
 strcat(replyBuffer,c2);
 }
 strcat(replyBuffer,"03");

 strcat(replyBuffer,"=");
 
   float temperature = getTemp();
 Serial.println(temperature);
 
 dtostrf(temperature, 4, 1, DStemp);
 
 strcat(replyBuffer,DStemp);
 
      httpRequest();
    
   }

   lastConnected = client.connected();
 
 delay(100); //just here to slow down the output so it is easier to read
 
}


float getTemp(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !ds.search(addr)) {
   //no more sensors on chain, reset search
   ds.reset_search();
   return -1000;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -1000;
 }

 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -1000;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = ds.reset();
 ds.select(addr);  
 ds.write(0xBE); // Read Scratchpad

 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = ds.read();
 }
 
 ds.reset_search();
 
 byte MSB = data[1];
 byte LSB = data[0];

 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 
 return TemperatureSum;
 

 }

 void httpRequest() {
   if (client.connect(server, 80)) {

     // send the HTTP POST request:
     client.println("POST http://narodmon.ru/post.php HTTP/1.0");
     Serial.println("POST http://narodmon.ru/post.php HTTP/1.0");
     client.println("Host: narodmon.ru");
     Serial.println("Host: narodmon.ru");
     //client.println("User-Agent: arduino-ethernet");
     //client.println("Connection: close");
     client.println("Content-Type: application/x-www-form-urlencoded");
     Serial.println("Content-Type: application/x-www-form-urlencoded");
     client.print("Content-Length: ");
     client.println(strlen(replyBuffer));
     Serial.print("Content-Length: ");
     Serial.println(strlen(replyBuffer));
     //client.println();
     Serial.println();
     client.println(replyBuffer);
     Serial.println(replyBuffer);
     //client.println();
     lastConnectionTime = millis();
     delay(1000);
   }
   else {
     Serial.print("http request failed - client not connected");
     client.stop();
   }
 }


Output:
1
2
3
4
5
6
7
8
9
10
11
12
Line 17: error: dht.h: No such file or directory
Line 18: error: Dhcp.h: No such file or directory
Line 17: error: Dns.h: No such file or directory
Line 22: error: Ethernet.h: No such file or directory
Line 28: error: EthernetClient.h: No such file or directory
Line 28: error: EthernetServer.h: No such file or directory
Line 25: error: EthernetUdp.h: No such file or directory
Line 18: error: util.h: No such file or directory
Line 17: error: SPI.h: No such file or directory
Line 20: error: OneWire.h: No such file or directory
Line 16: error: 'dht' does not name a type
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: