Exemple #1
0
int main(int argc, char **argv) {
	int onetime_mode = 0;

	if (argc >= 2) {
		if (strcmp(argv[1], "-1") == 0) {
			onetime_mode = 1;
		}
	}

	if(dht11_init() == -1) {
		exit(1);
	}

	// wait for the the setup of DHT11
	delay(10);

	if (onetime_mode) {
		dht11_read_val();
	} else {
		int i;
		for (i = 0; i < RETRY_MAX; i++) {
			dht11_read_val();
			delay(1000);
		}
	}

	return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
    int last_pir_val, last_ldr_diff;

    printf("Interfacing Sensors With Raspberry Pi\n");
    if(wiringPiSetup()==-1)
        exit(1);

    fname[0] = '\0';
    if (argc > 1) {
        fd = fopen (argv[1], "a");
        if (fd) {
            strncpy (fname, argv[1], 29);
            fclose (fd);
        }
    }

    night_light_off ();

    launch_lm393_thread ();
    while(1)
    {
        // read all sensors */
        dht11_read_val();
        last_pir_val = pir_read_val();
        last_ldr_diff = ldr_read_val();

        night_light_oper (last_ldr_diff, last_pir_val);
    }
    return 0;
}
Exemple #3
0
int main(void)
{
	printf("Interfacing Temperature and Humidity Sensor (DHT11) With Raspberry Pi\n");
	
	// ***
	// *** Ensure we have wiringPi
	// ***
	if (wiringPiSetup() == -1)
	{
		exit(1);
	}

	while (1)
	{
		// ***
		// *** Read the sensor
		// ***
		dht11_read_val();

		// ***
		// *** Delay between readings
		// ***
		delay(DELAY_TIME);
	}

	return 0;
}
Exemple #4
0
static void kaa_demo_add_log_record(void *context)
{
    static size_t log_record_counter = 0;

    float humidity = 0.0;
    float temperature = 0.0;

    if (dht11_read_val(DHT11_PIN, &humidity, &temperature) != 0) {
        printf("Failed to read data from sensor\n");
        return;
    }

    ++log_record_counter;

    kaa_user_log_record_t *log_record = kaa_logging_sensor_data_create();
    if (!log_record) {
        printf("Failed to create log record, error code %d\n", KAA_ERR_NOMEM);
        return;
    }

    log_record->sensor_id = kaa_string_copy_create("Sensor 1");
    log_record->region = kaa_string_copy_create("Region 1");
    log_record->model = kaa_string_copy_create("DHT11");
    log_record->value = temperature;

    printf("Going to add %zuth log record: { id: '%s', region: '%s', model: '%s', val: %g }\n"
            , log_record_counter, log_record->sensor_id->data, log_record->region->data, log_record->model->data, log_record->value);

    kaa_error_t error_code = kaa_logging_add_record(kaa_client_get_context((kaa_client_t *)context)->log_collector, log_record, NULL);
    if (error_code) {
        printf("Failed to add log record, error code %d\n", error_code);
    }

    log_record->destroy(log_record);
}
Exemple #5
0
int main(void)  
{  
  if(wiringPiSetup()==-1)  
    exit(1);  
  while(1)  
  {  
     dht11_read_val();  
     delay(3000);  
  }  
  return 0;  
}  
Exemple #6
0
int main(void)  
{  
	int ihumidity = -1;
	int itemp = -1;
  printf("Interfacing Temperature and Humidity Sensor (DHT11) With Raspberry Pi\n");  
  if(wiringPiSetup()==-1)  
    exit(1);  
  while(1)  
  {  
     dht11_read_val();  
     delay(3000);  
  }  
  return 0;  
}  
Exemple #7
0
int main(void){
//    int attempts=ATTEMPTS;
    if(wiringPiSetup()==-1)
        exit(1);
//    while(attempts){                        //you have 5 times to retry
        int success = dht11_read_val();     //get result including printing out
//        if (success) {                      //if get result, quit program; if not, retry 5 times then quit
//            break;
//        }
//        attempts--;
//        delay(2500);
//    }
    return success;
}
Exemple #8
0
int main(void)
{
  int attempts=ATTEMPTS;
  if(wiringPiSetup()==-1)
    exit(1);
  while(attempts)
  {
    int success = dht11_read_val();
    if (success) {
      break;
    }
    attempts--;
    delay(500);
  }
  return 0;
}
int main(void)
{
		int a = 0;
		int attempts=ATTEMPTS;
		if(wiringPiSetup()==-1)
		exit(1);
		for(a=0; a<5; )
		{
			int success = dht11_read_val();
			if (success) {
				a++;
				delay(5000);
				
			}
		//attempts--;
		}
		
		
	

return 0;
}
Exemple #10
0
void pm_read()
{
	int uart0_filestream = -1;


    uart0_filestream = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY | O_NDELAY);		//Open in non blocking read/write mode
    if (uart0_filestream == -1)
    {

        printf("Error - Unable to open UART.  Ensure it is not in use by another application\n");
    }


    struct termios options;
    tcgetattr(uart0_filestream, &options);
    options.c_cflag = B9600 | CS8 | CLOCAL | CREAD;		//<Set baud rate
    options.c_iflag = IGNPAR;
    options.c_oflag = 0;
    options.c_lflag = 0;
    tcflush(uart0_filestream, TCIFLUSH);
    tcsetattr(uart0_filestream, TCSANOW, &options);

	int counter=0;



	for(;;)
	{


        sleep(1);
        
        if (uart0_filestream != -1)
        {


            uint8_t rx_buffer[32];
            int rx_length = read(uart0_filestream, (uint8_t *)rx_buffer, 32);

            if (rx_length < 0)
            {
            }
            else if (rx_length == 0)
            {

                //No data waiting
            }
            else
            {
                //Bytes received
                //printf("c=%d\n",c);
                //rx_buffer[rx_length] = '\0';

                uint8_t test;

                pm1_0 = (rx_buffer[4]<<8)+rx_buffer[5];
                pm2_5 = (rx_buffer[6]<<8)+rx_buffer[7];
                pm10 = (rx_buffer[8]<<8)+rx_buffer[9];
                test = rx_buffer[0];

                if(test==66)
                {
					printf("PM1.0: %d\n",pm1_0);
                    printf("PM2.5: %d\n",pm2_5);
					printf("PM10: %d\n",pm10);
					dht11_read_val();
					printf("*******************************\n");
                      
                     



                }
            }
        }
    }
	close(uart0_filestream);
}