opkg update
opkg install sqlite3-cli
opkg install luasql-sqlite3
sqlite3 /root/sensor.db
sqlite> CREATE TABLE sensor_data(
    id INTEGER PRIMARY KEY,
    temperature VARCHAR(64),
    sqlitetimestamp DATETIME DEFAULT CURRENT_TIMESTAMP
);
sqlite> INSERT INTO sensor_data (temperature) VALUES (30);
sqlite> INSERT INTO sensor_data (temperature) VALUES (40);
sqlite> select * from sensor_data;
sqlite>.quit
nano /root/sensor.lua
#!/usr/bin/lua
sqlite3 = require "luasql.sqlite3"
local x = os.clock()
for i=1,1000,1
do
        local env  = sqlite3.sqlite3()
        local conn = env:connect('/root/sensor.db')
        --print(env,conn)
        cursor,errorString = conn:execute([[select temperature from sensor_data limit 1]])
        --print(cursor,errorString)
        row = cursor:fetch ({}, "a")
        --print(row.temperature)
        -- close everything
        cursor:close()
        conn:close()
        env:close()
        --print(i)
end
print(string.format("elapsed time: %.2f\n", os.clock() - x))
chmod 755 /root/sensor.lua
root@Arduino:~# /root/sensor.lua
elapsed time: 4.69

Lua and Sqlite3 profile speed is 4.69 ms

Comments powered by CComment