int updateStatus (int port, bool portStatus){ //6 = HUMO - 21/22 //5 = PRTA - 23 - NC - LOW //2 = TALT - 24 // DETECTA VALOR -10 => PUERTA ABIERTA 0 // DETECTA VALOR -20 => PUERTA CERRADA 1 if (!mysql_connect ()){ if (portStatus){ db_insert (5,0,puerta_abierta); printf ("PA\n"); } else { db_insert (5,0,puerta_cerrada); printf ("PC\n"); } db_update (5,0,0); mysql_disconnect (); } return 0; }
//***************************************************************************** //************************* MAIN-FUNCTION ********************************* //***************************************************************************** int main () { //Connect to the database mysql_connect(); //gets min_rv en RV[] get_stuff(); //disconnect from the database mysql_disconnect(); //check for a too low value and send mail for(int i = 0; i < 3600; i++){ if((RV[i] < min_rv) && (RV[i] > 0)){ //exec command //snprintf(temp, 100, "cat /usr/share/nginx/mail/humidity_low.txt | mail -s \"Test Subject\" [email protected]"); //echo "<b>HTML Message goes here</b>" | mail -s "$(echo -e "This is the subject\nContent-Type: text/html")" [email protected] snprintf(temp, 200, "cat /usr/share/nginx/mail/humidity_low.txt | mail -s \"$(echo \"[TerraPi] Too low humidity detected.\nContent-Type: text/html\")\" [email protected]"); system(temp); printf("Error: Too low humidity - mail has been sent.\n\n"); break; } } }
int main() { mysql_connect(); list_drivers(); list_data_sources(); list_driver_information(); list_tables(); execute_query("select * from junk"); execute_query("select count(*), sum(a) from junk"); execute_query("select a, a+3, 3.141592654 from junk"); execute_query("select j1.a, j2.a from junk j1 natural join junk j2"); mysql_disconnect(); }
int main(int argc, char **argv){ uint8_t data_array[4]; uint8_t tx_address[5] = { 0xE7, 0xE7, 0xE7, 0xE7, 0xE7 }; uint8_t rx_address[5] = { 0xD7, 0xD7, 0xD7, 0xD7, 0xD7 }; if (!bcm2835_init()) return 1; mysql_connect(); /* init hardware pins */ nrf24_init(); /* Channel #2 , payload length: 4 */ nrf24_config(2, 4); /* Set the device addresses */ nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); printf("Configured\n"); while (1){ if (nrf24_dataReady()) { nrf24_getData(data_array); printf("> %d %d %d %d \n", data_array[0], data_array[1], data_array[2], data_array[3]); if (argc>1) { if (argv[1][0]=='1') { writeCpm( data_array[0], data_array[1], data_array[2], data_array[3]); } } } } mysql_disconnect(); bcm2835_close(); return 0; }
///////////////////////////////////////////////////////////////////////////////// //++++++++++++++++++++++ START READ PORTS FUNCTION ++++++++++++++++++++++++++++++ ///////////////////////////////////////////////////////////////////////////////// int readActivePorts (void){ int size = sizeof (activePorts)/ sizeof (int); int result; int lcontador = 0; if (!mysql_connect ()){ if (!digitalRead (24)) volts = 0; db_insert (2,0,volts); db_update (2,0,0); if (!digitalRead (21)) humo = 70; db_insert (6,0,humo); db_update (6,0,0); humo = 20; if (!digitalRead (22)) humo = 70; db_insert (6,1,humo); db_update (6,1,0); fileRead (); for (int i=0 ; ((i < MAXPORTS) && (i < size)) ; i++){ result = displayDHTData (activePorts[i]); if(!result){ db_insert (0,i,temperature); db_update (0,i,0); fprintf(fr, "%2.1f\t", temperature); db_insert (1,i,humidity); db_update (1,i,0); fprintf(fr, "%2.1f\t", humidity); db_insert (4,i,dewPoint); db_update (4,i,0); fprintf(fr, "%2.1f\n", dewPoint); //lcontador = 0; } //else { //if ((result == 20) && (lcontador < MAX_ERRORS)){ // ++lcontador; // --i; //} else if (result == 20){ for (int j = 1; j < i; j++){ fscanf(fr, "%*f %*f %*f"); //printf ("J:%d\n",j); //printf ("I:%d\n",i); } fscanf(fr, "%f %f %f", &temperature, &humidity, &dewPoint); fprintf(stderr, "New value T %2.1f\n", temperature); fprintf(stderr, "New value H %2.1f\n", humidity); fprintf(stderr, "New value D %2.1f\n", dewPoint); db_insert (0,i,temperature); db_update (0,i,0); db_insert (1,i,humidity); db_update (1,i,0); db_insert (4,i,dewPoint); db_update (4,i,0); // lcontador = 0; } else if (result == 10){ db_update (0,i,result); db_update (1,i,result); db_update (4,i,result); //lcontador = 0; } } //fflush (fr); fclose (fr); printf("File Closed\n"); mysql_disconnect (); } return 0; }