#include #include #include #include #include #include #include #include #include #include #define WTHR_STATION_ID 0 #define TIMESTAMP_FIELD 1 #define DATA_VAL_FIELD 2 #define STATION_ID_FIELD 3 #define INSERT_HUM_TEMPL "INSERT INTO humidity(timestamp, value, station) VALUES(?, ?, ?)" #define INSERT_TEMP_TEMPL "INSERT INTO temperature(timestamp, value, station) VALUES(?, ?, ?)" sqlite3* get_db(void) { sqlite3 *db; char *zErrMsg = 0; int rc; rc = sqlite3_open("test.db", &db); if( rc ) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); } else { fprintf(stderr, "Opened database successfully\n"); } return db; } int open_port(void) { int fd; /* File descriptor for the port */ fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { perror("open_port: Unable to open /dev/USB0 - "); } else fcntl(fd, F_SETFL, 0); return (fd); } enum record_type { R_TEMP, R_REL_HUMIDITY }; void ccleanup(sqlite3 *db) { static bool setup = false; static sqlite3 *saved; if (!setup) { saved = db; setup = true; } else { sqlite3_close(db); printf("Closed DB.\n"); } } static void call_cleanup(int signo) { ccleanup(NULL); exit(0); } struct query_result { int argc; char **argv; char **azColName; }; static int save_qry(void *retval, int argc, char **argv, char **azColName) { struct query_result r; r.argc = argc; r.argv = argv; r.azColName = azColName; struct query_result* ret = retval; *ret = r; return 0; } static int callback(void *retval, int argc, char **argv, char **azColName) { int i; for(i = 0; i