Hi all, when I use the following LUA code:
soil_moisture = read_pin(59, “analog”)
The value does not appear in the ‘sensor history’ section of the web app. Is there any way to achieve this within a sequence?
Thanks
Hi all, when I use the following LUA code:
soil_moisture = read_pin(59, “analog”)
The value does not appear in the ‘sensor history’ section of the web app. Is there any way to achieve this within a sequence?
Thanks
Yes! What you need to do after the read_pin() call is use the new_sensor_reading() function.
Thank you. When I run below code
I got this error message "%Exqlite.Error{message: “NOT NULL constraint failed: sensor_readings.read_at”, statement: “INSERT INTO “sensor_readings” (“monitor”,“value”,“mode”,“x”,”
What is the message mean? And how to fix this error. I sure the moisture sensor is mounted properly.
Woops, sorry about this - there was an error in the code examples in the documentation which I will update now.
The corrected code requires setting the read_at time in the new_sensor_reading request:
-- Mount the soil sensor
mount_tool ("Soil Sensor")
-- Move to (720, 610, 0)
move_absolute (720, 610, 0)
-- Move Z to -380
move_absolute ({z= -380})
-- Measure soil moisture reading
local pin_59 = 59
local soil_moisture = read_pin(pin_59, "analog")
local xyz = get_xyz()
local read_at = utc() -- Get the current time in UTC
new_sensor_reading({
x=xyz.x,
y=xyz.y,
z=xyz.z,
mode=1,
pin=pin_59,
value=soil_moisture,
read_at=read_at -- Include the time with the sensor reading request
})
Thank you, it is working perfectly.