Hi, I am using the device TRB140. I am using the Impulse Counter service. It is working fine. I am also using the Data to Server service to send the count to an external MQTT broker. It is working fine. However, when the count does not change I do not receive a message that notifies of such zero. This is a problem, because I have a synoptic that every minute must update the state. If no counts happened then the synoptic must show that. However, given that only positive counts are sent, my synoptic keeps the state of the last non-zero value.
Of course I could implement some logic in my synoptic such that “If no data is received in the last minute then set the count to zero“. However, I do not think this is good practice, because if at some point I want to change the interval time to send the data in the Data to Sever, I would have to change my synoptic logic in order to adapt to this new interval. This can lead to potential problems in the future.
In short, can Impulse Counter send 0 counts?
Greetings,
Could you please send screenshots of your data to server configuration? Please ensure that no sensitive information is included.
Also, have you tried setting the Empty value option under the collection configuration to 0 ?
Best Regards,
Justinas
Hi, thank you for the quick response. Sure, here I provide the data to server configuration. The zero is never sent.
As I said previously, the data to server works when the count is positive.
Thank you in advance.
Greetings,
I have forwarded your inquiry to our research and development department. Once I get their feedback on how sending 0 counts be achieved, I will get back to you.
Best Regards,
Justinas
Greetings,
If no pulses are detected, no entry is created in the database, meaning the impulse counter data isn’t sent. A workaround would be to use a Lua script. Within the script, you can pull the impulse counter values (via API or by getting data straight from the database) and add logic to send a “0” when no impulses are recorded.
I am sending you a script you can use as a reference. While its specific goal is to sum up impulses, which isn’t exactly what you’re looking for, it’s a good example of how a Lua script that interacts with the impulse counter within the data sender can look like.
local json = require("luci.jsonc")
local sqlite3 = require("lsqlite3")
function handle_format_request(data)
local db = sqlite3.open("/var/run/icounter/impulse_counter.db")
if not db then
print("Failed to open database")
return json.stringify(0)
end
local sql = "SELECT SUM(count) AS total_count FROM count_data;"
local stmt = db:prepare(sql)
if not stmt then
print("Failed to prepare statement.")
db:close()
return json.stringify(0)
end
local total = 0
local result = stmt:step()
if result == sqlite3.ROW then
total = stmt:get_value(0)
end
-- Clean up
stmt:finalize()
db:close()
--print("Total count:", total)
return json.stringify(total)
end
Writing and troubleshooting custom scripts is outside of our technical support scope, you can find more information about custom scripts here: User Scripts examples - Teltonika Networks Wiki
Best Regards,
Justinas