Integrating Sqlite
You need to install the sqlite3 command line tool to create a simple database file. We can then read it from our agent.
Lets create an sqlite database and add some data to it
/tmp$ sqlite3 building-data.db
SQLite version 3.43.2 2023-10-10 13:08:14
Enter ".help" for usage hints.
sqlite> create table IAQData(sensor varchar(255), value float, time datetime);
sqlite> insert into IAQData(sensor,value,time) values('S1',23,'2024-01-01T09:00:00Z');
sqlite> insert into IAQData(sensor,value,time) values('S2',21.2,'2024-01-01T09:00:00Z');
sqlite> insert into IAQData(sensor,value,time) values('S3',22.6,'2024-01-01T09:00:00Z');So we have a database with some data inside the IAQData table.
Lets now read this from our agent.
We need to install the sqlite3 driver for node.js
Integrating Sqlite into your connector
First install the appropriate npm package
npm install sqlite3Then use require to reference that module in your index.js file
We can now open the database.
Note that we are now hard-coding the database file path. You could change this to also accept a database file as one of the inputs from your connector definition.
Lets open the database:
This can go at the top of the file right when the program starts.
Next, lets add an async function to query the database:
Finally, lets modify our processRequest() function:
The full code is here:
Now when you exeute your model action you should see the data from your sqlite3 database showing up in the Lucy model!

Last updated