diff --git a/.gitignore b/.gitignore index 87e8251..8db3ac8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -fb_dash +fbdash *.o *.swp diff --git a/Makefile b/Makefile index 88b1f46..5630eaa 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,11 @@ -CFLAGS=-g -Wall -lm +# Prerequisites: +# # sudo apt-get install libmariadb-dev +# # mariadb_config --libs +# +CFLAGS=-g -Wall -lm -L/usr/lib/arm-linux-gnueabihf -lmariadb -I/usr/include/mariadb fbdash: fbdash.c fblib fbfont - gcc fblib.o fbfont.o -o $@ $(CFLAGS) $< + gcc -o $@ fblib.o fbfont.o $< $(CFLAGS) fblib: fblib.o gcc -c fblib.c diff --git a/fbdash b/fbdash deleted file mode 100755 index 6dac5f1..0000000 Binary files a/fbdash and /dev/null differ diff --git a/fbdash.c b/fbdash.c index 881d25b..4aebf7f 100644 --- a/fbdash.c +++ b/fbdash.c @@ -21,10 +21,13 @@ */ +#include #include #include #include +#include + #include "fblib.h" #define WIDTH 240 @@ -53,16 +56,54 @@ void draw() { - +/* char *text = "Hell O_o!"; render_string(fbp, ubuntu_mono_48, text, 15, 0, 255, 255, 255); render_string(fbp, ubuntu_mono_24, text, 15, 50, 255, 255, 255); render_string(fbp, basic_8, text, 15, 100, 255, 255, 255); +*/ +} + +void finish_with_error(MYSQL *con) +{ + fprintf(stderr, "%s\n", mysql_error(con)); + mysql_close(con); + exit(1); } // application entry point int main(int argc, char* argv[]) { + + printf("MySQL client version: %s\n", mysql_get_client_info()); + MYSQL *con = mysql_init(NULL); + if (con == NULL) { + fprintf(stderr, "%s\n", mysql_error(con)); + exit(1); + } + if (mysql_real_connect(con, "web-pi", "root", "root_passwd", NULL, 0, NULL, 0) == NULL) { + fprintf(stderr, "%s\n", mysql_error(con)); + mysql_close(con); + exit(1); + } + if (mysql_query(con, "SELECT * FROM grafanaData.readings ORDER BY time DESC LIMIT 1")) { + finish_with_error(con); + } + MYSQL_RES *result = mysql_store_result(con); + if (result == NULL) { + finish_with_error(con); + } + int num_fields = mysql_num_fields(result); + MYSQL_ROW row; + while ((row = mysql_fetch_row(result))) { + for(int i = 0; i < num_fields; i++) { + printf("%s ", row[i] ? row[i] : "NULL"); + } + printf("\n"); + } + mysql_free_result(result); + mysql_close(con); + int fbfd = 0; long int screensize = 0;