working on adding database query to retrieve display data
This commit is contained in:
parent
3dffca483d
commit
8855ec007b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
fb_dash
|
fbdash
|
||||||
*.o
|
*.o
|
||||||
*.swp
|
*.swp
|
||||||
|
|||||||
8
Makefile
8
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
|
fbdash: fbdash.c fblib fbfont
|
||||||
gcc fblib.o fbfont.o -o $@ $(CFLAGS) $<
|
gcc -o $@ fblib.o fbfont.o $< $(CFLAGS)
|
||||||
|
|
||||||
fblib: fblib.o
|
fblib: fblib.o
|
||||||
gcc -c fblib.c
|
gcc -c fblib.c
|
||||||
|
|||||||
43
fbdash.c
43
fbdash.c
@ -21,10 +21,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include <mysql.h>
|
||||||
|
|
||||||
#include "fblib.h"
|
#include "fblib.h"
|
||||||
|
|
||||||
#define WIDTH 240
|
#define WIDTH 240
|
||||||
@ -53,16 +56,54 @@ void draw() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
char *text = "Hell O_o!";
|
char *text = "Hell O_o!";
|
||||||
render_string(fbp, ubuntu_mono_48, text, 15, 0, 255, 255, 255);
|
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, ubuntu_mono_24, text, 15, 50, 255, 255, 255);
|
||||||
render_string(fbp, basic_8, text, 15, 100, 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
|
// application entry point
|
||||||
int main(int argc, char* argv[])
|
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;
|
int fbfd = 0;
|
||||||
long int screensize = 0;
|
long int screensize = 0;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user